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 | |||
33 | /** @var Aspects\JoinPoint */ |
||
34 | public $onPreDownload; |
||
35 | |||
36 | /** @var Aspects\JoinPoint */ |
||
37 | public $onPostDownload; |
||
38 | |||
39 | /** |
||
40 | * @param IO\IOInterface $io |
||
41 | * @param CConfig $config |
||
42 | * @param array $options |
||
43 | */ |
||
44 | 8 | public function __construct(IO\IOInterface $io, CConfig $config, array $options = array()) |
|
50 | |||
51 | 8 | public function setPluginConfig(array $pluginConfig) |
|
55 | |||
56 | /** |
||
57 | * Copy the remote file in local. |
||
58 | * |
||
59 | * @param string $origin host/domain text |
||
60 | * @param string $fileUrl targeturl |
||
61 | * @param string $fileName the local filename |
||
62 | * @param bool $progress Display the progression |
||
63 | * @param array $options Additional context options |
||
64 | * |
||
65 | * @return bool true |
||
66 | */ |
||
67 | 4 | public function copy($origin, $fileUrl, $fileName, $progress = true, $options = array()) |
|
68 | { |
||
69 | 4 | $that = $this; // for PHP5.3 |
|
70 | |||
71 | return $this->fetch($origin, $fileUrl, $progress, $options, function($ch, $request) use ($that, $fileName) { |
||
72 | 4 | $outputFile = new OutputFile($fileName); |
|
73 | 4 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); |
|
74 | 4 | curl_setopt($ch, CURLOPT_FILE, $outputFile->getPointer()); |
|
75 | |||
76 | 4 | list(, $response) = $result = $that->exec($ch, $request); |
|
77 | |||
78 | 2 | curl_setopt($ch, CURLOPT_FILE, STDOUT); |
|
79 | |||
80 | 2 | if (200 === $response->info['http_code']) { |
|
81 | 1 | $outputFile->setSuccess(); |
|
82 | } |
||
83 | |||
84 | 2 | return $result; |
|
85 | 4 | }); |
|
86 | } |
||
87 | |||
88 | /** |
||
89 | * Get the content. |
||
90 | * |
||
91 | * @param string $origin The origin URL |
||
92 | * @param string $fileUrl The file URL |
||
93 | * @param bool $progress Display the progression |
||
94 | * @param array $options Additional context options |
||
95 | * |
||
96 | * @return bool|string The content |
||
97 | */ |
||
98 | 1 | public function getContents($origin, $fileUrl, $progress = true, $options = array()) |
|
110 | |||
111 | /** |
||
112 | * @param string $origin |
||
113 | * @param string $fileUrl |
||
114 | * @param boolean $progress |
||
115 | * @param \Closure $exec |
||
116 | */ |
||
117 | 5 | protected function fetch($origin, $fileUrl, $progress, $options, $exec) |
|
158 | |||
159 | /** |
||
160 | * Retrieve the options set in the constructor |
||
161 | * |
||
162 | * @return array Options |
||
163 | */ |
||
164 | 1 | public function getOptions() |
|
168 | |||
169 | /** |
||
170 | * Returns the headers of the last request |
||
171 | * |
||
172 | * @return array |
||
173 | */ |
||
174 | 1 | public function getLastHeaders() |
|
178 | |||
179 | /** |
||
180 | * @internal |
||
181 | * @param resource $ch |
||
182 | * @param Aspects\HttpGetRequest $request |
||
183 | * @return array {int, Aspects\HttpGetResponse} |
||
184 | */ |
||
185 | 5 | public function exec($ch, Aspects\HttpGetRequest $request) |
|
205 | |||
206 | /** |
||
207 | * @internal |
||
208 | */ |
||
209 | 4 | public function progress() |
|
227 | |||
228 | /** |
||
229 | * @internal |
||
230 | * @param resource $ch |
||
231 | * @param string $header |
||
232 | * @return int |
||
233 | */ |
||
234 | 5 | public function processHeader($ch, $header) |
|
239 | |||
240 | 3 | protected function promptAuth(Aspects\HttpGetRequest $req, Aspects\HttpGetResponse $res) |
|
244 | } |
||
245 |