-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRuleMatcher.php
More file actions
42 lines (38 loc) · 864 Bytes
/
RuleMatcher.php
File metadata and controls
42 lines (38 loc) · 864 Bytes
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
<?php
/**
* Definition of class RuleMatcher
*
* @copyright 2015-today Justso GmbH
* @author j.schirrmacher@justso.de
* @package justso\justgen
*/
namespace justso\justgen;
/**
* Class RuleMatcher
*
* @package justso\justgen
*/
class RuleMatcher
{
private $rules;
public function __construct(array $rules)
{
$this->rules = $rules;
}
/**
* Searches a matching rule for the given name or null if none could be found
*
* @param string $what
* @return string|null
*/
public function find($what)
{
foreach ($this->rules as $name => $entry) {
$pattern = str_replace(array('/', '*', '%d'), array('\\/', '.*', '\d'), $name);
if (preg_match('/^' . $pattern . '$/', $what)) {
return $entry;
}
}
return null;
}
}