move 'is' method to the str class where it belongs.
This commit is contained in:
@@ -300,6 +300,30 @@ class Str {
|
||||
return substr(str_shuffle(str_repeat(static::pool($type), 5)), 0, $length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a given string matches a given pattern.
|
||||
*
|
||||
* @param string $pattern
|
||||
* @param string $value
|
||||
* @return bool
|
||||
*/
|
||||
public static function is($pattern, $value)
|
||||
{
|
||||
// Asterisks are translated into zero-or-more regular expression wildcards
|
||||
// to make it convenient to check if the URI starts with a given pattern
|
||||
// such as "library/*". This is only done when not root.
|
||||
if ($pattern !== '/')
|
||||
{
|
||||
$pattern = str_replace('*', '(.*)', $pattern).'\z';
|
||||
}
|
||||
else
|
||||
{
|
||||
$pattern = '^/$';
|
||||
}
|
||||
|
||||
return preg_match('#'.$pattern.'#', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the character pool for a given type of random string.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user