File tree Expand file tree Collapse file tree 4 files changed +74
-24
lines changed
tests/Coduo/PHPMatcher/Factory Expand file tree Collapse file tree 4 files changed +74
-24
lines changed Original file line number Diff line number Diff line change 11<?php
22
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 ;
134
145if (is_dir ($ vendor = __DIR__ . '/../vendor ' )) {
156 require_once ($ vendor . '/autoload.php ' );
3324 */
3425 function match ($ value , $ pattern )
3526 {
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 ();
5029
5130 return $ matcher ->match ($ value , $ pattern );
5231 }
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 \NullMatcher (),
43+ new Matcher \ScalarMatcher (),
44+ new Matcher \WildcardMatcher ()
45+ ));
46+ }
47+ }
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