+ private function download($source) {
+ $this->info("Fetching remote source %s ... ", $source);
+ if ($this->args["git"]) {
+ $local = new Tempdir("gitclone");
+ $cmd = new ExecCmd("git", $this->args->verbose);
+ $cmd->run(["clone", $source, $local]);
+ if (!$this->args->verbose) {
+ $this->info("OK\n");
+ }
+ } else {
+ $context = stream_context_create([],["notification" => function($notification, $severity, $message, $code, $bytes_cur, $bytes_max) {
+ switch ($notification) {
+ case STREAM_NOTIFY_CONNECT:
+ $this->debug("\n");
+ break;
+ case STREAM_NOTIFY_PROGRESS:
+ if ($bytes_max) {
+ $bytes_pct = $bytes_cur/$bytes_max;
+ $this->debug("\r %3d%% [%s>%s] ",
+ $bytes_pct*100,
+ str_repeat("=", round(70*$bytes_pct)),
+ str_repeat(" ", round(70*(1-$bytes_pct)))
+ );
+ }
+ break;
+ case STREAM_NOTIFY_COMPLETED:
+ /* this is not generated, why? */
+ break;
+ }
+ }]);
+ if (!$remote = fopen($source, "r", false, $context)) {
+ $this->error(null);
+ exit(2);
+ }
+ $local = new Tempfile("remote");
+ if (!stream_copy_to_stream($remote, $local->getStream())) {
+ $this->error(null);
+ exit(2);
+ }
+ $local->closeStream();
+ $this->info("OK\n");