maxLength() public static method

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
return boolean
Beispiel #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;
 }
Beispiel #2
0
 /**
  * @param $text
  */
 public function __construct($text)
 {
     Assertion::string($text);
     Assertion::minLength($text, 1);
     Assertion::maxLength($text, 1000);
     $this->text = $text;
 }
Beispiel #3
0
 /**
  * @param string $value
  */
 public function __construct($value)
 {
     Assertion::string($value);
     Assertion::minLength($value, 1);
     Assertion::maxLength($value, 50);
     $this->value = strtolower($value);
 }
Beispiel #4
0
 /**
  * __construct()
  *
  * @param string $name Project name
  */
 public function __construct($name)
 {
     Assertion::string($name);
     Assertion::maxLength($name, 20, 'Project key exceeds max allowed chars');
     Assertion::regex($name, '/^[a-z0-9\\-]*$/', 'Project key does not match expected format');
     $this->name = $name;
     $this->environments = new \SplObjectStorage();
     $this->servers = new \SplObjectStorage();
     $this->tasks = new \SplObjectStorage();
 }
Beispiel #5
0
 public function testValidMaxLength()
 {
     Assertion::maxLength("foo", 10);
     Assertion::maxLength("foo", 3);
     Assertion::maxLength("", 0);
     Assertion::maxLength("址址", 2);
 }
Beispiel #6
0
 /**
  * Validate reference code:
  * Length <= 20
  * @param string $referenceCode
  */
 public static function referenceCode($referenceCode)
 {
     Assert::maxLength($referenceCode, 20);
 }
Beispiel #7
0
 /**
  * @param string $category
  *
  * @throws \InvalidArgumentException
  *
  * @return static
  */
 public function withCategory($category)
 {
     Assertion::string($category);
     Assertion::maxLength($category, VideoInterface::CATEGORY_MAX_LENGTH);
     $instance = clone $this;
     $instance->category = $category;
     return $instance;
 }