Assert\Assertion::endsWith PHP Method

endsWith() public static method

Assert that string ends with a sequence of chars.
public static endsWith ( 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
return boolean
    public static function endsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8')
    {
        static::string($string, $message, $propertyPath);
        $stringPosition = mb_strlen($string, $encoding) - mb_strlen($needle, $encoding);
        if (mb_strripos($string, $needle, null, $encoding) !== $stringPosition) {
            $message = sprintf($message ?: 'Value "%s" does not end with "%s".', static::stringify($string), static::stringify($needle));
            $constraints = array('needle' => $needle, 'encoding' => $encoding);
            throw static::createException($string, $message, static::INVALID_STRING_END, $propertyPath, $constraints);
        }
        return true;
    }

Usage Example

Exemplo n.º 1
0
 public function testValidEndsWith()
 {
     Assertion::endsWith("foo", "foo");
     Assertion::endsWith("sonderbar", "bar");
     Assertion::endsWith("opp", "p");
     Assertion::endsWith("foo址", "址");
 }
All Usage Examples Of Assert\Assertion::endsWith