1 | <?php |
||
13 | abstract class AbstractBaseRetriever implements RetrieverInterface |
||
14 | { |
||
15 | /** @var string */ |
||
16 | private $basePath; |
||
17 | |||
18 | /** @var DownloaderInterface */ |
||
19 | private $downloader; |
||
20 | |||
21 | /** |
||
22 | * This variable stores the list of retrieved resources to avoid infinite recursion |
||
23 | * @var array |
||
24 | */ |
||
25 | private $history = []; |
||
26 | |||
27 | /** |
||
28 | * This method checks if the recently downloaded file from $source located at $path |
||
29 | * is a valid resource, if not will remove the file and throw an exception |
||
30 | * |
||
31 | * @param string $source |
||
32 | * @param string $localpath |
||
33 | * @throws \RuntimeException when the source is not valid |
||
34 | */ |
||
35 | abstract protected function checkIsValidDownloadedFile(string $source, string $localpath); |
||
36 | |||
37 | /** |
||
38 | * Retriever constructor. |
||
39 | * |
||
40 | * @param string $basePath |
||
41 | * @param DownloaderInterface $downloader |
||
42 | */ |
||
43 | 16 | public function __construct($basePath, DownloaderInterface $downloader = null) |
|
48 | |||
49 | 2 | public function getBasePath(): string |
|
53 | |||
54 | 1 | public function getDownloader(): DownloaderInterface |
|
58 | |||
59 | 16 | public function setDownloader(DownloaderInterface $downloader) |
|
63 | |||
64 | 13 | public function buildPath(string $url): string |
|
71 | |||
72 | 10 | public function download(string $resource): string |
|
96 | |||
97 | 3 | public function retrieveHistory(): array |
|
101 | |||
102 | 4 | protected function clearHistory() |
|
106 | |||
107 | 4 | protected function addToHistory(string $source, string $localpath) |
|
111 | |||
112 | 13 | protected function urlParts(string $url) |
|
120 | } |
||
121 |