Laravel version update
Laravel version update
This commit is contained in:
@@ -31,14 +31,16 @@ class StringLength extends AbstractValidator
|
||||
* @var array
|
||||
*/
|
||||
protected $messageVariables = [
|
||||
'min' => ['options' => 'min'],
|
||||
'max' => ['options' => 'max'],
|
||||
'min' => ['options' => 'min'],
|
||||
'max' => ['options' => 'max'],
|
||||
'length' => ['options' => 'length']
|
||||
];
|
||||
|
||||
protected $options = [
|
||||
'min' => 0, // Minimum length
|
||||
'max' => null, // Maximum length, null if there is no length limitation
|
||||
'encoding' => 'UTF-8', // Encoding to use
|
||||
'length' => 0 // Actual length
|
||||
];
|
||||
|
||||
protected $stringWrapper;
|
||||
@@ -50,14 +52,14 @@ class StringLength extends AbstractValidator
|
||||
*/
|
||||
public function __construct($options = [])
|
||||
{
|
||||
if (!is_array($options)) {
|
||||
if (! is_array($options)) {
|
||||
$options = func_get_args();
|
||||
$temp['min'] = array_shift($options);
|
||||
if (!empty($options)) {
|
||||
if (! empty($options)) {
|
||||
$temp['max'] = array_shift($options);
|
||||
}
|
||||
|
||||
if (!empty($options)) {
|
||||
if (! empty($options)) {
|
||||
$temp['encoding'] = array_shift($options);
|
||||
}
|
||||
|
||||
@@ -135,7 +137,7 @@ class StringLength extends AbstractValidator
|
||||
*/
|
||||
public function getStringWrapper()
|
||||
{
|
||||
if (!$this->stringWrapper) {
|
||||
if (! $this->stringWrapper) {
|
||||
$this->stringWrapper = StringUtils::getWrapper($this->getEncoding());
|
||||
}
|
||||
return $this->stringWrapper;
|
||||
@@ -177,6 +179,28 @@ class StringLength extends AbstractValidator
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length option
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function getLength()
|
||||
{
|
||||
return $this->options['length'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the length option
|
||||
*
|
||||
* @param int $length
|
||||
* @return StringLength Provides a fluent interface
|
||||
*/
|
||||
private function setLength($length)
|
||||
{
|
||||
$this->options['length'] = (int) $length;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if and only if the string length of $value is at least the min option and
|
||||
* no greater than the max option (when the max option is not null).
|
||||
@@ -186,19 +210,19 @@ class StringLength extends AbstractValidator
|
||||
*/
|
||||
public function isValid($value)
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
if (! is_string($value)) {
|
||||
$this->error(self::INVALID);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->setValue($value);
|
||||
|
||||
$length = $this->getStringWrapper()->strlen($value);
|
||||
if ($length < $this->getMin()) {
|
||||
$this->setLength($this->getStringWrapper()->strlen($value));
|
||||
if ($this->getLength() < $this->getMin()) {
|
||||
$this->error(self::TOO_SHORT);
|
||||
}
|
||||
|
||||
if (null !== $this->getMax() && $this->getMax() < $length) {
|
||||
if (null !== $this->getMax() && $this->getMax() < $this->getLength()) {
|
||||
$this->error(self::TOO_LONG);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user