forked from coduo/php-matcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
match.php
51 lines (47 loc) · 1.58 KB
/
match.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
use Coduo\PHPMatcher\Matcher\ArrayMatcher;
use Coduo\PHPMatcher\Matcher\CallbackMatcher;
use Coduo\PHPMatcher\Matcher\ChainMatcher;
use Coduo\PHPMatcher\Matcher\ExpressionMatcher;
use Coduo\PHPMatcher\Matcher\JsonMatcher;
use Coduo\PHPMatcher\Matcher\ScalarMatcher;
use Coduo\PHPMatcher\Matcher\TypeMatcher;
use Coduo\PHPMatcher\Matcher\WildcardMatcher;
use Coduo\PHPMatcher\Matcher;
if (is_dir($vendor = __DIR__ . '/../vendor')) {
require_once($vendor . '/autoload.php');
} elseif (is_dir($vendor = __DIR__ . '/../../../vendor')) {
require_once($vendor . '/autoload.php');
} elseif (is_dir($vendor = __DIR__ . '/vendor')) {
require_once($vendor . '/autoload.php');
} else {
die(
'You must set up the project dependencies, run the following commands:' . PHP_EOL .
'curl -s http://getcomposer.org/installer | php' . PHP_EOL .
'php composer.phar install' . PHP_EOL
);
}
if (!function_exists('match')) {
/**
* @param mixed $value
* @param mixed $pattern
* @return boolean
*/
function match($value, $pattern)
{
$scalarMatchers = new ChainMatcher(array(
new CallbackMatcher(),
new ExpressionMatcher(),
new TypeMatcher(),
new ScalarMatcher(),
new WildcardMatcher()
));
$arrayMatcher = new ArrayMatcher($scalarMatchers);
$matcher = new Matcher(new ChainMatcher(array(
$scalarMatchers,
$arrayMatcher,
new JsonMatcher($arrayMatcher)
)));
return $matcher->match($value, $pattern);
}
}