Assert\Assertion::minLength PHP Method

minLength() public static method

Assert that a string is at least $minLength chars long.
public static minLength ( mixed $value, integer $minLength, string | null $message = null, string | null $propertyPath = null, string $encoding = 'utf8' ) : boolean
$value mixed
$minLength integer
$message string | null
$propertyPath string | null
$encoding string
return boolean
    public static function minLength($value, $minLength, $message = null, $propertyPath = null, $encoding = 'utf8')
    {
        static::string($value, $message, $propertyPath);
        if (mb_strlen($value, $encoding) < $minLength) {
            $message = sprintf($message ?: 'Value "%s" is too short, it should have more than %d characters, but only has %d characters.', static::stringify($value), $minLength, mb_strlen($value, $encoding));
            $constraints = array('min_length' => $minLength, 'encoding' => $encoding);
            throw static::createException($value, $message, static::INVALID_MIN_LENGTH, $propertyPath, $constraints);
        }
        return true;
    }

Usage Example

 /**
  * @param null|string   $identifierMethodName
  * @param null|string   $versionMethodName
  * @param null|string   $popRecordedEventsMethodName
  * @param null|string   $replayEventsMethodsName
  * @param null|string   $staticReconstituteFromHistoryMethodName
  * @param null|callable $eventToMessageCallback
  * @param null|callable $messageToEventCallback
  */
 public function __construct($identifierMethodName = null, $versionMethodName = null, $popRecordedEventsMethodName = null, $replayEventsMethodsName = null, $staticReconstituteFromHistoryMethodName = null, $eventToMessageCallback = null, $messageToEventCallback = null)
 {
     if (null !== $identifierMethodName) {
         Assertion::minLength($identifierMethodName, 1, 'Identifier method name needs to be a non empty string');
         $this->identifierMethodName = $identifierMethodName;
     }
     if (null !== $versionMethodName) {
         Assertion::minLength($versionMethodName, 1, 'Version method name needs to be a non empty string');
         $this->versionMethodName = $versionMethodName;
     }
     if (null !== $popRecordedEventsMethodName) {
         Assertion::minLength($popRecordedEventsMethodName, 1, 'Pop recorded events method name needs to be a non empty string');
         $this->popRecordedEventsMethodName = $popRecordedEventsMethodName;
     }
     if (null !== $replayEventsMethodsName) {
         Assertion::minLength($replayEventsMethodsName, 1, 'Replay events method name needs to be a non empty string');
         $this->replayEventsMethodName = $replayEventsMethodsName;
     }
     if (null !== $staticReconstituteFromHistoryMethodName) {
         Assertion::minLength($staticReconstituteFromHistoryMethodName, 1, 'Method name for static method reconstitute from history needs to be non empty string');
         $this->staticReconstituteFromHistoryMethodName = $staticReconstituteFromHistoryMethodName;
     }
     if (null !== $eventToMessageCallback) {
         Assertion::true(is_callable($eventToMessageCallback), 'EventToMessage callback needs to be a callable');
         $this->eventToMessageCallback = $eventToMessageCallback;
     }
     if (null !== $messageToEventCallback) {
         Assertion::true(is_callable($messageToEventCallback), 'MessageToEvent callback needs to be a callable');
         $this->messageToEventCallback = $messageToEventCallback;
     }
 }
All Usage Examples Of Assert\Assertion::minLength