private function download($url) { $output = $this->output; $progress = $this->progress; $ctx = stream_context_create(array(), array('notification' => function ($notificationCode, $severity, $message, $messageCode, $bytesTransferred, $bytesMax) use($output, $progress) { switch ($notificationCode) { case STREAM_NOTIFY_FILE_SIZE_IS: $progress->start($output, $bytesMax); break; case STREAM_NOTIFY_PROGRESS: $progress->setCurrent($bytesTransferred); break; } })); $output->writeln("downloading {$url} "); $fileContents = file_get_contents($url, false, $ctx); $progress->finish(); if (!$fileContents) { throw new \Exception('Cannot fetch <' . $url . '>'); } $tmpdir = Util\TmpDir::get(); $path = $tmpdir . DIRECTORY_SEPARATOR . basename($url); if (!file_put_contents($path, $fileContents)) { throw new \Exception('Cannot save temporary file <' . $path . '>'); } return $path; }
public function deliver($target = '', $no_convert = false) { $target = $target ? realpath($target) : Util\TmpDir::get() . DIRECTORY_SEPARATOR . $this->command->getName(); return $this->command->execute($target, $no_convert); }