PhpBrew\Downloader\BaseDownloader::download PHP Method

download() public method

public download ( string $url, string $targetFilePath = null ) : boolean | string
$url string the url to be downloaded
$targetFilePath string the path where file to be saved. null means auto-generated temp path
return boolean | string if download successfully, return target file path, otherwise return false.
    public function download($url, $targetFilePath = null)
    {
        if (empty($targetFilePath)) {
            $targetFilePath = tempnam(sys_get_temp_dir(), 'phpbrew_');
            if ($targetFilePath === false) {
                throw new RuntimeException('Fail to create temp file');
            }
        } else {
            if (!file_exists($targetFilePath)) {
                touch($targetFilePath);
            }
        }
        if (!is_writable($targetFilePath)) {
            throw new \RuntimeException("Target path ({$targetFilePath}) is not writable!");
        }
        if ($this->process($url, $targetFilePath)) {
            $this->logger->debug("{$url} => {$targetFilePath}");
            return $targetFilePath;
        } else {
            return false;
        }
    }