1 | <?php |
||
32 | class Reader |
||
33 | { |
||
34 | /** |
||
35 | * @var \FeedIo\Adapter\ClientInterface; |
||
36 | */ |
||
37 | protected $client; |
||
38 | |||
39 | /** |
||
40 | * @var \Psr\Log\LoggerInterface |
||
41 | */ |
||
42 | protected $logger; |
||
43 | |||
44 | /** |
||
45 | * @var array |
||
46 | */ |
||
47 | protected $parsers = array(); |
||
48 | |||
49 | /** |
||
50 | * @param ClientInterface $client |
||
51 | * @param LoggerInterface $logger |
||
52 | 13 | */ |
|
53 | public function __construct(ClientInterface $client, LoggerInterface $logger) |
||
54 | 13 | { |
|
55 | 13 | $this->client = $client; |
|
56 | 13 | $this->logger = $logger; |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * @param Parser $parser |
||
61 | * @return $this |
||
62 | 13 | */ |
|
63 | public function addParser(ParserAbstract $parser) |
||
64 | 13 | { |
|
65 | 13 | $this->logger->debug("new parser added : ".get_class($parser->getStandard())); |
|
66 | $this->parsers[] = $parser; |
||
67 | 13 | ||
68 | return $this; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * adds a filter to every parsers |
||
73 | * |
||
74 | * @param \FeedIo\FilterInterface $filter |
||
75 | * @return $this |
||
76 | 2 | */ |
|
77 | public function addFilter(FilterInterface $filter) |
||
78 | 2 | { |
|
79 | 2 | foreach ($this->parsers as $parser) { |
|
80 | 2 | $parser->addFilter($filter); |
|
81 | } |
||
82 | 2 | ||
83 | return $this; |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * Reset filters on every parsers |
||
88 | * @return $this |
||
89 | 1 | */ |
|
90 | public function resetFilters() |
||
91 | 1 | { |
|
92 | 1 | foreach ($this->parsers as $parser) { |
|
93 | 1 | $parser->resetFilters(); |
|
94 | } |
||
95 | 1 | ||
96 | return $this; |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * @param $url |
||
101 | * @param FeedInterface $feed |
||
102 | * @param \DateTime $modifiedSince |
||
103 | * @return \FeedIo\Reader\Result |
||
104 | * @throws ReadErrorException |
||
105 | 4 | */ |
|
106 | public function read($url, FeedInterface $feed, \DateTime $modifiedSince = null) |
||
125 | 1 | ||
126 | 1 | /** |
|
127 | * @param ResponseInterface $response |
||
128 | * @param FeedInterface $feed |
||
129 | * @return Document |
||
130 | */ |
||
131 | public function handleResponse(ResponseInterface $response, FeedInterface $feed) |
||
143 | |||
144 | /** |
||
145 | * @param Document $document |
||
146 | * @param FeedInterface $feed |
||
147 | * @return FeedInterface |
||
148 | * @throws Parser\UnsupportedFormatException |
||
149 | 4 | * @throws Reader\NoAccurateParserException |
|
150 | */ |
||
151 | 4 | public function parseDocument(Document $document, FeedInterface $feed) |
|
158 | 1 | ||
159 | 1 | /** |
|
160 | * @param Document $document |
||
161 | * @return ParserAbstract |
||
162 | * @throws Reader\NoAccurateParserException |
||
163 | */ |
||
164 | public function getAccurateParser(Document $document) |
||
176 | } |
||
177 |