File tree Expand file tree Collapse file tree 4 files changed +73
-24
lines changed
tests/Coduo/PHPMatcher/Factory Expand file tree Collapse file tree 4 files changed +73
-24
lines changed Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
- use Coduo \PHPMatcher \Matcher \ArrayMatcher ;
4
- use Coduo \PHPMatcher \Matcher \CallbackMatcher ;
5
- use Coduo \PHPMatcher \Matcher \ChainMatcher ;
6
- use Coduo \PHPMatcher \Matcher \ExpressionMatcher ;
7
- use Coduo \PHPMatcher \Matcher \JsonMatcher ;
8
- use Coduo \PHPMatcher \Matcher \NullMatcher ;
9
- use Coduo \PHPMatcher \Matcher \ScalarMatcher ;
10
- use Coduo \PHPMatcher \Matcher \TypeMatcher ;
11
- use Coduo \PHPMatcher \Matcher \WildcardMatcher ;
12
- use Coduo \PHPMatcher \Matcher ;
3
+ use Coduo \PHPMatcher \Factory \SimpleFactory ;
13
4
14
5
if (is_dir ($ vendor = __DIR__ . '/../vendor ' )) {
15
6
require_once ($ vendor . '/autoload.php ' );
33
24
*/
34
25
function match ($ value , $ pattern )
35
26
{
36
- $ scalarMatchers = new ChainMatcher (array (
37
- new CallbackMatcher (),
38
- new ExpressionMatcher (),
39
- new TypeMatcher (),
40
- new NullMatcher (),
41
- new ScalarMatcher (),
42
- new WildcardMatcher ()
43
- ));
44
- $ arrayMatcher = new ArrayMatcher ($ scalarMatchers );
45
- $ matcher = new Matcher (new ChainMatcher (array (
46
- $ scalarMatchers ,
47
- $ arrayMatcher ,
48
- new JsonMatcher ($ arrayMatcher )
49
- )));
27
+ $ factory = new SimpleFactory ();
28
+ $ matcher = $ factory ->createMatcher ();
50
29
51
30
return $ matcher ->match ($ value , $ pattern );
52
31
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+ namespace Coduo \PHPMatcher ;
3
+
4
+ interface Factory
5
+ {
6
+ /**
7
+ * @return Matcher
8
+ */
9
+ public function createMatcher ();
10
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Coduo \PHPMatcher \Factory ;
4
+
5
+ use Coduo \PHPMatcher \Factory ;
6
+ use Coduo \PHPMatcher \Matcher ;
7
+
8
+ class SimpleFactory implements Factory
9
+ {
10
+ /**
11
+ * @return Matcher
12
+ */
13
+ public function createMatcher ()
14
+ {
15
+ return new Matcher ($ this ->buildMatchers ());
16
+ }
17
+
18
+ /**
19
+ * @return Matcher\ChainMatcher
20
+ */
21
+ protected function buildMatchers ()
22
+ {
23
+ $ scalarMatchers = $ this ->buildScalarMatchers ();
24
+ $ arrayMatcher = new Matcher \ArrayMatcher ($ scalarMatchers );
25
+
26
+ return new Matcher \ChainMatcher (array (
27
+ $ scalarMatchers ,
28
+ $ arrayMatcher ,
29
+ new Matcher \JsonMatcher ($ arrayMatcher )
30
+ ));
31
+ }
32
+
33
+ /**
34
+ * @return Matcher\ChainMatcher
35
+ */
36
+ protected function buildScalarMatchers ()
37
+ {
38
+ return new Matcher \ChainMatcher (array (
39
+ new Matcher \CallbackMatcher (),
40
+ new Matcher \ExpressionMatcher (),
41
+ new Matcher \TypeMatcher (),
42
+ new Matcher \ScalarMatcher (),
43
+ new Matcher \WildcardMatcher ()
44
+ ));
45
+ }
46
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ namespace Coduo \PHPMatcher \Tests ;
3
+
4
+ use Coduo \PHPMatcher \Matcher ;
5
+ use Coduo \PHPMatcher \Factory \SimpleFactory ;
6
+
7
+ class SimpleFactoryTest extends \PHPUnit_Framework_TestCase
8
+ {
9
+ public function test_creating_matcher ()
10
+ {
11
+ $ factory = new SimpleFactory ();
12
+ $ this ->assertInstanceOf ('Coduo\PHPMatcher\Matcher ' , $ factory ->createMatcher ());
13
+ }
14
+ }
You can’t perform that action at this time.
0 commit comments