1 | <?php |
||
18 | class CurlRemoteFilesystem extends Util\RemoteFilesystem |
||
19 | { |
||
20 | protected $io; |
||
21 | protected $config; |
||
22 | protected $options; |
||
23 | |||
24 | protected $retryAuthFailure = true; |
||
25 | |||
26 | protected $pluginConfig; |
||
27 | |||
28 | private $_lastHeaders = array(); |
||
29 | |||
30 | // global flags |
||
31 | private $_retry = false; |
||
32 | private $_degradedMode = false; |
||
33 | |||
34 | /** @var Aspects\JoinPoint */ |
||
35 | public $onPreDownload; |
||
36 | |||
37 | /** @var Aspects\JoinPoint */ |
||
38 | public $onPostDownload; |
||
39 | |||
40 | /** |
||
41 | * @param IO\IOInterface $io |
||
42 | * @param CConfig $config |
||
43 | * @param array $options |
||
44 | */ |
||
45 | 8 | public function __construct(IO\IOInterface $io, CConfig $config, array $options = array()) |
|
51 | |||
52 | 8 | public function setPluginConfig(array $pluginConfig) |
|
56 | |||
57 | /** |
||
58 | * Copy the remote file in local. |
||
59 | * |
||
60 | * @param string $origin host/domain text |
||
61 | * @param string $fileUrl targeturl |
||
62 | * @param string $fileName the local filename |
||
63 | * @param bool $progress Display the progression |
||
64 | * @param array $options Additional context options |
||
65 | * |
||
66 | * @return bool true |
||
67 | */ |
||
68 | 4 | public function copy($origin, $fileUrl, $fileName, $progress = true, $options = array()) |
|
69 | { |
||
70 | 4 | $that = $this; // for PHP5.3 |
|
71 | |||
72 | return $this->fetch($origin, $fileUrl, $progress, $options, function($ch, $request) use ($that, $fileName) { |
||
73 | 4 | $outputFile = new OutputFile($fileName); |
|
74 | 4 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); |
|
75 | 4 | curl_setopt($ch, CURLOPT_FILE, $outputFile->getPointer()); |
|
76 | |||
77 | 4 | list(, $response) = $result = $that->exec($ch, $request); |
|
78 | |||
79 | 2 | curl_setopt($ch, CURLOPT_FILE, STDOUT); |
|
80 | |||
81 | 2 | if (200 === $response->info['http_code']) { |
|
82 | 1 | $outputFile->setSuccess(); |
|
83 | 1 | } |
|
84 | |||
85 | 2 | return $result; |
|
86 | 4 | }); |
|
87 | } |
||
88 | |||
89 | /** |
||
90 | * Get the content. |
||
91 | * |
||
92 | * @param string $origin The origin URL |
||
93 | * @param string $fileUrl The file URL |
||
94 | * @param bool $progress Display the progression |
||
95 | * @param array $options Additional context options |
||
96 | * |
||
97 | * @return bool|string The content |
||
98 | */ |
||
99 | 1 | public function getContents($origin, $fileUrl, $progress = true, $options = array()) |
|
111 | |||
112 | /** |
||
113 | * @param string $origin |
||
114 | * @param string $fileUrl |
||
115 | * @param boolean $progress |
||
116 | * @param \Closure $exec |
||
117 | */ |
||
118 | 5 | protected function fetch($origin, $fileUrl, $progress, $options, $exec) |
|
162 | |||
163 | /** |
||
164 | 5 | * Retrieve the options set in the constructor |
|
165 | * |
||
166 | * @return array Options |
||
167 | 5 | */ |
|
168 | public function getOptions() |
||
172 | |||
173 | 5 | /** |
|
174 | 3 | * Returns the headers of the last request |
|
175 | * |
||
176 | 3 | * @return array |
|
177 | 2 | */ |
|
178 | 2 | public function getLastHeaders() |
|
182 | |||
183 | /** |
||
184 | * @internal |
||
185 | * @param resource $ch |
||
186 | * @param Aspects\HttpGetRequest $request |
||
187 | * @return array {int, Aspects\HttpGetResponse} |
||
188 | 1 | */ |
|
189 | public function exec($ch, Aspects\HttpGetRequest $request) |
||
209 | 5 | ||
210 | /** |
||
211 | 5 | * @internal |
|
212 | 5 | */ |
|
213 | 5 | public function progress() |
|
231 | |||
232 | /** |
||
233 | 4 | * @internal |
|
234 | * @param resource $ch |
||
235 | * @param string $header |
||
236 | * @return int |
||
237 | */ |
||
238 | public function processHeader($ch, $header) |
||
243 | 4 | ||
244 | 1 | protected function promptAuth(Aspects\HttpGetRequest $req, Aspects\HttpGetResponse $res) |
|
248 | } |
||
249 |