File tree Expand file tree Collapse file tree 2 files changed +10
-30
lines changed Expand file tree Collapse file tree 2 files changed +10
-30
lines changed Original file line number Diff line number Diff line change @@ -26,9 +26,10 @@ composer require --dev "coduo/php-matcher"
26
26
27
27
use Coduo\PHPMatcher\PHPMatcher;
28
28
29
- if (!PHPMatcher::match("lorem ipsum dolor", "@string@")) {
30
- echo PHPMatcher::getError() ; // reason why value does not match pattern.
29
+ if (!PHPMatcher::match("lorem ipsum dolor", "@string@", $error )) {
30
+ echo $error ; // in case of error message is set on $error message via reference
31
31
}
32
+
32
33
```
33
34
34
35
Original file line number Diff line number Diff line change 6
6
7
7
final class PHPMatcher
8
8
{
9
- /**
10
- * @var Matcher|null
11
- */
12
- private static $ matcher ;
13
-
14
9
/**
15
10
* @param $value
16
11
* @param $pattern
12
+ * @param null $error
17
13
* @return bool
18
14
*/
19
- public static function match ($ value , $ pattern )
15
+ public static function match ($ value , $ pattern, & $ error = null )
20
16
{
21
- $ matcher = self :: createMatcher ();
17
+ $ matcher = ( new SimpleFactory ())-> createMatcher ();
22
18
23
- return $ matcher ->match ($ value , $ pattern );
24
- }
25
-
26
- /**
27
- * @return null|string
28
- */
29
- public static function getError ()
30
- {
31
- $ matcher = self ::createMatcher ();
32
-
33
- return $ matcher ->getError ();
34
- }
35
-
36
- private static function createMatcher ()
37
- {
38
- if (self ::$ matcher instanceof Matcher) {
39
- return self ::$ matcher ;
19
+ if (!$ matcher ->match ($ value , $ pattern )) {
20
+ $ error = $ matcher ->getError ();
21
+ return false ;
40
22
}
41
23
42
- $ factory = new SimpleFactory ();
43
- self ::$ matcher = $ factory ->createMatcher ();
44
-
45
- return self ::$ matcher ;
24
+ return true ;
46
25
}
47
26
}
You can’t perform that action at this time.
0 commit comments