Assert\Assertion::maxLength PHP Метод

maxLength() публичный статический Метод

Assert that string value is not longer than $maxLength chars.
public static maxLength ( mixed $value, integer $maxLength, string | null $message = null, string | null $propertyPath = null, string $encoding = 'utf8' ) : boolean
$value mixed
$maxLength integer
$message string | null
$propertyPath string | null
$encoding string
Результат boolean
    public static function maxLength($value, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8')
    {
        static::string($value, $message, $propertyPath);
        if (mb_strlen($value, $encoding) > $maxLength) {
            $message = sprintf($message ?: 'Value "%s" is too long, it should have no more than %d characters, but has %d characters.', static::stringify($value), $maxLength, mb_strlen($value, $encoding));
            $constraints = array('max_length' => $maxLength, 'encoding' => $encoding);
            throw static::createException($value, $message, static::INVALID_MAX_LENGTH, $propertyPath, $constraints);
        }
        return true;
    }

Usage Example

Пример #1
0
 /**
  * @param $name
  */
 public function __construct($name)
 {
     Assertion::string($name, 'StreamName must be a string');
     Assertion::notEmpty($name, 'StreamName must not be empty');
     Assertion::maxLength($name, 200, 'StreamName should not be longer than 200 chars');
     $this->name = $name;
 }
All Usage Examples Of Assert\Assertion::maxLength