1 | <?php |
||
10 | class DefinitionMap |
||
11 | { |
||
12 | /** |
||
13 | * @var array |
||
14 | */ |
||
15 | private $map; |
||
16 | |||
17 | /** |
||
18 | * @param array $map Initial mapping using friendly names as keys and matching sub-definitions as values |
||
19 | */ |
||
20 | 13 | public function __construct(array $map = array()) |
|
21 | { |
||
22 | 13 | foreach ($map as $definition => $subdefinition) { |
|
23 | 7 | $this->addMapping($definition, $subdefinition); |
|
24 | } |
||
25 | 13 | } |
|
26 | |||
27 | /** |
||
28 | * @return string[] |
||
29 | */ |
||
30 | 1 | public function toArray() |
|
34 | |||
35 | /** |
||
36 | * @param string $definition |
||
37 | * @param string|array $subDefinition |
||
38 | */ |
||
39 | 8 | public function addMapping($definition, $subDefinition) |
|
40 | { |
||
41 | 8 | if (! is_array($subDefinition)) { |
|
42 | 7 | $subDefinition = [ 'default' => $subDefinition ]; |
|
43 | } |
||
44 | |||
45 | 8 | $this->map[$definition] = $subDefinition; |
|
46 | 8 | } |
|
47 | |||
48 | /** |
||
49 | * @param string $definition |
||
50 | * @param string|null $type |
||
51 | * @return bool |
||
52 | */ |
||
53 | 10 | public function hasSubDefinition($definition, $type = null) |
|
61 | |||
62 | /** |
||
63 | * @param string $definition |
||
64 | * @param string|null $type |
||
65 | * @return string |
||
66 | */ |
||
67 | 7 | public function getSubDefinition($definition, $type = null) |
|
79 | } |
||
80 |