This repository was archived by the owner on Sep 28, 2018. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 7575 toSlugCase :
7676 text : toSlugCase
7777 relativeUrl : docs/Methods/toslugcase.html
78+ is :
79+ text : is
80+ relativeUrl : docs/Methods/is.html
7881 isLowerCase :
7982 text : isLowerCase
8083 relativeUrl : docs/Methods/islowercase.html
Original file line number Diff line number Diff line change 1+ # is
2+ Poor mans WildCard regular expression.
3+
4+ ## Description
5+ ` bool is(string $pattern) `
6+
7+ Asterisks are translated into zero-or-more regular expression wildcards
8+ to make it convenient to check if the strings starts with the given
9+ pattern such as "library/* ", making any string check convenient.
10+
11+ ### Parameters
12+ * _ string_ __ $pattern__
13+ The string or pattern to match against.
14+
15+
16+ ### Return Value
17+ _ bool_
18+ Whether or not we match the provided pattern.
Original file line number Diff line number Diff line change 1515
1616trait Is
1717{
18+ /**
19+ * Poor mans WildCard regular expression.
20+ *
21+ * Asterisks are translated into zero-or-more regular expression wildcards
22+ * to make it convenient to check if the strings starts with the given
23+ * pattern such as "library/*", making any string check convenient.
24+ *
25+ * @credit Originally from Laravel, thanks Taylor.
26+ *
27+ * @param string $pattern The string or pattern to match against.
28+ *
29+ * @return bool Whether or not we match the provided pattern.
30+ */
31+ public function is ($ pattern )
32+ {
33+ if ($ this ->toString () === $ pattern ) return true ;
34+ $ quotedPattern = preg_quote ($ pattern , $ this ->regexDelimiter );
35+ $ replaceWildCards = str_replace ('\* ' , '.* ' , $ quotedPattern );
36+ return $ this ->regexMatch ('^ ' .$ replaceWildCards .'\z ' );
37+ }
38+
1839 /**
1940 * Is the entire string lower case?
2041 *
Original file line number Diff line number Diff line change 44
55class IsTest extends PHPUnit_Framework_TestCase
66{
7+ /**
8+ * @dataProvider isProvider()
9+ */
10+ public function testIs ($ expected , $ string , $ pattern , $ encoding = null )
11+ {
12+ $ str = new Str ($ string , $ encoding );
13+ $ result = $ str ->is ($ pattern );
14+ $ this ->assertInternalType ('boolean ' , $ result );
15+ $ this ->assertEquals ($ expected , $ result );
16+ $ this ->assertEquals ($ string , $ str );
17+ }
18+
19+ public function isProvider ()
20+ {
21+ return array
22+ (
23+ [true , 'Gears \\String \\Str ' , 'Gears \\String \\Str ' ],
24+ [true , 'Gears \\String \\Str ' , 'Gears \\* \\Str ' ],
25+ [true , 'Gears \\String \\Str ' , 'Gears \\* \\* ' ],
26+ [false , 'Gears \\String \\Str ' , 'Gears-*-* ' ]
27+ );
28+ }
29+
730 /**
831 * @dataProvider isLowerCaseProvider()
932 */
You can’t perform that action at this time.
0 commit comments