1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Copyright (c) 2011-2015, Celestino Diaz <[email protected]> |
5
|
|
|
* |
6
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
7
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
8
|
|
|
* in the Software without restriction, including without limitation the rights |
9
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
10
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
11
|
|
|
* furnished to do so, subject to the following conditions: |
12
|
|
|
* |
13
|
|
|
* The above copyright notice and this permission notice shall be included in |
14
|
|
|
* all copies or substantial portions of the Software. |
15
|
|
|
* |
16
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
20
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
21
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
22
|
|
|
* THE SOFTWARE. |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace Brickoo\Component\Annotation\Definition; |
26
|
|
|
|
27
|
|
|
use ArrayIterator; |
28
|
|
|
use Brickoo\Component\Common\Collection; |
29
|
|
|
use Brickoo\Component\Common\Exception\InvalidTypeException; |
30
|
|
|
use Brickoo\Component\Common\Assert; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* AnnotationDefinitionTargetFilter |
34
|
|
|
* |
35
|
|
|
* Implements an annotation definition collection target filter. |
36
|
|
|
* Filter annotation definition by its target. |
37
|
|
|
* @author Celestino Diaz <[email protected]> |
38
|
|
|
*/ |
39
|
|
|
class AnnotationDefinitionTargetFilter { |
40
|
|
|
|
41
|
|
|
/** @var \Brickoo\Component\Common\Collection */ |
42
|
|
|
private $definitionsCollection; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Class constructor. |
46
|
|
|
* @param \Brickoo\Component\Common\Collection $definitionsCollection |
47
|
|
|
* @throws InvalidTypeException |
48
|
|
|
*/ |
49
|
2 |
|
public function __construct(Collection $definitionsCollection) { |
50
|
2 |
|
if ($definitionsCollection->getType() !== "Brickoo\\Component\\Annotation\\Definition\\AnnotationDefinition") { |
51
|
1 |
|
throw new InvalidTypeException($definitionsCollection->getType()); |
52
|
|
|
} |
53
|
1 |
|
$this->definitionsCollection = $definitionsCollection; |
54
|
1 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Returns the annotations definitions matching the target |
58
|
|
|
* as an iterable array object. |
59
|
|
|
* @param integer $target |
60
|
|
|
* @return \ArrayIterator |
61
|
|
|
*/ |
62
|
1 |
|
public function filter($target) { |
63
|
1 |
|
Assert::isInteger($target); |
64
|
1 |
|
$annotationsDefinitions = []; |
65
|
1 |
|
foreach ($this->definitionsCollection as $annotationDefinition) { |
66
|
1 |
|
if ($annotationDefinition->isTarget($target)) { |
67
|
1 |
|
$annotationsDefinitions[] = $annotationDefinition; |
68
|
1 |
|
} |
69
|
1 |
|
} |
70
|
1 |
|
return new ArrayIterator($annotationsDefinitions); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
} |
74
|
|
|
|