1 | <?php |
||
19 | class Downloader implements DownloaderInterface |
||
20 | { |
||
21 | /** @var EventDispatcherInterface */ |
||
22 | private $dispatcher; |
||
23 | |||
24 | /** @var PersistenceHandlerInterface */ |
||
25 | private $persistenceHandler; |
||
26 | |||
27 | /** @var RequestHandlerInterface */ |
||
28 | private $requestHandler; |
||
29 | |||
30 | /** @var int the maximum number of downloaded resources. 0 means no limit */ |
||
31 | private $downloadLimit = 0; |
||
32 | |||
33 | /** @var PostFetchFilterInterface[] */ |
||
34 | private $postFetchFilters = array(); |
||
35 | |||
36 | /** |
||
37 | * @param int Maximum number of resources to download |
||
38 | * @return $this |
||
39 | */ |
||
40 | public function setDownloadLimit($downloadLimit) |
||
45 | |||
46 | /** |
||
47 | * @return int Maximum number of resources to download |
||
48 | */ |
||
49 | public function getDownloadLimit() |
||
50 | { |
||
51 | return $this->downloadLimit; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @param PostFetchFilterInterface $filter |
||
56 | */ |
||
57 | public function addPostFetchFilter(PostFetchFilterInterface $filter) |
||
61 | |||
62 | /** |
||
63 | * @param DiscoveredUri $uri |
||
64 | * @return false|Resource |
||
65 | */ |
||
66 | public function download(DiscoveredUri $uri) |
||
81 | |||
82 | public function isDownLoadLimitExceeded() |
||
83 | { |
||
84 | return $this->getDownloadLimit() !== 0 && $this->getPersistenceHandler()->count() >= $this->getDownloadLimit(); |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * A shortcut for EventDispatcher::dispatch() |
||
89 | * |
||
90 | * @param string $eventName |
||
91 | * @param null|Event $event |
||
92 | */ |
||
93 | private function dispatch($eventName, Event $event = null) |
||
97 | |||
98 | /** |
||
99 | * @param EventDispatcherInterface $eventDispatcher |
||
100 | * @return $this |
||
101 | */ |
||
102 | public function setDispatcher(EventDispatcherInterface $eventDispatcher) |
||
108 | |||
109 | /** |
||
110 | * @return EventDispatcherInterface |
||
111 | */ |
||
112 | public function getDispatcher() |
||
119 | |||
120 | |||
121 | /** |
||
122 | * @param DiscoveredUri $uri |
||
123 | * @return Resource|false |
||
124 | */ |
||
125 | protected function fetchResource(DiscoveredUri $uri) |
||
144 | |||
145 | /** |
||
146 | * @param Resource $resource |
||
147 | * @return bool |
||
148 | */ |
||
149 | private function matchesPostfetchFilter(Resource $resource) |
||
162 | |||
163 | /** |
||
164 | * @param PersistenceHandlerInterface $persistenceHandler |
||
165 | */ |
||
166 | public function setPersistenceHandler(PersistenceHandlerInterface $persistenceHandler) |
||
170 | |||
171 | /** |
||
172 | * @return PersistenceHandlerInterface |
||
173 | */ |
||
174 | public function getPersistenceHandler() |
||
182 | |||
183 | /** |
||
184 | * @param RequestHandlerInterface $requestHandler |
||
185 | */ |
||
186 | public function setRequestHandler(RequestHandlerInterface $requestHandler) |
||
190 | |||
191 | /** |
||
192 | * @return RequestHandlerInterface |
||
193 | */ |
||
194 | public function getRequestHandler() |
||
202 | } |
||
203 |