1 | <?php |
||
31 | class Fetcher { |
||
32 | |||
33 | const DEFAULT_BASE_URL = 'https://updates.owncloud.com/server/'; |
||
34 | |||
35 | /** |
||
36 | * @var Locator $locator |
||
37 | */ |
||
38 | protected $locator; |
||
39 | |||
40 | /** |
||
41 | * @var ConfigReader $configReader |
||
42 | */ |
||
43 | protected $configReader; |
||
44 | |||
45 | /** |
||
46 | * @var Client $httpClient |
||
47 | */ |
||
48 | protected $httpClient; |
||
49 | protected $requiredFeedEntries = [ |
||
50 | 'version', |
||
51 | 'versionstring', |
||
52 | 'url' |
||
53 | ]; |
||
54 | |||
55 | /** |
||
56 | * Constructor |
||
57 | * |
||
58 | * @param Client $httpClient |
||
59 | * @param Locator $locator |
||
60 | * @param ConfigReader $configReader |
||
61 | */ |
||
62 | public function __construct(Client $httpClient, Locator $locator, ConfigReader $configReader){ |
||
63 | $this->httpClient = $httpClient; |
||
64 | $this->locator = $locator; |
||
65 | $this->configReader = $configReader; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * Download new ownCloud package |
||
70 | * @param Feed $feed |
||
71 | * @param Callable $onProgress |
||
72 | * @throws \Exception |
||
73 | * @throws \UnexpectedValueException |
||
74 | */ |
||
75 | public function getOwncloud(Feed $feed, callable $onProgress){ |
||
76 | if ($feed->isValid()){ |
||
77 | $downloadPath = $this->getBaseDownloadPath($feed); |
||
78 | if (!is_writable(dirname($downloadPath))){ |
||
79 | throw new \Exception(dirname($downloadPath) . ' is not writable.'); |
||
80 | } |
||
81 | $url = $feed->getUrl(); |
||
82 | $request = $this->httpClient->createRequest( |
||
|
|||
83 | 'GET', |
||
84 | $url, |
||
85 | [ |
||
86 | 'save_to' => $downloadPath, |
||
87 | 'timeout' => 600 |
||
88 | ] |
||
89 | ); |
||
90 | $request->getEmitter()->on('progress', $onProgress); |
||
91 | $response = $this->httpClient->send($request); |
||
92 | $this->validateResponse($response); |
||
93 | } |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * Produce a local path to save the package to |
||
98 | * @param Feed $feed |
||
99 | * @return string |
||
100 | */ |
||
101 | public function getBaseDownloadPath(Feed $feed){ |
||
105 | |||
106 | /** |
||
107 | * Get md5 sum for the package |
||
108 | * @param Feed $feed |
||
109 | * @return string |
||
110 | */ |
||
111 | public function getMd5(Feed $feed){ |
||
117 | |||
118 | /** |
||
119 | * Read update feed for new releases |
||
120 | * @return Feed |
||
121 | */ |
||
122 | public function getFeed(){ |
||
140 | |||
141 | /** |
||
142 | * @return mixed|string |
||
143 | */ |
||
144 | public function getUpdateChannel(){ |
||
152 | |||
153 | /** |
||
154 | * Produce complete feed URL |
||
155 | * @return string |
||
156 | */ |
||
157 | protected function getFeedUrl(){ |
||
175 | |||
176 | /** |
||
177 | * Get URL content |
||
178 | * @param string $url |
||
179 | * @return string |
||
180 | * @throws \UnexpectedValueException |
||
181 | */ |
||
182 | protected function download($url){ |
||
187 | |||
188 | /** |
||
189 | * Check if request was successful |
||
190 | * @param \GuzzleHttp\Message\ResponseInterface $response |
||
191 | * @throws \UnexpectedValueException |
||
192 | */ |
||
193 | protected function validateResponse($response){ |
||
203 | |||
204 | } |
||
205 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.