From 3d8ad8840c0e529cfe0f3a4ee804245bb8bbb3c9 Mon Sep 17 00:00:00 2001 From: Norbert Orzechowicz Date: Thu, 19 Jun 2014 13:30:53 +0200 Subject: [PATCH 1/2] Matcher factory introduction --- match.php | 27 ++--------- src/Coduo/PHPMatcher/Factory.php | 10 ++++ .../PHPMatcher/Factory/SimpleFactory.php | 46 +++++++++++++++++++ .../PHPMatcher/Factory/SimpleFactoryTest.php | 14 ++++++ 4 files changed, 73 insertions(+), 24 deletions(-) create mode 100644 src/Coduo/PHPMatcher/Factory.php create mode 100644 src/Coduo/PHPMatcher/Factory/SimpleFactory.php create mode 100644 tests/Coduo/PHPMatcher/Factory/SimpleFactoryTest.php diff --git a/match.php b/match.php index a77bb73e..1a867113 100644 --- a/match.php +++ b/match.php @@ -1,15 +1,6 @@ createMatcher(); return $matcher->match($value, $pattern); } diff --git a/src/Coduo/PHPMatcher/Factory.php b/src/Coduo/PHPMatcher/Factory.php new file mode 100644 index 00000000..f45e5f3a --- /dev/null +++ b/src/Coduo/PHPMatcher/Factory.php @@ -0,0 +1,10 @@ +buildMatchers()); + } + + /** + * @return Matcher\ChainMatcher + */ + protected function buildMatchers() + { + $scalarMatchers = $this->buildScalarMatchers(); + $arrayMatcher = new Matcher\ArrayMatcher($scalarMatchers); + + return new Matcher\ChainMatcher(array( + $scalarMatchers, + $arrayMatcher, + new Matcher\JsonMatcher($arrayMatcher) + )); + } + + /** + * @return Matcher\ChainMatcher + */ + protected function buildScalarMatchers() + { + return new Matcher\ChainMatcher(array( + new Matcher\CallbackMatcher(), + new Matcher\ExpressionMatcher(), + new Matcher\TypeMatcher(), + new Matcher\ScalarMatcher(), + new Matcher\WildcardMatcher() + )); + } +} diff --git a/tests/Coduo/PHPMatcher/Factory/SimpleFactoryTest.php b/tests/Coduo/PHPMatcher/Factory/SimpleFactoryTest.php new file mode 100644 index 00000000..241d6ae5 --- /dev/null +++ b/tests/Coduo/PHPMatcher/Factory/SimpleFactoryTest.php @@ -0,0 +1,14 @@ +assertInstanceOf('Coduo\PHPMatcher\Matcher', $factory->createMatcher()); + } +} From 6bf2d8ecd1020f8b513d16280a43a7de51e59eb8 Mon Sep 17 00:00:00 2001 From: Norbert Orzechowicz Date: Thu, 19 Jun 2014 13:53:24 +0200 Subject: [PATCH 2/2] Added null matcher --- src/Coduo/PHPMatcher/Factory/SimpleFactory.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Coduo/PHPMatcher/Factory/SimpleFactory.php b/src/Coduo/PHPMatcher/Factory/SimpleFactory.php index 6451f30d..46cc3151 100644 --- a/src/Coduo/PHPMatcher/Factory/SimpleFactory.php +++ b/src/Coduo/PHPMatcher/Factory/SimpleFactory.php @@ -39,6 +39,7 @@ protected function buildScalarMatchers() new Matcher\CallbackMatcher(), new Matcher\ExpressionMatcher(), new Matcher\TypeMatcher(), + new Matcher\NullMatcher(), new Matcher\ScalarMatcher(), new Matcher\WildcardMatcher() ));