|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Coduo\PHPMatcher\Factory; |
|
4
|
|
|
|
|
5
|
|
|
use Coduo\PHPMatcher\Factory; |
|
6
|
|
|
use Coduo\PHPMatcher\Lexer; |
|
7
|
|
|
use Coduo\PHPMatcher\Matcher; |
|
8
|
|
|
use Coduo\PHPMatcher\Parser; |
|
9
|
|
|
|
|
10
|
|
|
class SimpleFactory implements Factory |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @return Matcher |
|
14
|
|
|
*/ |
|
15
|
|
|
public function createMatcher() |
|
16
|
|
|
{ |
|
17
|
|
|
return new Matcher($this->buildMatchers()); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @return Matcher\ChainMatcher |
|
22
|
|
|
*/ |
|
23
|
|
|
protected function buildMatchers() |
|
24
|
|
|
{ |
|
25
|
|
|
$scalarMatchers = $this->buildScalarMatchers(); |
|
26
|
|
|
$orMatcher = $this->buildOrMatcher(); |
|
27
|
|
|
|
|
28
|
|
|
$chainMatcher = new Matcher\ChainMatcher(array( |
|
29
|
|
|
$scalarMatchers, |
|
30
|
|
|
$orMatcher, |
|
31
|
|
|
new Matcher\JsonMatcher($orMatcher), |
|
32
|
|
|
new Matcher\XmlMatcher($orMatcher), |
|
33
|
|
|
new Matcher\TextMatcher($scalarMatchers, $this->buildParser()) |
|
34
|
|
|
)); |
|
35
|
|
|
|
|
36
|
|
|
return $chainMatcher; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @return Matcher\ChainMatcher |
|
41
|
|
|
*/ |
|
42
|
|
|
protected function buildOrMatcher() |
|
43
|
|
|
{ |
|
44
|
|
|
$scalarMatchers = $this->buildScalarMatchers(); |
|
45
|
|
|
$orMatcher = new Matcher\OrMatcher($scalarMatchers); |
|
46
|
|
|
$arrayMatcher = new Matcher\ArrayMatcher( |
|
47
|
|
|
new Matcher\ChainMatcher(array( |
|
48
|
|
|
$orMatcher, |
|
49
|
|
|
$scalarMatchers |
|
50
|
|
|
)), |
|
51
|
|
|
$this->buildParser() |
|
52
|
|
|
); |
|
53
|
|
|
|
|
54
|
|
|
$chainMatcher = new Matcher\ChainMatcher(array( |
|
55
|
|
|
$orMatcher, |
|
56
|
|
|
$arrayMatcher, |
|
57
|
|
|
)); |
|
58
|
|
|
|
|
59
|
|
|
return $chainMatcher; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return Matcher\ChainMatcher |
|
64
|
|
|
*/ |
|
65
|
|
|
protected function buildScalarMatchers() |
|
66
|
|
|
{ |
|
67
|
|
|
$parser = $this->buildParser(); |
|
68
|
|
|
|
|
69
|
|
|
return new Matcher\ChainMatcher(array( |
|
70
|
|
|
new Matcher\CallbackMatcher(), |
|
71
|
|
|
new Matcher\ExpressionMatcher(), |
|
72
|
|
|
new Matcher\NullMatcher(), |
|
73
|
|
|
new Matcher\StringMatcher($parser), |
|
74
|
|
|
new Matcher\IntegerMatcher($parser), |
|
75
|
|
|
new Matcher\BooleanMatcher(), |
|
76
|
|
|
new Matcher\DoubleMatcher($parser), |
|
77
|
|
|
new Matcher\NumberMatcher(), |
|
78
|
|
|
new Matcher\ScalarMatcher(), |
|
79
|
|
|
new Matcher\WildcardMatcher() |
|
80
|
|
|
)); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @return Parser |
|
85
|
|
|
*/ |
|
86
|
|
|
protected function buildParser() |
|
87
|
|
|
{ |
|
88
|
|
|
return new Parser(new Lexer(), new Parser\ExpanderInitializer()); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|