@@ -60,6 +60,9 @@ discard block |
||
60 | 60 | } |
61 | 61 | } |
62 | 62 | |
63 | + /** |
|
64 | + * @param string $url |
|
65 | + */ |
|
63 | 66 | public function importURL($url) |
64 | 67 | { |
65 | 68 | $struct = parse_url($url); |
@@ -78,6 +81,11 @@ discard block |
||
78 | 81 | } |
79 | 82 | |
80 | 83 | // utility for __construct |
84 | + |
|
85 | + /** |
|
86 | + * @param string $key |
|
87 | + * @param string $default |
|
88 | + */ |
|
81 | 89 | private static function setOr(array $struct, $key, $default=null) |
82 | 90 | { |
83 | 91 | if (!empty($struct[$key])) { |
@@ -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 { |
@@ -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); |