src/Traits/StringTrait.php
/**
	 * Determine if a given string matches a given pattern.
	 * Used Laravel Str::is for based, added little more functionality, it detects if pattern is already regular expression
	 *
	 * @param string|array $patterns
	 * @param string       $value
	 * @return bool
	 * @author https://github.com/illuminate/support/blob/master/Str.php
	 */
Determine if a given string matches a given pattern.
Used Laravel Str::is for based, added little more functionality, it detects if pattern is already regular expression


Determine if a given string matches a given pattern . Used Laravel Str :: is for based added little more functionality it detects if pattern is already regular expression
public static function is($patterns, string $value): bool
	{
		if (is_null($patterns)) {
			$patterns = [];
		}
		$patterns = is_null($patterns) ? [] : (is_array($patterns) ? $patterns : [$patterns]);
		if (empty($patterns)) {
			return false;
		}
		foreach ($patterns as $pattern) {
			$pattern = (string)$pattern;
			if ($pattern == $value) {
				return true;
			}
			if (Regex::isPattern($pattern) and preg_match($pattern, $value) === 1) {
				return true;
			}
			$pattern = preg_quote($pattern, '#');
			$pattern = str_replace('\*', '.*', $pattern);
			if (preg_match('#^' . $pattern . '\z#u', $value) === 1) {
				return true;
			}
		}
		return false;
	}
public static function is ( $ patterns , string $ value ) : bool { if ( is_null ( $ patterns ) ) { $ patterns = [ ] ; } $ patterns = is_null ( $ patterns ) ? [ ] : ( is_array ( $ patterns ) ? $ patterns : [ $ patterns ] ) ; if ( empty ( $ patterns ) ) { return false ; } foreach ( $ patterns as $ pattern ) { $ pattern = ( string ) $ pattern ; if ( $ pattern == $ value ) { return true ; } if ( Regex :: isPattern ( $ pattern ) and preg_match ( $ pattern , $ value ) === 1 ) { return true ; } $ pattern = preg_quote ( $ pattern , '#' ) ; $ pattern = str_replace ( '\*' , '.*' , $ pattern ) ; if ( preg_match ( '#^' . $ pattern . '\z#u' , $ value ) === 1 ) { return true ; } } return false ; }
Determine if a given string matches a given pattern.
Determine if a given string matches a given pattern .
// If the given value is an exact match we can of course return true right // from the beginning. Otherwise, we will translate asterisks and do an // actual pattern match against the two strings to see if they match. // Asterisks are translated into zero-or-more regular expression wildcards // to make it convenient to check if the strings starts with the given // pattern such as "library/*", making any string check convenient.