1 | <?php |
||
72 | class FeedIo |
||
73 | { |
||
74 | |||
75 | /** |
||
76 | * @var \FeedIo\Reader |
||
77 | */ |
||
78 | protected $reader; |
||
79 | |||
80 | /** |
||
81 | * @var \FeedIo\Rule\DateTimeBuilder |
||
82 | */ |
||
83 | protected $dateTimeBuilder; |
||
84 | |||
85 | /** |
||
86 | * @var \Psr\Log\LoggerInterface |
||
87 | */ |
||
88 | protected $logger; |
||
89 | |||
90 | /** |
||
91 | * @var array |
||
92 | */ |
||
93 | protected $standards; |
||
94 | |||
95 | /** |
||
96 | * @var \FeedIo\Reader\FixerSet |
||
97 | */ |
||
98 | protected $fixerSet; |
||
99 | |||
100 | /** |
||
101 | * @param \FeedIo\Adapter\ClientInterface $client |
||
102 | * @param \Psr\Log\LoggerInterface $logger |
||
103 | */ |
||
104 | 8 | public function __construct(ClientInterface $client, LoggerInterface $logger) |
|
105 | { |
||
106 | 8 | $this->logger = $logger; |
|
107 | 8 | $this->dateTimeBuilder = new DateTimeBuilder(); |
|
108 | 8 | $this->setReader(new Reader($client, $logger)); |
|
109 | 8 | $this->loadCommonStandards(); |
|
110 | 8 | $this->loadFixerSet(); |
|
111 | 8 | } |
|
112 | |||
113 | /** |
||
114 | * Loads main standards (RSS, RDF, Atom) in current object's attributes |
||
115 | * |
||
116 | * @return $this |
||
117 | */ |
||
118 | 8 | protected function loadCommonStandards() |
|
127 | |||
128 | /** |
||
129 | * adds a filter to the reader |
||
130 | * |
||
131 | * @param \FeedIo\FilterInterface $filter |
||
132 | * @return $this |
||
133 | */ |
||
134 | 1 | public function addFilter(FilterInterface $filter) |
|
135 | { |
||
136 | 1 | $this->getReader()->addFilter($filter); |
|
137 | |||
138 | 1 | return $this; |
|
139 | } |
||
140 | |||
141 | /** |
||
142 | * Returns main standards |
||
143 | * |
||
144 | * @return array |
||
145 | */ |
||
146 | 8 | public function getCommonStandards() |
|
147 | { |
||
148 | return array( |
||
149 | 8 | 'atom' => new Atom($this->dateTimeBuilder), |
|
150 | 8 | 'rss' => new Rss($this->dateTimeBuilder), |
|
151 | 8 | 'rdf' => new Rdf($this->dateTimeBuilder), |
|
152 | 8 | ); |
|
153 | } |
||
154 | |||
155 | /** |
||
156 | * @param string $name |
||
157 | * @param \FeedIo\StandardAbstract $standard |
||
158 | * @return $this |
||
159 | */ |
||
160 | 8 | public function addStandard($name, StandardAbstract $standard) |
|
170 | |||
171 | /** |
||
172 | * @return \FeedIo\Reader\FixerSet |
||
173 | */ |
||
174 | 1 | public function getFixerSet() |
|
178 | |||
179 | /** |
||
180 | * @return $this |
||
181 | */ |
||
182 | 7 | protected function loadFixerSet() |
|
193 | |||
194 | /** |
||
195 | * @param FixerAbstract $fixer |
||
196 | * @return $this |
||
197 | */ |
||
198 | 7 | public function addFixer(FixerAbstract $fixer) |
|
205 | |||
206 | /** |
||
207 | * @return array |
||
208 | */ |
||
209 | 7 | public function getBaseFixers() |
|
217 | |||
218 | /** |
||
219 | * @param array $formats |
||
220 | * @return $this |
||
221 | */ |
||
222 | 1 | public function addDateFormats(array $formats) |
|
230 | |||
231 | /** |
||
232 | * @return \FeedIo\Rule\DateTimeBuilder |
||
233 | */ |
||
234 | 2 | public function getDateTimeBuilder() |
|
238 | |||
239 | /** |
||
240 | * @return \FeedIo\Reader |
||
241 | */ |
||
242 | 2 | public function getReader() |
|
246 | |||
247 | /** |
||
248 | * @param \FeedIo\Reader |
||
249 | * @return $this |
||
250 | */ |
||
251 | 8 | public function setReader(Reader $reader) |
|
257 | |||
258 | /** |
||
259 | * @param $url |
||
260 | * @param FeedInterface $feed |
||
261 | * @param \DateTime $modifiedSince |
||
262 | * @return \FeedIo\Reader\Result |
||
263 | */ |
||
264 | 1 | public function read($url, FeedInterface $feed = null, \DateTime $modifiedSince = null) |
|
281 | |||
282 | /** |
||
283 | * @param $url |
||
284 | * @param \DateTime $modifiedSince |
||
285 | * @return \FeedIo\Reader\Result |
||
286 | */ |
||
287 | 1 | public function readSince($url, \DateTime $modifiedSince) |
|
291 | |||
292 | /** |
||
293 | * @return $this |
||
294 | */ |
||
295 | public function resetFilters() |
||
301 | |||
302 | /** |
||
303 | * @param FeedInterface $feed |
||
304 | * @param string $standard Standard's name |
||
305 | * @return \DomDocument |
||
306 | */ |
||
307 | 1 | public function format(FeedInterface $feed, $standard) |
|
315 | |||
316 | /** |
||
317 | * @param \FeedIo\FeedInterface $feed |
||
318 | * @return \DomDocument |
||
319 | */ |
||
320 | 1 | public function toRss(FeedInterface $feed) |
|
324 | |||
325 | /** |
||
326 | * @param \FeedIo\FeedInterface $feed |
||
327 | * @return \DomDocument |
||
328 | */ |
||
329 | 1 | public function toAtom(FeedInterface $feed) |
|
333 | |||
334 | /** |
||
335 | * @param string $name |
||
336 | * @return \FeedIo\StandardAbstract |
||
337 | * @throws \OutOfBoundsException |
||
338 | */ |
||
339 | 2 | public function getStandard($name) |
|
348 | |||
349 | /** |
||
350 | * @param \FeedIo\FeedInterface $feed |
||
351 | * @param string $message |
||
352 | * @return $this |
||
353 | */ |
||
354 | 1 | protected function logAction(FeedInterface $feed, $message) |
|
361 | } |
||
362 |