-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from norzechowicz/factory
Matcher factory introduction
- Loading branch information
Showing
4 changed files
with
74 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
namespace Coduo\PHPMatcher; | ||
|
||
interface Factory | ||
{ | ||
/** | ||
* @return Matcher | ||
*/ | ||
public function createMatcher(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Coduo\PHPMatcher\Factory; | ||
|
||
use Coduo\PHPMatcher\Factory; | ||
use Coduo\PHPMatcher\Matcher; | ||
|
||
class SimpleFactory implements Factory | ||
{ | ||
/** | ||
* @return Matcher | ||
*/ | ||
public function createMatcher() | ||
{ | ||
return new Matcher($this->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\NullMatcher(), | ||
new Matcher\ScalarMatcher(), | ||
new Matcher\WildcardMatcher() | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
namespace Coduo\PHPMatcher\Tests; | ||
|
||
use Coduo\PHPMatcher\Matcher; | ||
use Coduo\PHPMatcher\Factory\SimpleFactory; | ||
|
||
class SimpleFactoryTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function test_creating_matcher() | ||
{ | ||
$factory = new SimpleFactory(); | ||
$this->assertInstanceOf('Coduo\PHPMatcher\Matcher', $factory->createMatcher()); | ||
} | ||
} |