Webmozart\Assert\Assert::startsWithLetter PHP Method

startsWithLetter() public static method

public static startsWithLetter ( $value, $message = '' )
    public static function startsWithLetter($value, $message = '')
    {
        $valid = isset($value[0]);
        if ($valid) {
            $locale = setlocale(LC_CTYPE, 0);
            setlocale(LC_CTYPE, 'C');
            $valid = ctype_alpha($value[0]);
            setlocale(LC_CTYPE, $locale);
        }
        if (!$valid) {
            static::reportInvalidArgument(sprintf($message ?: 'Expected a value to start with a letter. Got: %s', static::valueToString($value)));
        }
    }

Usage Example

Example #1
0
 /**
  * Creates a new parameter.
  *
  * @param string $name         The parameter name.
  * @param int    $flags        A bitwise combination of the flag constants
  *                             in this class.
  * @param mixed  $defaultValue The parameter's default value.
  */
 public function __construct($name, $flags = self::OPTIONAL, $defaultValue = null)
 {
     Assert::stringNotEmpty($name, 'The parameter name must be a non-empty string. Got: %s');
     Assert::startsWithLetter($name, 'The parameter name must start with a letter. Got: %s');
     Assert::nullOrInteger($flags, 'The parameter "$flags" must be an integer or null. Got: %s');
     if ($flags & self::REQUIRED && null !== $defaultValue) {
         throw new RuntimeException('Required parameters must not have default values.');
     }
     $this->name = $name;
     $this->flags = $flags;
     $this->defaultValue = $defaultValue;
 }
All Usage Examples Of Webmozart\Assert\Assert::startsWithLetter