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

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

Assert that string starts with a sequence of chars.
public static startsWith ( mixed $string, string $needle, string | null $message = null, string | null $propertyPath = null, string $encoding = 'utf8' ) : boolean
$string mixed
$needle string
$message string | null
$propertyPath string | null
$encoding string
Результат boolean
    public static function startsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8')
    {
        static::string($string, $message, $propertyPath);
        if (mb_strpos($string, $needle, null, $encoding) !== 0) {
            $message = sprintf($message ?: 'Value "%s" does not start with "%s".', static::stringify($string), static::stringify($needle));
            $constraints = array('needle' => $needle, 'encoding' => $encoding);
            throw static::createException($string, $message, static::INVALID_STRING_START, $propertyPath, $constraints);
        }
        return true;
    }

Usage Example

 private function setType($type)
 {
     Assertion::string($type, 'Token type should be a string');
     Assertion::startsWith($type, 'T_', 'Token type should start with T_');
     Assertion::true(defined($type), 'Token type should be the name of a defined constant');
     $this->type = $type;
     $this->code = constant($type);
 }
All Usage Examples Of Assert\Assertion::startsWith