Remove FileSystem::fetch() and FileSystem::download()

This commit is contained in:
Giuseppe Criscione 2021-04-22 15:38:58 +02:00
parent 67b7c77ac1
commit 0e79802ddf

View File

@ -716,28 +716,6 @@ class FileSystem
throw new FileSystemException(sprintf('Cannot resolve symbolic link "%s": %s', $link, static::getLastErrorMessage()));
}
/**
* Fetch a remote file
*
* @param resource $context A stream context resource
*/
public static function fetch(string $source, $context = null): string
{
if (filter_var($source, FILTER_VALIDATE_URL) === false) {
throw new FileSystemException(sprintf('Cannot fetch "%s": invalid URI', $source));
}
if ($context !== null) {
$valid = is_resource($context) && get_resource_type($context) === 'stream-context';
if (!$valid) {
throw new FileSystemException('Invalid stream context resource');
}
}
if (($data = @file_get_contents($source, false, $context)) !== false) {
return $data;
}
throw new FileSystemException(sprintf('Cannot fetch "%s": %s', $source, static::getLastErrorMessage()));
}
/**
* Create a new file with empty content
*/
@ -821,22 +799,6 @@ class FileSystem
throw new FileSystemException(sprintf('Cannot create symbolic link "%s": %s', $link, static::getLastErrorMessage()));
}
/**
* Download a file to a destination
*
* @param bool $overwrite Whether to overwrite destination if already exists
* @param resource $context A stream context resource
*/
public static function download(string $source, string $destination, bool $overwrite = false, $context = null): bool
{
if (!$overwrite) {
static::assertExists($destination, false);
}
$data = static::fetch($source, $context);
static::write($destination, $data);
return true;
}
/**
* Convert bytes to a human-readable size
*/