|
3 | 3 | * @file |
4 | 4 | * Contains \RoboFile |
5 | 5 | */ |
| 6 | +namespace DrupalComposer\DrupalScaffold; |
6 | 7 |
|
7 | 8 | use DrupalComposer\DrupalScaffold\Extract; |
8 | 9 |
|
@@ -102,8 +103,30 @@ public function drupal_scaffoldDownload($version = '8', $options = array( |
102 | 103 | * @param string $target |
103 | 104 | */ |
104 | 105 | protected function downloadFile($source, $target) { |
105 | | - $client = new \GuzzleHttp\Client(['base_uri' => dirname($source) . "/"]); |
106 | | - $response = $client->request('GET', basename($source), ['sink' => $target]); |
| 106 | + $this->say("Attempt to download $source to $target"); |
| 107 | + $fp = fopen($target, 'w+'); |
| 108 | + if (!$fp) { |
| 109 | + $this->yell('Could not open target file ' . $target); |
| 110 | + return false; |
| 111 | + } |
| 112 | + $ch = curl_init(); |
| 113 | + curl_setopt($ch, CURLOPT_URL, $source); |
| 114 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); |
| 115 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
| 116 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 100); |
| 117 | + curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); |
| 118 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
| 119 | + curl_setopt($ch, CURLOPT_FILE, $fp); |
| 120 | + $result = curl_exec($ch); |
| 121 | + fclose($fp); |
| 122 | + $details = curl_getinfo($ch); |
| 123 | + curl_close($ch); |
| 124 | + |
| 125 | + if (!array_key_exists('http_code', $details) || ($details['http_code'] != '200')) { |
| 126 | + $this->yell('Could not download ' . $source); |
| 127 | + return false; |
| 128 | + } |
| 129 | + return true; |
107 | 130 | } |
108 | 131 |
|
109 | 132 | } |
0 commit comments