1 | <?php |
||
21 | abstract class AbstractCrawler |
||
22 | { |
||
23 | public const URL_PREFIX = 'http://last.fm'; |
||
24 | |||
25 | public const NEWLINE = "\n"; |
||
26 | |||
27 | /** |
||
28 | * @var ConnectionInterface |
||
29 | */ |
||
30 | private $connection; |
||
31 | |||
32 | /** |
||
33 | * @param ConnectionInterface $connection |
||
34 | */ |
||
35 | public function __construct(ConnectionInterface $connection) |
||
39 | |||
40 | /** |
||
41 | * @param Crawler|null $node |
||
42 | * |
||
43 | * @return array |
||
44 | */ |
||
45 | final protected function crawlEventList(Crawler $node): array |
||
59 | |||
60 | /** |
||
61 | * @param Crawler $node |
||
62 | * @param DateTime $datetime |
||
63 | * |
||
64 | * @return array |
||
65 | */ |
||
66 | protected function crawlEventListGroup(Crawler $node, DateTime $datetime): array |
||
93 | |||
94 | /** |
||
95 | * Crawles a url. |
||
96 | * |
||
97 | * @param string $url |
||
98 | * |
||
99 | * @return Crawler|null |
||
100 | */ |
||
101 | final protected function crawl(string $url): ?Crawler |
||
109 | |||
110 | /** |
||
111 | * Parses a url node. |
||
112 | * |
||
113 | * @param Crawler $node |
||
114 | * @param string $attr |
||
115 | * |
||
116 | * @return string|null |
||
117 | */ |
||
118 | final protected function parseUrl(Crawler $node, string $attr = 'href'): ?string |
||
130 | |||
131 | /** |
||
132 | * Parses an image node. |
||
133 | * |
||
134 | * @param Crawler $node |
||
135 | * |
||
136 | * @return Image|null |
||
137 | */ |
||
138 | final protected function parseImage(Crawler $node): ?Image |
||
148 | |||
149 | /** |
||
150 | * Parses a string node. |
||
151 | * |
||
152 | * @param Crawler $node |
||
153 | * @param bool $multiline |
||
154 | * |
||
155 | * @return string|null |
||
156 | */ |
||
157 | final protected function parseString(Crawler $node, bool $multiline = false): ?string |
||
178 | |||
179 | /** |
||
180 | * Parses a date note. |
||
181 | * |
||
182 | * @param Crawler $node |
||
183 | * |
||
184 | * @return \DateTime|null |
||
185 | */ |
||
186 | final protected function parseDate(Crawler $node): ?\DateTime |
||
196 | } |
||
197 |