@@ -108,6 +108,12 @@ |
||
| 108 | 108 | }); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | + /** |
|
| 112 | + * @param string $origin |
|
| 113 | + * @param string $fileUrl |
|
| 114 | + * @param boolean $progress |
|
| 115 | + * @param \Closure $exec |
|
| 116 | + */ |
|
| 111 | 117 | protected function fetch($origin, $fileUrl, $progress, $options, $exec) |
| 112 | 118 | { |
| 113 | 119 | do { |
@@ -64,11 +64,11 @@ discard block |
||
| 64 | 64 | * |
| 65 | 65 | * @return bool true |
| 66 | 66 | */ |
| 67 | - public function copy($origin, $fileUrl, $fileName, $progress=true, $options=array()) |
|
| 67 | + public function copy($origin, $fileUrl, $fileName, $progress = true, $options = array()) |
|
| 68 | 68 | { |
| 69 | 69 | $that = $this; // for PHP5.3 |
| 70 | 70 | |
| 71 | - return $this->fetch($origin, $fileUrl, $progress, $options, function ($ch, $request) use ($that, $fileName) { |
|
| 71 | + return $this->fetch($origin, $fileUrl, $progress, $options, function($ch, $request) use ($that, $fileName) { |
|
| 72 | 72 | $outputFile = new OutputFile($fileName); |
| 73 | 73 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); |
| 74 | 74 | curl_setopt($ch, CURLOPT_FILE, $outputFile->getPointer()); |
@@ -95,11 +95,11 @@ discard block |
||
| 95 | 95 | * |
| 96 | 96 | * @return bool|string The content |
| 97 | 97 | */ |
| 98 | - public function getContents($origin, $fileUrl, $progress=true, $options=array()) |
|
| 98 | + public function getContents($origin, $fileUrl, $progress = true, $options = array()) |
|
| 99 | 99 | { |
| 100 | 100 | $that = $this; // for PHP5.3 |
| 101 | 101 | |
| 102 | - return $this->fetch($origin, $fileUrl, $progress, $options, function ($ch, $request) use ($that) { |
|
| 102 | + return $this->fetch($origin, $fileUrl, $progress, $options, function($ch, $request) use ($that) { |
|
| 103 | 103 | // This order is important. |
| 104 | 104 | curl_setopt($ch, CURLOPT_FILE, STDOUT); |
| 105 | 105 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
@@ -154,13 +154,13 @@ discard block |
||
| 154 | 154 | if ($this->pluginConfig['insecure']) { |
| 155 | 155 | $opts[CURLOPT_SSL_VERIFYPEER] = false; |
| 156 | 156 | } |
| 157 | - if (! empty($pluginConfig['capath'])) { |
|
| 157 | + if (!empty($pluginConfig['capath'])) { |
|
| 158 | 158 | $opts[CURLOPT_CAPATH] = $pluginConfig['capath']; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | curl_setopt_array($ch, $opts); |
| 162 | 162 | |
| 163 | - list($execStatus, ) = $exec($ch, $request); |
|
| 163 | + list($execStatus,) = $exec($ch, $request); |
|
| 164 | 164 | } while ($this->_retry); |
| 165 | 165 | |
| 166 | 166 | if ($progress) { |
@@ -224,9 +224,9 @@ discard block |
||
| 224 | 224 | { |
| 225 | 225 | // @codeCoverageIgnoreStart |
| 226 | 226 | if (PHP_VERSION_ID >= 50500) { |
| 227 | - list(, $downBytesMax, $downBytes, , ) = func_get_args(); |
|
| 227 | + list(, $downBytesMax, $downBytes,,) = func_get_args(); |
|
| 228 | 228 | } else { |
| 229 | - list($downBytesMax, $downBytes, , ) = func_get_args(); |
|
| 229 | + list($downBytesMax, $downBytes,,) = func_get_args(); |
|
| 230 | 230 | } |
| 231 | 231 | // @codeCoverageIgnoreEnd |
| 232 | 232 | |
@@ -122,41 +122,41 @@ |
||
| 122 | 122 | } while ($stat === CURLM_CALL_MULTI_PERFORM); |
| 123 | 123 | |
| 124 | 124 | switch (curl_multi_select($mh, 5)) { |
| 125 | - case -1: |
|
| 126 | - usleep(250); |
|
| 127 | - // fall through |
|
| 128 | - case 0: |
|
| 129 | - continue 2; |
|
| 130 | - default: |
|
| 131 | - do { |
|
| 132 | - $stat = curl_multi_exec($mh, $running); |
|
| 133 | - } while ($stat === CURLM_CALL_MULTI_PERFORM); |
|
| 134 | - |
|
| 135 | - do { |
|
| 136 | - if ($raised = curl_multi_info_read($mh, $remains)) { |
|
| 137 | - $ch = $raised['handle']; |
|
| 138 | - $errno = curl_errno($ch); |
|
| 139 | - $info = curl_getinfo($ch); |
|
| 140 | - curl_setopt($ch, CURLOPT_FILE, STDOUT); |
|
| 141 | - $index = (int)$ch; |
|
| 142 | - $outputFile = $chFpMap[$index]; |
|
| 143 | - unset($chFpMap[$index]); |
|
| 144 | - if (CURLE_OK === $errno && 200 === $info['http_code']) { |
|
| 145 | - ++$this->successCnt; |
|
| 146 | - } else { |
|
| 147 | - ++$this->failureCnt; |
|
| 148 | - $outputFile->setFailure(); |
|
| 125 | + case -1: |
|
| 126 | + usleep(250); |
|
| 127 | + // fall through |
|
| 128 | + case 0: |
|
| 129 | + continue 2; |
|
| 130 | + default: |
|
| 131 | + do { |
|
| 132 | + $stat = curl_multi_exec($mh, $running); |
|
| 133 | + } while ($stat === CURLM_CALL_MULTI_PERFORM); |
|
| 134 | + |
|
| 135 | + do { |
|
| 136 | + if ($raised = curl_multi_info_read($mh, $remains)) { |
|
| 137 | + $ch = $raised['handle']; |
|
| 138 | + $errno = curl_errno($ch); |
|
| 139 | + $info = curl_getinfo($ch); |
|
| 140 | + curl_setopt($ch, CURLOPT_FILE, STDOUT); |
|
| 141 | + $index = (int)$ch; |
|
| 142 | + $outputFile = $chFpMap[$index]; |
|
| 143 | + unset($chFpMap[$index]); |
|
| 144 | + if (CURLE_OK === $errno && 200 === $info['http_code']) { |
|
| 145 | + ++$this->successCnt; |
|
| 146 | + } else { |
|
| 147 | + ++$this->failureCnt; |
|
| 148 | + $outputFile->setFailure(); |
|
| 149 | + } |
|
| 150 | + unset($outputFile); |
|
| 151 | + $this->io->write($this->makeDownloadingText($info['url'])); |
|
| 152 | + curl_multi_remove_handle($mh, $ch); |
|
| 153 | + $unused[] = $ch; |
|
| 149 | 154 | } |
| 150 | - unset($outputFile); |
|
| 151 | - $this->io->write($this->makeDownloadingText($info['url'])); |
|
| 152 | - curl_multi_remove_handle($mh, $ch); |
|
| 153 | - $unused[] = $ch; |
|
| 154 | - } |
|
| 155 | - } while ($remains > 0); |
|
| 155 | + } while ($remains > 0); |
|
| 156 | 156 | |
| 157 | - if (count($packages) > 0) { |
|
| 158 | - break 2; |
|
| 159 | - } |
|
| 157 | + if (count($packages) > 0) { |
|
| 158 | + break 2; |
|
| 159 | + } |
|
| 160 | 160 | } |
| 161 | 161 | } while ($running); |
| 162 | 162 | } while (count($packages) > 0); |