/** * Download a Builder template from the registery,. * * @param string $template, the selected template * @param bool $force, force download if the template already exists * * @return bool (true = success) */ protected function download($template, $force = false) { $dist = $this->getBuilderPath(); $path = "{$dist}/{$template}"; if (!$this->files->exists($path) || $force) { $bar = $this->createProgressIndicator(); $src = _render(_config('config.archive'), ['registry' => $this->registry, 'template' => $template]); /* get a temp folder to download the template zip to */ $tmp = $this->getBuilderPath(_config('config.tmp')); try { /* download the template zip file, show progress, uncompress and remove */ $bar->start(" Downloading '{$template}' ... "); $this->files->put($tmp, file_get_contents($src, false, stream_context_create([], ['notification' => function ($notification_code) use($bar) { if (in_array($notification_code, [STREAM_NOTIFY_CONNECT, STREAM_NOTIFY_PROGRESS])) { $bar->advance(); } }]))); $this->zip->open($tmp); $this->zip->extractTo($dist); $this->zip->close(); $this->files->moveDirectory("{$path}-master", $path, true); $this->files->deleteDirectory(dirname($tmp)); $bar->finish(" Download '{$template}' was successful "); } catch (\ErrorException $e) { return false; } } else { $this->output->note("Builder template '{$template}' already exists. \nUse --force option to get a fresh copy."); } return true; }