1 | <?php |
||
13 | class CurlRemoteFilesystem extends Util\RemoteFilesystem |
||
14 | { |
||
15 | protected $io; |
||
16 | protected $config; |
||
17 | protected $options; |
||
18 | protected $disableTls; |
||
19 | |||
20 | private $req; |
||
21 | |||
22 | /** |
||
23 | * @inheritDoc |
||
24 | */ |
||
25 | 1 | public function __construct(IO\IOInterface $io, Config $config = null, array $options = array(), $disableTls = false) |
|
33 | |||
34 | /** |
||
35 | * @inheritDoc |
||
36 | */ |
||
37 | 1 | public function getContents($originUrl, $fileUrl, $progress = true, $options = array()) |
|
38 | { |
||
39 | 1 | $res = null; |
|
40 | 1 | if (isset($options['http']['header'])) { |
|
41 | $headers = $options['http']['header']; |
||
42 | 1 | } elseif (isset($options['https']['header'])) { |
|
43 | $headers = $options['https']['header']; |
||
44 | } else { |
||
45 | 1 | $headers = array(); |
|
46 | } |
||
47 | try { |
||
48 | 1 | $this->req = new FetchRequest($fileUrl, $this->io, $this->config); |
|
|
|||
49 | 1 | foreach ($headers as $header) { |
|
50 | list($key, $val) = explode(':', $header, 2); |
||
51 | $this->req->addHeader($key, $val); |
||
52 | } |
||
53 | 1 | $res = $this->req->fetch(); |
|
54 | } catch (\Exception $e) { |
||
55 | $this->io->writeError((string)$e); |
||
56 | } |
||
57 | 1 | if (false === $res) { |
|
58 | 1 | return parent::getContents($originUrl, $fileUrl, $progress, $options); |
|
59 | } else { |
||
60 | return $res; |
||
61 | } |
||
62 | } |
||
63 | |||
64 | 1 | public function getLastHeaders() |
|
72 | |||
73 | 1 | public function __debugInfo() |
|
77 | } |
||
78 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: