1 | <?php |
||
9 | class DiscovererSet implements \IteratorAggregate |
||
10 | { |
||
11 | /** |
||
12 | * @var Discoverer[] |
||
13 | */ |
||
14 | private $discoverers = array(); |
||
15 | |||
16 | /** @var Filter[] */ |
||
17 | private $filters = array(); |
||
18 | |||
19 | /** |
||
20 | * @var int maximum crawl depth |
||
21 | */ |
||
22 | public $maxDepth = 3; |
||
23 | |||
24 | /** |
||
25 | * @var array the list of already visited URIs with the depth they were discovered on as value |
||
26 | */ |
||
27 | private $alreadySeenUris = array(); |
||
28 | |||
29 | public function __construct(array $discoverers = array()) |
||
35 | |||
36 | /** |
||
37 | * @param DiscoveredUri $uri |
||
38 | * |
||
39 | * Mark an Uri as already seen. |
||
40 | * |
||
41 | * If it already exists, it is not overwritten, since we want to keep the |
||
42 | * first depth it was found at. |
||
43 | */ |
||
44 | private function markSeen(DiscoveredUri $uri) |
||
51 | |||
52 | /** |
||
53 | * @return bool Returns true if this URI was found at max depth |
||
54 | */ |
||
55 | private function isAtMaxDepth(DiscoveredUri $uri) |
||
62 | |||
63 | /** |
||
64 | * @param Resource $resource |
||
65 | * @return UriInterface[] |
||
66 | */ |
||
67 | public function discover(Resource $resource) |
||
93 | |||
94 | /** |
||
95 | * Sets a discoverer. |
||
96 | * |
||
97 | * @param discovererInterface $discoverer The discoverer instance |
||
98 | * @param string $alias An alias |
||
99 | */ |
||
100 | public function set(DiscovererInterface $discoverer, $alias = null) |
||
109 | |||
110 | /** |
||
111 | * @param PreFetchFilterInterface $filter |
||
112 | */ |
||
113 | public function addFilter(PreFetchFilterInterface $filter) |
||
117 | |||
118 | /** |
||
119 | * Returns true if the discoverer is defined. |
||
120 | * |
||
121 | * @param string $name The discoverer name |
||
122 | * |
||
123 | * @return bool true if the discoverer is defined, false otherwise |
||
124 | */ |
||
125 | public function has($name) |
||
129 | |||
130 | /** |
||
131 | * Gets a discoverer. |
||
132 | * |
||
133 | * @param string $name The discoverer name |
||
134 | * |
||
135 | * @return Discoverer The discoverer instance |
||
136 | * |
||
137 | * @throws InvalidArgumentException if the discoverer is not defined |
||
138 | */ |
||
139 | public function get($name) |
||
147 | |||
148 | public function getIterator() |
||
152 | |||
153 | /** |
||
154 | * @param UriInterface[] $discoveredUris |
||
155 | */ |
||
156 | private function normalize(array &$discoveredUris) |
||
162 | |||
163 | /** |
||
164 | * @param UriInterface[] $discoveredUris |
||
165 | */ |
||
166 | private function filterAlreadySeen(array &$discoveredUris) |
||
174 | |||
175 | /** |
||
176 | * @param UriInterface[] $discoveredUris |
||
177 | */ |
||
178 | private function filter(array &$discoveredUris) |
||
188 | |||
189 | /** |
||
190 | * @param UriInterface[] $discoveredUris |
||
191 | */ |
||
192 | private function removeDuplicates(array &$discoveredUris) |
||
211 | } |
||
212 |