Primo Committ
This commit is contained in:
202
vendor/laravel/framework/src/Illuminate/Validation/Rules/DatabaseRule.php
vendored
Normal file
202
vendor/laravel/framework/src/Illuminate/Validation/Rules/DatabaseRule.php
vendored
Normal file
@@ -0,0 +1,202 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Validation\Rules;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
trait DatabaseRule
|
||||
{
|
||||
/**
|
||||
* The table to run the query against.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table;
|
||||
|
||||
/**
|
||||
* The column to check on.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $column;
|
||||
|
||||
/**
|
||||
* The extra where clauses for the query.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $wheres = [];
|
||||
|
||||
/**
|
||||
* The array of custom query callbacks.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $using = [];
|
||||
|
||||
/**
|
||||
* Create a new rule instance.
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $column
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($table, $column = 'NULL')
|
||||
{
|
||||
$this->column = $column;
|
||||
|
||||
$this->table = $this->resolveTableName($table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the name of the table from the given string.
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
public function resolveTableName($table)
|
||||
{
|
||||
if (! Str::contains($table, '\\') || ! class_exists($table)) {
|
||||
return $table;
|
||||
}
|
||||
|
||||
if (is_subclass_of($table, Model::class)) {
|
||||
$model = new $table;
|
||||
|
||||
return implode('.', array_filter(
|
||||
[$model->getConnectionName(), $model->getTable()]
|
||||
));
|
||||
}
|
||||
|
||||
return $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a "where" constraint on the query.
|
||||
*
|
||||
* @param \Closure|string $column
|
||||
* @param array|string|null $value
|
||||
* @return $this
|
||||
*/
|
||||
public function where($column, $value = null)
|
||||
{
|
||||
if (is_array($value)) {
|
||||
return $this->whereIn($column, $value);
|
||||
}
|
||||
|
||||
if ($column instanceof Closure) {
|
||||
return $this->using($column);
|
||||
}
|
||||
|
||||
if (is_null($value)) {
|
||||
return $this->whereNull($column);
|
||||
}
|
||||
|
||||
$this->wheres[] = compact('column', 'value');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a "where not" constraint on the query.
|
||||
*
|
||||
* @param string $column
|
||||
* @param array|string $value
|
||||
* @return $this
|
||||
*/
|
||||
public function whereNot($column, $value)
|
||||
{
|
||||
if (is_array($value)) {
|
||||
return $this->whereNotIn($column, $value);
|
||||
}
|
||||
|
||||
return $this->where($column, '!'.$value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a "where null" constraint on the query.
|
||||
*
|
||||
* @param string $column
|
||||
* @return $this
|
||||
*/
|
||||
public function whereNull($column)
|
||||
{
|
||||
return $this->where($column, 'NULL');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a "where not null" constraint on the query.
|
||||
*
|
||||
* @param string $column
|
||||
* @return $this
|
||||
*/
|
||||
public function whereNotNull($column)
|
||||
{
|
||||
return $this->where($column, 'NOT_NULL');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a "where in" constraint on the query.
|
||||
*
|
||||
* @param string $column
|
||||
* @param array $values
|
||||
* @return $this
|
||||
*/
|
||||
public function whereIn($column, array $values)
|
||||
{
|
||||
return $this->where(function ($query) use ($column, $values) {
|
||||
$query->whereIn($column, $values);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a "where not in" constraint on the query.
|
||||
*
|
||||
* @param string $column
|
||||
* @param array $values
|
||||
* @return $this
|
||||
*/
|
||||
public function whereNotIn($column, array $values)
|
||||
{
|
||||
return $this->where(function ($query) use ($column, $values) {
|
||||
$query->whereNotIn($column, $values);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a custom query callback.
|
||||
*
|
||||
* @param \Closure $callback
|
||||
* @return $this
|
||||
*/
|
||||
public function using(Closure $callback)
|
||||
{
|
||||
$this->using[] = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the custom query callbacks for the rule.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function queryCallbacks()
|
||||
{
|
||||
return $this->using;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the where clauses.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function formatWheres()
|
||||
{
|
||||
return collect($this->wheres)->map(function ($where) {
|
||||
return $where['column'].','.'"'.str_replace('"', '""', $where['value']).'"';
|
||||
})->implode(',');
|
||||
}
|
||||
}
|
||||
131
vendor/laravel/framework/src/Illuminate/Validation/Rules/Dimensions.php
vendored
Normal file
131
vendor/laravel/framework/src/Illuminate/Validation/Rules/Dimensions.php
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Validation\Rules;
|
||||
|
||||
class Dimensions
|
||||
{
|
||||
/**
|
||||
* The constraints for the dimensions rule.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $constraints = [];
|
||||
|
||||
/**
|
||||
* Create a new dimensions rule instance.
|
||||
*
|
||||
* @param array $constraints
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $constraints = [])
|
||||
{
|
||||
$this->constraints = $constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the "width" constraint.
|
||||
*
|
||||
* @param int $value
|
||||
* @return $this
|
||||
*/
|
||||
public function width($value)
|
||||
{
|
||||
$this->constraints['width'] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the "height" constraint.
|
||||
*
|
||||
* @param int $value
|
||||
* @return $this
|
||||
*/
|
||||
public function height($value)
|
||||
{
|
||||
$this->constraints['height'] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the "min width" constraint.
|
||||
*
|
||||
* @param int $value
|
||||
* @return $this
|
||||
*/
|
||||
public function minWidth($value)
|
||||
{
|
||||
$this->constraints['min_width'] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the "min height" constraint.
|
||||
*
|
||||
* @param int $value
|
||||
* @return $this
|
||||
*/
|
||||
public function minHeight($value)
|
||||
{
|
||||
$this->constraints['min_height'] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the "max width" constraint.
|
||||
*
|
||||
* @param int $value
|
||||
* @return $this
|
||||
*/
|
||||
public function maxWidth($value)
|
||||
{
|
||||
$this->constraints['max_width'] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the "max height" constraint.
|
||||
*
|
||||
* @param int $value
|
||||
* @return $this
|
||||
*/
|
||||
public function maxHeight($value)
|
||||
{
|
||||
$this->constraints['max_height'] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the "ratio" constraint.
|
||||
*
|
||||
* @param float $value
|
||||
* @return $this
|
||||
*/
|
||||
public function ratio($value)
|
||||
{
|
||||
$this->constraints['ratio'] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the rule to a validation string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$result = '';
|
||||
|
||||
foreach ($this->constraints as $key => $value) {
|
||||
$result .= "$key=$value,";
|
||||
}
|
||||
|
||||
return 'dimensions:'.substr($result, 0, -1);
|
||||
}
|
||||
}
|
||||
22
vendor/laravel/framework/src/Illuminate/Validation/Rules/Exists.php
vendored
Normal file
22
vendor/laravel/framework/src/Illuminate/Validation/Rules/Exists.php
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Validation\Rules;
|
||||
|
||||
class Exists
|
||||
{
|
||||
use DatabaseRule;
|
||||
|
||||
/**
|
||||
* Convert the rule to a validation string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return rtrim(sprintf('exists:%s,%s,%s',
|
||||
$this->table,
|
||||
$this->column,
|
||||
$this->formatWheres()
|
||||
), ',');
|
||||
}
|
||||
}
|
||||
45
vendor/laravel/framework/src/Illuminate/Validation/Rules/In.php
vendored
Normal file
45
vendor/laravel/framework/src/Illuminate/Validation/Rules/In.php
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Validation\Rules;
|
||||
|
||||
class In
|
||||
{
|
||||
/**
|
||||
* The name of the rule.
|
||||
*/
|
||||
protected $rule = 'in';
|
||||
|
||||
/**
|
||||
* The accepted values.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Create a new in rule instance.
|
||||
*
|
||||
* @param array $values
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $values)
|
||||
{
|
||||
$this->values = $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the rule to a validation string.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @see \Illuminate\Validation\ValidationRuleParser::parseParameters
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$values = array_map(function ($value) {
|
||||
return '"'.str_replace('"', '""', $value).'"';
|
||||
}, $this->values);
|
||||
|
||||
return $this->rule.':'.implode(',', $values);
|
||||
}
|
||||
}
|
||||
43
vendor/laravel/framework/src/Illuminate/Validation/Rules/NotIn.php
vendored
Normal file
43
vendor/laravel/framework/src/Illuminate/Validation/Rules/NotIn.php
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Validation\Rules;
|
||||
|
||||
class NotIn
|
||||
{
|
||||
/**
|
||||
* The name of the rule.
|
||||
*/
|
||||
protected $rule = 'not_in';
|
||||
|
||||
/**
|
||||
* The accepted values.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Create a new "not in" rule instance.
|
||||
*
|
||||
* @param array $values
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $values)
|
||||
{
|
||||
$this->values = $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the rule to a validation string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$values = array_map(function ($value) {
|
||||
return '"'.str_replace('"', '""', $value).'"';
|
||||
}, $this->values);
|
||||
|
||||
return $this->rule.':'.implode(',', $values);
|
||||
}
|
||||
}
|
||||
38
vendor/laravel/framework/src/Illuminate/Validation/Rules/RequiredIf.php
vendored
Normal file
38
vendor/laravel/framework/src/Illuminate/Validation/Rules/RequiredIf.php
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Validation\Rules;
|
||||
|
||||
class RequiredIf
|
||||
{
|
||||
/**
|
||||
* The condition that validates the attribute.
|
||||
*
|
||||
* @var callable|bool
|
||||
*/
|
||||
public $condition;
|
||||
|
||||
/**
|
||||
* Create a new required validation rule based on a condition.
|
||||
*
|
||||
* @param callable|bool $condition
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($condition)
|
||||
{
|
||||
$this->condition = $condition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the rule to a validation string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
if (is_callable($this->condition)) {
|
||||
return call_user_func($this->condition) ? 'required' : '';
|
||||
}
|
||||
|
||||
return $this->condition ? 'required' : '';
|
||||
}
|
||||
}
|
||||
74
vendor/laravel/framework/src/Illuminate/Validation/Rules/Unique.php
vendored
Normal file
74
vendor/laravel/framework/src/Illuminate/Validation/Rules/Unique.php
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Validation\Rules;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Unique
|
||||
{
|
||||
use DatabaseRule;
|
||||
|
||||
/**
|
||||
* The ID that should be ignored.
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $ignore;
|
||||
|
||||
/**
|
||||
* The name of the ID column.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $idColumn = 'id';
|
||||
|
||||
/**
|
||||
* Ignore the given ID during the unique check.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param string|null $idColumn
|
||||
* @return $this
|
||||
*/
|
||||
public function ignore($id, $idColumn = null)
|
||||
{
|
||||
if ($id instanceof Model) {
|
||||
return $this->ignoreModel($id, $idColumn);
|
||||
}
|
||||
|
||||
$this->ignore = $id;
|
||||
$this->idColumn = $idColumn ?? 'id';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignore the given model during the unique check.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @param string|null $idColumn
|
||||
* @return $this
|
||||
*/
|
||||
public function ignoreModel($model, $idColumn = null)
|
||||
{
|
||||
$this->idColumn = $idColumn ?? $model->getKeyName();
|
||||
$this->ignore = $model->{$this->idColumn};
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the rule to a validation string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return rtrim(sprintf('unique:%s,%s,%s,%s,%s',
|
||||
$this->table,
|
||||
$this->column,
|
||||
$this->ignore ? '"'.addslashes($this->ignore).'"' : 'NULL',
|
||||
$this->idColumn,
|
||||
$this->formatWheres()
|
||||
), ',');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user