1 | <?php |
||
12 | class TargetDefinition implements TargetDefinitionInterface |
||
13 | { |
||
14 | /** |
||
15 | * @var Collection|ConditionInterface[] |
||
16 | */ |
||
17 | protected $conditions; |
||
18 | /** @var string */ |
||
19 | protected $route; |
||
20 | |||
21 | /** |
||
22 | * TargetDefinition constructor. |
||
23 | * |
||
24 | * @param string $route |
||
25 | */ |
||
26 | 7 | public function __construct($route) |
|
27 | { |
||
28 | 7 | $this->route = $route; |
|
29 | 7 | $this->conditions = new ArrayCollection(); |
|
30 | 7 | } |
|
31 | |||
32 | /** {@inheritdoc} */ |
||
33 | 7 | public function match(DestinationInterface $destination) |
|
51 | |||
52 | /** |
||
53 | * Get conditions indexed by code |
||
54 | * |
||
55 | * @return ConditionInterface[] |
||
56 | */ |
||
57 | public function getConditions() |
||
61 | |||
62 | /** {@inheritdoc} */ |
||
63 | public function setCondition($code, ConditionInterface $condition) |
||
71 | |||
72 | /** {@inheritdoc} */ |
||
73 | 1 | public function getCondition($code) |
|
74 | { |
||
75 | 1 | if ($this->conditions->containsKey($code)) { |
|
76 | return $this->conditions->get($code); |
||
77 | } |
||
78 | |||
79 | 1 | return new PermissiveCondition(); |
|
80 | } |
||
81 | |||
82 | /** |
||
83 | * @param SourceInterface[] $sources |
||
84 | * |
||
85 | * @return int |
||
86 | */ |
||
87 | 1 | public function count(array $sources) |
|
88 | { |
||
89 | 1 | $count = 1; |
|
90 | 1 | $uniqueSources = []; |
|
91 | 1 | foreach ($sources as $code => $source) { |
|
92 | 1 | $source->withCondition($this->getCondition($code)); |
|
93 | 1 | $uniqueSources[spl_object_hash($source)] = $source; |
|
94 | 1 | } |
|
95 | |||
96 | 1 | foreach ($uniqueSources as $source) { |
|
97 | 1 | $count *= $source->count(); |
|
98 | 1 | } |
|
99 | |||
100 | 1 | return $count; |
|
101 | } |
||
102 | |||
103 | /** {@inheritdoc} */ |
||
104 | 11 | public function getRoute() |
|
108 | } |
||
109 |