public function downloadFile($url, $progress = true)
    {
        /** @var ProgressBar|null $progressBar */
        $progressBar = null;
        $downloadCallback = function ($size, $downloaded, $client, $request, Response $response) use (&$progressBar) {
            // Don't initialize the progress bar for redirects as the size is much smaller.
            if ($response->getStatusCode() >= 300) {
                return;
            }

            if (null === $progressBar) {
                ProgressBar::setPlaceholderFormatterDefinition('max', function (ProgressBar $bar) {
                    return $this->formatSize($bar->getMaxSteps());
                });

                ProgressBar::setPlaceholderFormatterDefinition('current', function (ProgressBar $bar) {
                    return str_pad($this->formatSize($bar->getProgress()), 11, ' ', STR_PAD_LEFT);
                });

                $progressBar = new ProgressBar($this->output, $size);
                $progressBar->setFormat('%current%/%max% %bar%  %percent:3s%%');
                $progressBar->setRedrawFrequency(max(1, floor($size / 1000)));
                $progressBar->setBarWidth(60);

                if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
                    $progressBar->setEmptyBarCharacter('░'); // light shade character \u2591
                    $progressBar->setProgressCharacter('');
                    $progressBar->setBarCharacter('▓'); // dark shade character \u2593
                }

                $progressBar->start();
            }

            $progressBar->setProgress($downloaded);
        };

        $client = $this->getGuzzleClient();

        if ($progress) {
            $this->output->writeln(sprintf("\n Downloading %s...\n", $url));

            $client->getEmitter()->attach(new Progress(null, $downloadCallback));
        }

        $response = $client->get($url);

        $tmpFile = $this->filesystemHelper->newTempFilename();
        $this->fs->dumpFile($tmpFile, $response->getBody());

        if (null !== $progressBar) {
            $progressBar->finish();
            $this->output->writeln("\n");
        }

        return $tmpFile;
    }
public function downloadFile($url, $progress = true)
    {
        /** @var ProgressBar|null $progressBar */
        $progressBar = null;
        $downloadCallback = function ($size, $downloaded, $client, $request, Response $response) use (&$progressBar) {
            // Don't initialize the progress bar for redirects as the size is much smaller.
            if ($response->getStatusCode() >= 300) {
                return;
            }

            if (null === $progressBar) {
                ProgressBar::setPlaceholderFormatterDefinition('max', function (ProgressBar $bar) {
                    return $this->formatSize($bar->getMaxSteps());
                });

                ProgressBar::setPlaceholderFormatterDefinition('current', function (ProgressBar $bar) {
                    return str_pad($this->formatSize($bar->getProgress()), 11, ' ', STR_PAD_LEFT);
                });

                $progressBar = new ProgressBar($this->output, $size);
                $progressBar->setFormat('%current%/%max% %bar%  %percent:3s%%');
                $progressBar->setRedrawFrequency(max(1, floor($size / 1000)));
                $progressBar->setBarWidth(60);

                if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
                    $progressBar->setEmptyBarCharacter('░'); // light shade character \u2591
                    $progressBar->setProgressCharacter('');
                    $progressBar->setBarCharacter('▓'); // dark shade character \u2593
                }

                $progressBar->start();
            }

            $progressBar->setProgress($downloaded);
        };

        $client = $this->getGuzzleClient();

        if ($progress) {
            $this->output->writeln(sprintf("\n Downloading %s...\n", $url));

            $client->getEmitter()->attach(new Progress(null, $downloadCallback));
        }

        $response = $client->get($url);

        $tmpFile = $this->filesystemHelper->newTempFilename();
        $this->fs->dumpFile($tmpFile, $response->getBody());

        if (null !== $progressBar) {
            $progressBar->finish();
            $this->output->writeln("\n");
        }

        return $tmpFile;
    }
public function downloadFile ( $ url , $ progress = true ) { /** @var ProgressBar|null $progressBar */ $ progressBar = null ; $ downloadCallback = function ( $ size , $ downloaded , $ client , $ request , Response $ response ) use ( & $ progressBar ) { // Don't initialize the progress bar for redirects as the size is much smaller. if ( $ response -> getStatusCode ( ) >= 300 ) { return ; } if ( null === $ progressBar ) { ProgressBar :: setPlaceholderFormatterDefinition ( 'max' , function ( ProgressBar $ bar ) { return $ this -> formatSize ( $ bar -> getMaxSteps ( ) ) ; } ) ; ProgressBar :: setPlaceholderFormatterDefinition ( 'current' , function ( ProgressBar $ bar ) { return str_pad ( $ this -> formatSize ( $ bar -> getProgress ( ) ) , 11 , ' ' , STR_PAD_LEFT ) ; } ) ; $ progressBar = new ProgressBar ( $ this -> output , $ size ) ; $ progressBar -> setFormat ( '%current%/%max% %bar%  %percent:3s%%' ) ; $ progressBar -> setRedrawFrequency ( max ( 1 , floor ( $ size / 1000 ) ) ) ; $ progressBar -> setBarWidth ( 60 ) ; if ( ! defined ( 'PHP_WINDOWS_VERSION_BUILD' ) ) { $ progressBar -> setEmptyBarCharacter ( '░'); /  light shade character \u2591 $ progressBar -> setProgressCharacter ( '' ) ; $ progressBar -> setBarCharacter ( '▓'); /  dark shade character \u2593 } $ progressBar -> start ( ) ; } $ progressBar -> setProgress ( $ downloaded ) ; } ; $ client = $ this -> getGuzzleClient ( ) ; if ( $ progress ) { $ this -> output -> writeln ( sprintf ( "\n Downloading %s...\n" , $ url ) ) ; $ client -> getEmitter ( ) -> attach ( new Progress ( null , $ downloadCallback ) ) ; } $ response = $ client -> get ( $ url ) ; $ tmpFile = $ this -> filesystemHelper -> newTempFilename ( ) ; $ this -> fs -> dumpFile ( $ tmpFile , $ response -> getBody ( ) ) ; if ( null !== $ progressBar ) { $ progressBar -> finish ( ) ; $ this -> output -> writeln ( "\n" ) ; } return $ tmpFile ; }
Download a file from the URL to the destination.

@param string $url      Fully qualified URL to the file.
@param bool   $progress Show the progressbar when downloading.
Download a file from the URL to the destination .