Vendor lock
This commit is contained in:
70
vendor/illuminate/filesystem/Cache.php
vendored
Normal file
70
vendor/illuminate/filesystem/Cache.php
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Filesystem;
|
||||
|
||||
use Illuminate\Contracts\Cache\Repository;
|
||||
use League\Flysystem\Cached\Storage\AbstractCache;
|
||||
|
||||
class Cache extends AbstractCache
|
||||
{
|
||||
/**
|
||||
* The cache repository implementation.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Cache\Repository
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* The cache key.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $key;
|
||||
|
||||
/**
|
||||
* The cache expiration time in seconds.
|
||||
*
|
||||
* @var int|null
|
||||
*/
|
||||
protected $expire;
|
||||
|
||||
/**
|
||||
* Create a new cache instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Cache\Repository $repository
|
||||
* @param string $key
|
||||
* @param int|null $expire
|
||||
*/
|
||||
public function __construct(Repository $repository, $key = 'flysystem', $expire = null)
|
||||
{
|
||||
$this->key = $key;
|
||||
$this->expire = $expire;
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
$contents = $this->repository->get($this->key);
|
||||
|
||||
if (! is_null($contents)) {
|
||||
$this->setFromStorage($contents);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist the cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$contents = $this->getForStorage();
|
||||
|
||||
$this->repository->put($this->key, $contents, $this->expire);
|
||||
}
|
||||
}
|
609
vendor/illuminate/filesystem/Filesystem.php
vendored
Normal file
609
vendor/illuminate/filesystem/Filesystem.php
vendored
Normal file
@ -0,0 +1,609 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Filesystem;
|
||||
|
||||
use ErrorException;
|
||||
use FilesystemIterator;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Illuminate\Support\Traits\Macroable;
|
||||
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
||||
|
||||
class Filesystem
|
||||
{
|
||||
use Macroable;
|
||||
|
||||
/**
|
||||
* Determine if a file or directory exists.
|
||||
*
|
||||
* @param string $path
|
||||
* @return bool
|
||||
*/
|
||||
public function exists($path)
|
||||
{
|
||||
return file_exists($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the contents of a file.
|
||||
*
|
||||
* @param string $path
|
||||
* @param bool $lock
|
||||
* @return string
|
||||
*
|
||||
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
|
||||
*/
|
||||
public function get($path, $lock = false)
|
||||
{
|
||||
if ($this->isFile($path)) {
|
||||
return $lock ? $this->sharedGet($path) : file_get_contents($path);
|
||||
}
|
||||
|
||||
throw new FileNotFoundException("File does not exist at path {$path}");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get contents of a file with shared access.
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
public function sharedGet($path)
|
||||
{
|
||||
$contents = '';
|
||||
|
||||
$handle = fopen($path, 'rb');
|
||||
|
||||
if ($handle) {
|
||||
try {
|
||||
if (flock($handle, LOCK_SH)) {
|
||||
clearstatcache(true, $path);
|
||||
|
||||
$contents = fread($handle, $this->size($path) ?: 1);
|
||||
|
||||
flock($handle, LOCK_UN);
|
||||
}
|
||||
} finally {
|
||||
fclose($handle);
|
||||
}
|
||||
}
|
||||
|
||||
return $contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the returned value of a file.
|
||||
*
|
||||
* @param string $path
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
|
||||
*/
|
||||
public function getRequire($path)
|
||||
{
|
||||
if ($this->isFile($path)) {
|
||||
return require $path;
|
||||
}
|
||||
|
||||
throw new FileNotFoundException("File does not exist at path {$path}");
|
||||
}
|
||||
|
||||
/**
|
||||
* Require the given file once.
|
||||
*
|
||||
* @param string $file
|
||||
* @return mixed
|
||||
*/
|
||||
public function requireOnce($file)
|
||||
{
|
||||
require_once $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the MD5 hash of the file at the given path.
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
public function hash($path)
|
||||
{
|
||||
return md5_file($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the contents of a file.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $contents
|
||||
* @param bool $lock
|
||||
* @return int|bool
|
||||
*/
|
||||
public function put($path, $contents, $lock = false)
|
||||
{
|
||||
return file_put_contents($path, $contents, $lock ? LOCK_EX : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the contents of a file, replacing it atomically if it already exists.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $content
|
||||
* @return void
|
||||
*/
|
||||
public function replace($path, $content)
|
||||
{
|
||||
// If the path already exists and is a symlink, get the real path...
|
||||
clearstatcache(true, $path);
|
||||
|
||||
$path = realpath($path) ?: $path;
|
||||
|
||||
$tempPath = tempnam(dirname($path), basename($path));
|
||||
|
||||
// Fix permissions of tempPath because `tempnam()` creates it with permissions set to 0600...
|
||||
chmod($tempPath, 0777 - umask());
|
||||
|
||||
file_put_contents($tempPath, $content);
|
||||
|
||||
rename($tempPath, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepend to a file.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $data
|
||||
* @return int
|
||||
*/
|
||||
public function prepend($path, $data)
|
||||
{
|
||||
if ($this->exists($path)) {
|
||||
return $this->put($path, $data.$this->get($path));
|
||||
}
|
||||
|
||||
return $this->put($path, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append to a file.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $data
|
||||
* @return int
|
||||
*/
|
||||
public function append($path, $data)
|
||||
{
|
||||
return file_put_contents($path, $data, FILE_APPEND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get or set UNIX mode of a file or directory.
|
||||
*
|
||||
* @param string $path
|
||||
* @param int|null $mode
|
||||
* @return mixed
|
||||
*/
|
||||
public function chmod($path, $mode = null)
|
||||
{
|
||||
if ($mode) {
|
||||
return chmod($path, $mode);
|
||||
}
|
||||
|
||||
return substr(sprintf('%o', fileperms($path)), -4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the file at a given path.
|
||||
*
|
||||
* @param string|array $paths
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($paths)
|
||||
{
|
||||
$paths = is_array($paths) ? $paths : func_get_args();
|
||||
|
||||
$success = true;
|
||||
|
||||
foreach ($paths as $path) {
|
||||
try {
|
||||
if (! @unlink($path)) {
|
||||
$success = false;
|
||||
}
|
||||
} catch (ErrorException $e) {
|
||||
$success = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a file to a new location.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $target
|
||||
* @return bool
|
||||
*/
|
||||
public function move($path, $target)
|
||||
{
|
||||
return rename($path, $target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy a file to a new location.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $target
|
||||
* @return bool
|
||||
*/
|
||||
public function copy($path, $target)
|
||||
{
|
||||
return copy($path, $target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a hard link to the target file or directory.
|
||||
*
|
||||
* @param string $target
|
||||
* @param string $link
|
||||
* @return void
|
||||
*/
|
||||
public function link($target, $link)
|
||||
{
|
||||
if (! windows_os()) {
|
||||
return symlink($target, $link);
|
||||
}
|
||||
|
||||
$mode = $this->isDirectory($target) ? 'J' : 'H';
|
||||
|
||||
exec("mklink /{$mode} ".escapeshellarg($link).' '.escapeshellarg($target));
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the file name from a file path.
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
public function name($path)
|
||||
{
|
||||
return pathinfo($path, PATHINFO_FILENAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the trailing name component from a file path.
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
public function basename($path)
|
||||
{
|
||||
return pathinfo($path, PATHINFO_BASENAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the parent directory from a file path.
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
public function dirname($path)
|
||||
{
|
||||
return pathinfo($path, PATHINFO_DIRNAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the file extension from a file path.
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
public function extension($path)
|
||||
{
|
||||
return pathinfo($path, PATHINFO_EXTENSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file type of a given file.
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
public function type($path)
|
||||
{
|
||||
return filetype($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mime-type of a given file.
|
||||
*
|
||||
* @param string $path
|
||||
* @return string|false
|
||||
*/
|
||||
public function mimeType($path)
|
||||
{
|
||||
return finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file size of a given file.
|
||||
*
|
||||
* @param string $path
|
||||
* @return int
|
||||
*/
|
||||
public function size($path)
|
||||
{
|
||||
return filesize($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file's last modification time.
|
||||
*
|
||||
* @param string $path
|
||||
* @return int
|
||||
*/
|
||||
public function lastModified($path)
|
||||
{
|
||||
return filemtime($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given path is a directory.
|
||||
*
|
||||
* @param string $directory
|
||||
* @return bool
|
||||
*/
|
||||
public function isDirectory($directory)
|
||||
{
|
||||
return is_dir($directory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given path is readable.
|
||||
*
|
||||
* @param string $path
|
||||
* @return bool
|
||||
*/
|
||||
public function isReadable($path)
|
||||
{
|
||||
return is_readable($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given path is writable.
|
||||
*
|
||||
* @param string $path
|
||||
* @return bool
|
||||
*/
|
||||
public function isWritable($path)
|
||||
{
|
||||
return is_writable($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given path is a file.
|
||||
*
|
||||
* @param string $file
|
||||
* @return bool
|
||||
*/
|
||||
public function isFile($file)
|
||||
{
|
||||
return is_file($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find path names matching a given pattern.
|
||||
*
|
||||
* @param string $pattern
|
||||
* @param int $flags
|
||||
* @return array
|
||||
*/
|
||||
public function glob($pattern, $flags = 0)
|
||||
{
|
||||
return glob($pattern, $flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of all files in a directory.
|
||||
*
|
||||
* @param string $directory
|
||||
* @param bool $hidden
|
||||
* @return \Symfony\Component\Finder\SplFileInfo[]
|
||||
*/
|
||||
public function files($directory, $hidden = false)
|
||||
{
|
||||
return iterator_to_array(
|
||||
Finder::create()->files()->ignoreDotFiles(! $hidden)->in($directory)->depth(0)->sortByName(),
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the files from the given directory (recursive).
|
||||
*
|
||||
* @param string $directory
|
||||
* @param bool $hidden
|
||||
* @return \Symfony\Component\Finder\SplFileInfo[]
|
||||
*/
|
||||
public function allFiles($directory, $hidden = false)
|
||||
{
|
||||
return iterator_to_array(
|
||||
Finder::create()->files()->ignoreDotFiles(! $hidden)->in($directory)->sortByName(),
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the directories within a given directory.
|
||||
*
|
||||
* @param string $directory
|
||||
* @return array
|
||||
*/
|
||||
public function directories($directory)
|
||||
{
|
||||
$directories = [];
|
||||
|
||||
foreach (Finder::create()->in($directory)->directories()->depth(0)->sortByName() as $dir) {
|
||||
$directories[] = $dir->getPathname();
|
||||
}
|
||||
|
||||
return $directories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a directory.
|
||||
*
|
||||
* @param string $path
|
||||
* @param int $mode
|
||||
* @param bool $recursive
|
||||
* @param bool $force
|
||||
* @return bool
|
||||
*/
|
||||
public function makeDirectory($path, $mode = 0755, $recursive = false, $force = false)
|
||||
{
|
||||
if ($force) {
|
||||
return @mkdir($path, $mode, $recursive);
|
||||
}
|
||||
|
||||
return mkdir($path, $mode, $recursive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a directory.
|
||||
*
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
* @param bool $overwrite
|
||||
* @return bool
|
||||
*/
|
||||
public function moveDirectory($from, $to, $overwrite = false)
|
||||
{
|
||||
if ($overwrite && $this->isDirectory($to) && ! $this->deleteDirectory($to)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return @rename($from, $to) === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy a directory from one location to another.
|
||||
*
|
||||
* @param string $directory
|
||||
* @param string $destination
|
||||
* @param int|null $options
|
||||
* @return bool
|
||||
*/
|
||||
public function copyDirectory($directory, $destination, $options = null)
|
||||
{
|
||||
if (! $this->isDirectory($directory)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$options = $options ?: FilesystemIterator::SKIP_DOTS;
|
||||
|
||||
// If the destination directory does not actually exist, we will go ahead and
|
||||
// create it recursively, which just gets the destination prepared to copy
|
||||
// the files over. Once we make the directory we'll proceed the copying.
|
||||
if (! $this->isDirectory($destination)) {
|
||||
$this->makeDirectory($destination, 0777, true);
|
||||
}
|
||||
|
||||
$items = new FilesystemIterator($directory, $options);
|
||||
|
||||
foreach ($items as $item) {
|
||||
// As we spin through items, we will check to see if the current file is actually
|
||||
// a directory or a file. When it is actually a directory we will need to call
|
||||
// back into this function recursively to keep copying these nested folders.
|
||||
$target = $destination.'/'.$item->getBasename();
|
||||
|
||||
if ($item->isDir()) {
|
||||
$path = $item->getPathname();
|
||||
|
||||
if (! $this->copyDirectory($path, $target, $options)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// If the current items is just a regular file, we will just copy this to the new
|
||||
// location and keep looping. If for some reason the copy fails we'll bail out
|
||||
// and return false, so the developer is aware that the copy process failed.
|
||||
else {
|
||||
if (! $this->copy($item->getPathname(), $target)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively delete a directory.
|
||||
*
|
||||
* The directory itself may be optionally preserved.
|
||||
*
|
||||
* @param string $directory
|
||||
* @param bool $preserve
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteDirectory($directory, $preserve = false)
|
||||
{
|
||||
if (! $this->isDirectory($directory)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$items = new FilesystemIterator($directory);
|
||||
|
||||
foreach ($items as $item) {
|
||||
// If the item is a directory, we can just recurse into the function and
|
||||
// delete that sub-directory otherwise we'll just delete the file and
|
||||
// keep iterating through each file until the directory is cleaned.
|
||||
if ($item->isDir() && ! $item->isLink()) {
|
||||
$this->deleteDirectory($item->getPathname());
|
||||
}
|
||||
|
||||
// If the item is just a file, we can go ahead and delete it since we're
|
||||
// just looping through and waxing all of the files in this directory
|
||||
// and calling directories recursively, so we delete the real path.
|
||||
else {
|
||||
$this->delete($item->getPathname());
|
||||
}
|
||||
}
|
||||
|
||||
if (! $preserve) {
|
||||
@rmdir($directory);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all of the directories within a given directory.
|
||||
*
|
||||
* @param string $directory
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteDirectories($directory)
|
||||
{
|
||||
$allDirectories = $this->directories($directory);
|
||||
|
||||
if (! empty($allDirectories)) {
|
||||
foreach ($allDirectories as $directoryName) {
|
||||
$this->deleteDirectory($directoryName);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty the specified directory of all files and folders.
|
||||
*
|
||||
* @param string $directory
|
||||
* @return bool
|
||||
*/
|
||||
public function cleanDirectory($directory)
|
||||
{
|
||||
return $this->deleteDirectory($directory, true);
|
||||
}
|
||||
}
|
744
vendor/illuminate/filesystem/FilesystemAdapter.php
vendored
Normal file
744
vendor/illuminate/filesystem/FilesystemAdapter.php
vendored
Normal file
@ -0,0 +1,744 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Filesystem;
|
||||
|
||||
use RuntimeException;
|
||||
use Illuminate\Http\File;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
use InvalidArgumentException;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Collection;
|
||||
use League\Flysystem\AdapterInterface;
|
||||
use PHPUnit\Framework\Assert as PHPUnit;
|
||||
use League\Flysystem\FileExistsException;
|
||||
use League\Flysystem\FilesystemInterface;
|
||||
use League\Flysystem\AwsS3v3\AwsS3Adapter;
|
||||
use League\Flysystem\Cached\CachedAdapter;
|
||||
use League\Flysystem\FileNotFoundException;
|
||||
use League\Flysystem\Rackspace\RackspaceAdapter;
|
||||
use League\Flysystem\Adapter\Local as LocalAdapter;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
use Illuminate\Contracts\Filesystem\Cloud as CloudFilesystemContract;
|
||||
use Illuminate\Contracts\Filesystem\Filesystem as FilesystemContract;
|
||||
use Illuminate\Contracts\Filesystem\FileExistsException as ContractFileExistsException;
|
||||
use Illuminate\Contracts\Filesystem\FileNotFoundException as ContractFileNotFoundException;
|
||||
|
||||
/**
|
||||
* @mixin \League\Flysystem\FilesystemInterface
|
||||
*/
|
||||
class FilesystemAdapter implements FilesystemContract, CloudFilesystemContract
|
||||
{
|
||||
/**
|
||||
* The Flysystem filesystem implementation.
|
||||
*
|
||||
* @var \League\Flysystem\FilesystemInterface
|
||||
*/
|
||||
protected $driver;
|
||||
|
||||
/**
|
||||
* Create a new filesystem adapter instance.
|
||||
*
|
||||
* @param \League\Flysystem\FilesystemInterface $driver
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(FilesystemInterface $driver)
|
||||
{
|
||||
$this->driver = $driver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the given file exists.
|
||||
*
|
||||
* @param string|array $path
|
||||
* @return $this
|
||||
*/
|
||||
public function assertExists($path)
|
||||
{
|
||||
$paths = Arr::wrap($path);
|
||||
|
||||
foreach ($paths as $path) {
|
||||
PHPUnit::assertTrue(
|
||||
$this->exists($path), "Unable to find a file at path [{$path}]."
|
||||
);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the given file does not exist.
|
||||
*
|
||||
* @param string|array $path
|
||||
* @return $this
|
||||
*/
|
||||
public function assertMissing($path)
|
||||
{
|
||||
$paths = Arr::wrap($path);
|
||||
|
||||
foreach ($paths as $path) {
|
||||
PHPUnit::assertFalse(
|
||||
$this->exists($path), "Found unexpected file at path [{$path}]."
|
||||
);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a file exists.
|
||||
*
|
||||
* @param string $path
|
||||
* @return bool
|
||||
*/
|
||||
public function exists($path)
|
||||
{
|
||||
return $this->driver->has($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full path for the file at the given "short" path.
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
public function path($path)
|
||||
{
|
||||
return $this->driver->getAdapter()->getPathPrefix().$path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the contents of a file.
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*
|
||||
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
|
||||
*/
|
||||
public function get($path)
|
||||
{
|
||||
try {
|
||||
return $this->driver->read($path);
|
||||
} catch (FileNotFoundException $e) {
|
||||
throw new ContractFileNotFoundException($path, $e->getCode(), $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a streamed response for a given file.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string|null $name
|
||||
* @param array|null $headers
|
||||
* @param string|null $disposition
|
||||
* @return \Symfony\Component\HttpFoundation\StreamedResponse
|
||||
*/
|
||||
public function response($path, $name = null, array $headers = [], $disposition = 'inline')
|
||||
{
|
||||
$response = new StreamedResponse;
|
||||
|
||||
$filename = $name ?? basename($path);
|
||||
|
||||
$disposition = $response->headers->makeDisposition(
|
||||
$disposition, $filename, $this->fallbackName($filename)
|
||||
);
|
||||
|
||||
$response->headers->replace($headers + [
|
||||
'Content-Type' => $this->mimeType($path),
|
||||
'Content-Length' => $this->size($path),
|
||||
'Content-Disposition' => $disposition,
|
||||
]);
|
||||
|
||||
$response->setCallback(function () use ($path) {
|
||||
$stream = $this->readStream($path);
|
||||
fpassthru($stream);
|
||||
fclose($stream);
|
||||
});
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a streamed download response for a given file.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string|null $name
|
||||
* @param array|null $headers
|
||||
* @return \Symfony\Component\HttpFoundation\StreamedResponse
|
||||
*/
|
||||
public function download($path, $name = null, array $headers = [])
|
||||
{
|
||||
return $this->response($path, $name, $headers, 'attachment');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the string to ASCII characters that are equivalent to the given name.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
protected function fallbackName($name)
|
||||
{
|
||||
return str_replace('%', '', Str::ascii($name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the contents of a file.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string|resource $contents
|
||||
* @param mixed $options
|
||||
* @return bool
|
||||
*/
|
||||
public function put($path, $contents, $options = [])
|
||||
{
|
||||
$options = is_string($options)
|
||||
? ['visibility' => $options]
|
||||
: (array) $options;
|
||||
|
||||
// If the given contents is actually a file or uploaded file instance than we will
|
||||
// automatically store the file using a stream. This provides a convenient path
|
||||
// for the developer to store streams without managing them manually in code.
|
||||
if ($contents instanceof File ||
|
||||
$contents instanceof UploadedFile) {
|
||||
return $this->putFile($path, $contents, $options);
|
||||
}
|
||||
|
||||
return is_resource($contents)
|
||||
? $this->driver->putStream($path, $contents, $options)
|
||||
: $this->driver->put($path, $contents, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the uploaded file on the disk.
|
||||
*
|
||||
* @param string $path
|
||||
* @param \Illuminate\Http\File|\Illuminate\Http\UploadedFile $file
|
||||
* @param array $options
|
||||
* @return string|false
|
||||
*/
|
||||
public function putFile($path, $file, $options = [])
|
||||
{
|
||||
return $this->putFileAs($path, $file, $file->hashName(), $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the uploaded file on the disk with a given name.
|
||||
*
|
||||
* @param string $path
|
||||
* @param \Illuminate\Http\File|\Illuminate\Http\UploadedFile $file
|
||||
* @param string $name
|
||||
* @param array $options
|
||||
* @return string|false
|
||||
*/
|
||||
public function putFileAs($path, $file, $name, $options = [])
|
||||
{
|
||||
$stream = fopen($file->getRealPath(), 'r');
|
||||
|
||||
// Next, we will format the path of the file and store the file using a stream since
|
||||
// they provide better performance than alternatives. Once we write the file this
|
||||
// stream will get closed automatically by us so the developer doesn't have to.
|
||||
$result = $this->put(
|
||||
$path = trim($path.'/'.$name, '/'), $stream, $options
|
||||
);
|
||||
|
||||
if (is_resource($stream)) {
|
||||
fclose($stream);
|
||||
}
|
||||
|
||||
return $result ? $path : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the visibility for the given path.
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
public function getVisibility($path)
|
||||
{
|
||||
if ($this->driver->getVisibility($path) == AdapterInterface::VISIBILITY_PUBLIC) {
|
||||
return FilesystemContract::VISIBILITY_PUBLIC;
|
||||
}
|
||||
|
||||
return FilesystemContract::VISIBILITY_PRIVATE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the visibility for the given path.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $visibility
|
||||
* @return bool
|
||||
*/
|
||||
public function setVisibility($path, $visibility)
|
||||
{
|
||||
return $this->driver->setVisibility($path, $this->parseVisibility($visibility));
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepend to a file.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $data
|
||||
* @param string $separator
|
||||
* @return bool
|
||||
*/
|
||||
public function prepend($path, $data, $separator = PHP_EOL)
|
||||
{
|
||||
if ($this->exists($path)) {
|
||||
return $this->put($path, $data.$separator.$this->get($path));
|
||||
}
|
||||
|
||||
return $this->put($path, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append to a file.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $data
|
||||
* @param string $separator
|
||||
* @return bool
|
||||
*/
|
||||
public function append($path, $data, $separator = PHP_EOL)
|
||||
{
|
||||
if ($this->exists($path)) {
|
||||
return $this->put($path, $this->get($path).$separator.$data);
|
||||
}
|
||||
|
||||
return $this->put($path, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the file at a given path.
|
||||
*
|
||||
* @param string|array $paths
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($paths)
|
||||
{
|
||||
$paths = is_array($paths) ? $paths : func_get_args();
|
||||
|
||||
$success = true;
|
||||
|
||||
foreach ($paths as $path) {
|
||||
try {
|
||||
if (! $this->driver->delete($path)) {
|
||||
$success = false;
|
||||
}
|
||||
} catch (FileNotFoundException $e) {
|
||||
$success = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy a file to a new location.
|
||||
*
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
* @return bool
|
||||
*/
|
||||
public function copy($from, $to)
|
||||
{
|
||||
return $this->driver->copy($from, $to);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a file to a new location.
|
||||
*
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
* @return bool
|
||||
*/
|
||||
public function move($from, $to)
|
||||
{
|
||||
return $this->driver->rename($from, $to);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file size of a given file.
|
||||
*
|
||||
* @param string $path
|
||||
* @return int
|
||||
*/
|
||||
public function size($path)
|
||||
{
|
||||
return $this->driver->getSize($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mime-type of a given file.
|
||||
*
|
||||
* @param string $path
|
||||
* @return string|false
|
||||
*/
|
||||
public function mimeType($path)
|
||||
{
|
||||
return $this->driver->getMimetype($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file's last modification time.
|
||||
*
|
||||
* @param string $path
|
||||
* @return int
|
||||
*/
|
||||
public function lastModified($path)
|
||||
{
|
||||
return $this->driver->getTimestamp($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL for the file at the given path.
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function url($path)
|
||||
{
|
||||
$adapter = $this->driver->getAdapter();
|
||||
|
||||
if ($adapter instanceof CachedAdapter) {
|
||||
$adapter = $adapter->getAdapter();
|
||||
}
|
||||
|
||||
if (method_exists($adapter, 'getUrl')) {
|
||||
return $adapter->getUrl($path);
|
||||
} elseif (method_exists($this->driver, 'getUrl')) {
|
||||
return $this->driver->getUrl($path);
|
||||
} elseif ($adapter instanceof AwsS3Adapter) {
|
||||
return $this->getAwsUrl($adapter, $path);
|
||||
} elseif ($adapter instanceof RackspaceAdapter) {
|
||||
return $this->getRackspaceUrl($adapter, $path);
|
||||
} elseif ($adapter instanceof LocalAdapter) {
|
||||
return $this->getLocalUrl($path);
|
||||
} else {
|
||||
throw new RuntimeException('This driver does not support retrieving URLs.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function readStream($path)
|
||||
{
|
||||
try {
|
||||
return $this->driver->readStream($path) ?: null;
|
||||
} catch (FileNotFoundException $e) {
|
||||
throw new ContractFileNotFoundException($e->getMessage(), $e->getCode(), $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function writeStream($path, $resource, array $options = [])
|
||||
{
|
||||
try {
|
||||
return $this->driver->writeStream($path, $resource, $options);
|
||||
} catch (FileExistsException $e) {
|
||||
throw new ContractFileExistsException($e->getMessage(), $e->getCode(), $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL for the file at the given path.
|
||||
*
|
||||
* @param \League\Flysystem\AwsS3v3\AwsS3Adapter $adapter
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
protected function getAwsUrl($adapter, $path)
|
||||
{
|
||||
// If an explicit base URL has been set on the disk configuration then we will use
|
||||
// it as the base URL instead of the default path. This allows the developer to
|
||||
// have full control over the base path for this filesystem's generated URLs.
|
||||
if (! is_null($url = $this->driver->getConfig()->get('url'))) {
|
||||
return $this->concatPathToUrl($url, $adapter->getPathPrefix().$path);
|
||||
}
|
||||
|
||||
return $adapter->getClient()->getObjectUrl(
|
||||
$adapter->getBucket(), $adapter->getPathPrefix().$path
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL for the file at the given path.
|
||||
*
|
||||
* @param \League\Flysystem\Rackspace\RackspaceAdapter $adapter
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
protected function getRackspaceUrl($adapter, $path)
|
||||
{
|
||||
return (string) $adapter->getContainer()->getObject($path)->getPublicUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL for the file at the given path.
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
protected function getLocalUrl($path)
|
||||
{
|
||||
$config = $this->driver->getConfig();
|
||||
|
||||
// If an explicit base URL has been set on the disk configuration then we will use
|
||||
// it as the base URL instead of the default path. This allows the developer to
|
||||
// have full control over the base path for this filesystem's generated URLs.
|
||||
if ($config->has('url')) {
|
||||
return $this->concatPathToUrl($config->get('url'), $path);
|
||||
}
|
||||
|
||||
$path = '/storage/'.$path;
|
||||
|
||||
// If the path contains "storage/public", it probably means the developer is using
|
||||
// the default disk to generate the path instead of the "public" disk like they
|
||||
// are really supposed to use. We will remove the public from this path here.
|
||||
if (Str::contains($path, '/storage/public/')) {
|
||||
return Str::replaceFirst('/public/', '/', $path);
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a temporary URL for the file at the given path.
|
||||
*
|
||||
* @param string $path
|
||||
* @param \DateTimeInterface $expiration
|
||||
* @param array $options
|
||||
* @return string
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function temporaryUrl($path, $expiration, array $options = [])
|
||||
{
|
||||
$adapter = $this->driver->getAdapter();
|
||||
|
||||
if ($adapter instanceof CachedAdapter) {
|
||||
$adapter = $adapter->getAdapter();
|
||||
}
|
||||
|
||||
if (method_exists($adapter, 'getTemporaryUrl')) {
|
||||
return $adapter->getTemporaryUrl($path, $expiration, $options);
|
||||
} elseif ($adapter instanceof AwsS3Adapter) {
|
||||
return $this->getAwsTemporaryUrl($adapter, $path, $expiration, $options);
|
||||
} elseif ($adapter instanceof RackspaceAdapter) {
|
||||
return $this->getRackspaceTemporaryUrl($adapter, $path, $expiration, $options);
|
||||
} else {
|
||||
throw new RuntimeException('This driver does not support creating temporary URLs.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a temporary URL for the file at the given path.
|
||||
*
|
||||
* @param \League\Flysystem\AwsS3v3\AwsS3Adapter $adapter
|
||||
* @param string $path
|
||||
* @param \DateTimeInterface $expiration
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
public function getAwsTemporaryUrl($adapter, $path, $expiration, $options)
|
||||
{
|
||||
$client = $adapter->getClient();
|
||||
|
||||
$command = $client->getCommand('GetObject', array_merge([
|
||||
'Bucket' => $adapter->getBucket(),
|
||||
'Key' => $adapter->getPathPrefix().$path,
|
||||
], $options));
|
||||
|
||||
return (string) $client->createPresignedRequest(
|
||||
$command, $expiration
|
||||
)->getUri();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a temporary URL for the file at the given path.
|
||||
*
|
||||
* @param \League\Flysystem\Rackspace\RackspaceAdapter $adapter
|
||||
* @param string $path
|
||||
* @param \DateTimeInterface $expiration
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
public function getRackspaceTemporaryUrl($adapter, $path, $expiration, $options)
|
||||
{
|
||||
return $adapter->getContainer()->getObject($path)->getTemporaryUrl(
|
||||
Carbon::now()->diffInSeconds($expiration),
|
||||
$options['method'] ?? 'GET',
|
||||
$options['forcePublicUrl'] ?? true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Concatenate a path to a URL.
|
||||
*
|
||||
* @param string $url
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
protected function concatPathToUrl($url, $path)
|
||||
{
|
||||
return rtrim($url, '/').'/'.ltrim($path, '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of all files in a directory.
|
||||
*
|
||||
* @param string|null $directory
|
||||
* @param bool $recursive
|
||||
* @return array
|
||||
*/
|
||||
public function files($directory = null, $recursive = false)
|
||||
{
|
||||
$contents = $this->driver->listContents($directory, $recursive);
|
||||
|
||||
return $this->filterContentsByType($contents, 'file');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the files from the given directory (recursive).
|
||||
*
|
||||
* @param string|null $directory
|
||||
* @return array
|
||||
*/
|
||||
public function allFiles($directory = null)
|
||||
{
|
||||
return $this->files($directory, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the directories within a given directory.
|
||||
*
|
||||
* @param string|null $directory
|
||||
* @param bool $recursive
|
||||
* @return array
|
||||
*/
|
||||
public function directories($directory = null, $recursive = false)
|
||||
{
|
||||
$contents = $this->driver->listContents($directory, $recursive);
|
||||
|
||||
return $this->filterContentsByType($contents, 'dir');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all (recursive) of the directories within a given directory.
|
||||
*
|
||||
* @param string|null $directory
|
||||
* @return array
|
||||
*/
|
||||
public function allDirectories($directory = null)
|
||||
{
|
||||
return $this->directories($directory, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a directory.
|
||||
*
|
||||
* @param string $path
|
||||
* @return bool
|
||||
*/
|
||||
public function makeDirectory($path)
|
||||
{
|
||||
return $this->driver->createDir($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively delete a directory.
|
||||
*
|
||||
* @param string $directory
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteDirectory($directory)
|
||||
{
|
||||
return $this->driver->deleteDir($directory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush the Flysystem cache.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function flushCache()
|
||||
{
|
||||
$adapter = $this->driver->getAdapter();
|
||||
|
||||
if ($adapter instanceof CachedAdapter) {
|
||||
$adapter->getCache()->flush();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Flysystem driver.
|
||||
*
|
||||
* @return \League\Flysystem\FilesystemInterface
|
||||
*/
|
||||
public function getDriver()
|
||||
{
|
||||
return $this->driver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter directory contents by type.
|
||||
*
|
||||
* @param array $contents
|
||||
* @param string $type
|
||||
* @return array
|
||||
*/
|
||||
protected function filterContentsByType($contents, $type)
|
||||
{
|
||||
return Collection::make($contents)
|
||||
->where('type', $type)
|
||||
->pluck('path')
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given visibility value.
|
||||
*
|
||||
* @param string|null $visibility
|
||||
* @return string|null
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected function parseVisibility($visibility)
|
||||
{
|
||||
if (is_null($visibility)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch ($visibility) {
|
||||
case FilesystemContract::VISIBILITY_PUBLIC:
|
||||
return AdapterInterface::VISIBILITY_PUBLIC;
|
||||
case FilesystemContract::VISIBILITY_PRIVATE:
|
||||
return AdapterInterface::VISIBILITY_PRIVATE;
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException("Unknown visibility: {$visibility}");
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass dynamic methods call onto Flysystem.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public function __call($method, array $parameters)
|
||||
{
|
||||
return call_user_func_array([$this->driver, $method], $parameters);
|
||||
}
|
||||
}
|
401
vendor/illuminate/filesystem/FilesystemManager.php
vendored
Normal file
401
vendor/illuminate/filesystem/FilesystemManager.php
vendored
Normal file
@ -0,0 +1,401 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Filesystem;
|
||||
|
||||
use Closure;
|
||||
use Aws\S3\S3Client;
|
||||
use OpenCloud\Rackspace;
|
||||
use Illuminate\Support\Arr;
|
||||
use InvalidArgumentException;
|
||||
use League\Flysystem\AdapterInterface;
|
||||
use League\Flysystem\Sftp\SftpAdapter;
|
||||
use League\Flysystem\FilesystemInterface;
|
||||
use League\Flysystem\Cached\CachedAdapter;
|
||||
use League\Flysystem\Filesystem as Flysystem;
|
||||
use League\Flysystem\Adapter\Ftp as FtpAdapter;
|
||||
use League\Flysystem\Rackspace\RackspaceAdapter;
|
||||
use League\Flysystem\Adapter\Local as LocalAdapter;
|
||||
use League\Flysystem\AwsS3v3\AwsS3Adapter as S3Adapter;
|
||||
use League\Flysystem\Cached\Storage\Memory as MemoryStore;
|
||||
use Illuminate\Contracts\Filesystem\Factory as FactoryContract;
|
||||
|
||||
/**
|
||||
* @mixin \Illuminate\Contracts\Filesystem\Filesystem
|
||||
*/
|
||||
class FilesystemManager implements FactoryContract
|
||||
{
|
||||
/**
|
||||
* The application instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Foundation\Application
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* The array of resolved filesystem drivers.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $disks = [];
|
||||
|
||||
/**
|
||||
* The registered custom driver creators.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $customCreators = [];
|
||||
|
||||
/**
|
||||
* Create a new filesystem manager instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Foundation\Application $app
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($app)
|
||||
{
|
||||
$this->app = $app;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a filesystem instance.
|
||||
*
|
||||
* @param string|null $name
|
||||
* @return \Illuminate\Contracts\Filesystem\Filesystem
|
||||
*/
|
||||
public function drive($name = null)
|
||||
{
|
||||
return $this->disk($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a filesystem instance.
|
||||
*
|
||||
* @param string|null $name
|
||||
* @return \Illuminate\Contracts\Filesystem\Filesystem
|
||||
*/
|
||||
public function disk($name = null)
|
||||
{
|
||||
$name = $name ?: $this->getDefaultDriver();
|
||||
|
||||
return $this->disks[$name] = $this->get($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a default cloud filesystem instance.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Filesystem\Filesystem
|
||||
*/
|
||||
public function cloud()
|
||||
{
|
||||
$name = $this->getDefaultCloudDriver();
|
||||
|
||||
return $this->disks[$name] = $this->get($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to get the disk from the local cache.
|
||||
*
|
||||
* @param string $name
|
||||
* @return \Illuminate\Contracts\Filesystem\Filesystem
|
||||
*/
|
||||
protected function get($name)
|
||||
{
|
||||
return $this->disks[$name] ?? $this->resolve($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the given disk.
|
||||
*
|
||||
* @param string $name
|
||||
* @return \Illuminate\Contracts\Filesystem\Filesystem
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected function resolve($name)
|
||||
{
|
||||
$config = $this->getConfig($name);
|
||||
|
||||
if (isset($this->customCreators[$config['driver']])) {
|
||||
return $this->callCustomCreator($config);
|
||||
}
|
||||
|
||||
$driverMethod = 'create'.ucfirst($config['driver']).'Driver';
|
||||
|
||||
if (method_exists($this, $driverMethod)) {
|
||||
return $this->{$driverMethod}($config);
|
||||
} else {
|
||||
throw new InvalidArgumentException("Driver [{$config['driver']}] is not supported.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call a custom driver creator.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Contracts\Filesystem\Filesystem
|
||||
*/
|
||||
protected function callCustomCreator(array $config)
|
||||
{
|
||||
$driver = $this->customCreators[$config['driver']]($this->app, $config);
|
||||
|
||||
if ($driver instanceof FilesystemInterface) {
|
||||
return $this->adapt($driver);
|
||||
}
|
||||
|
||||
return $driver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the local driver.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Contracts\Filesystem\Filesystem
|
||||
*/
|
||||
public function createLocalDriver(array $config)
|
||||
{
|
||||
$permissions = $config['permissions'] ?? [];
|
||||
|
||||
$links = ($config['links'] ?? null) === 'skip'
|
||||
? LocalAdapter::SKIP_LINKS
|
||||
: LocalAdapter::DISALLOW_LINKS;
|
||||
|
||||
return $this->adapt($this->createFlysystem(new LocalAdapter(
|
||||
$config['root'], $config['lock'] ?? LOCK_EX, $links, $permissions
|
||||
), $config));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the ftp driver.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Contracts\Filesystem\Filesystem
|
||||
*/
|
||||
public function createFtpDriver(array $config)
|
||||
{
|
||||
return $this->adapt($this->createFlysystem(
|
||||
new FtpAdapter($config), $config
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the sftp driver.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Contracts\Filesystem\Filesystem
|
||||
*/
|
||||
public function createSftpDriver(array $config)
|
||||
{
|
||||
return $this->adapt($this->createFlysystem(
|
||||
new SftpAdapter($config), $config
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the Amazon S3 driver.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Contracts\Filesystem\Cloud
|
||||
*/
|
||||
public function createS3Driver(array $config)
|
||||
{
|
||||
$s3Config = $this->formatS3Config($config);
|
||||
|
||||
$root = $s3Config['root'] ?? null;
|
||||
|
||||
$options = $config['options'] ?? [];
|
||||
|
||||
return $this->adapt($this->createFlysystem(
|
||||
new S3Adapter(new S3Client($s3Config), $s3Config['bucket'], $root, $options), $config
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the given S3 configuration with the default options.
|
||||
*
|
||||
* @param array $config
|
||||
* @return array
|
||||
*/
|
||||
protected function formatS3Config(array $config)
|
||||
{
|
||||
$config += ['version' => 'latest'];
|
||||
|
||||
if (! empty($config['key']) && ! empty($config['secret'])) {
|
||||
$config['credentials'] = Arr::only($config, ['key', 'secret', 'token']);
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of the Rackspace driver.
|
||||
*
|
||||
* @param array $config
|
||||
* @return \Illuminate\Contracts\Filesystem\Cloud
|
||||
*/
|
||||
public function createRackspaceDriver(array $config)
|
||||
{
|
||||
$client = new Rackspace($config['endpoint'], [
|
||||
'username' => $config['username'], 'apiKey' => $config['key'],
|
||||
], $config['options'] ?? []);
|
||||
|
||||
$root = $config['root'] ?? null;
|
||||
|
||||
return $this->adapt($this->createFlysystem(
|
||||
new RackspaceAdapter($this->getRackspaceContainer($client, $config), $root), $config
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Rackspace Cloud Files container.
|
||||
*
|
||||
* @param \OpenCloud\Rackspace $client
|
||||
* @param array $config
|
||||
* @return \OpenCloud\ObjectStore\Resource\Container
|
||||
*/
|
||||
protected function getRackspaceContainer(Rackspace $client, array $config)
|
||||
{
|
||||
$urlType = $config['url_type'] ?? null;
|
||||
|
||||
$store = $client->objectStoreService('cloudFiles', $config['region'], $urlType);
|
||||
|
||||
return $store->getContainer($config['container']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Flysystem instance with the given adapter.
|
||||
*
|
||||
* @param \League\Flysystem\AdapterInterface $adapter
|
||||
* @param array $config
|
||||
* @return \League\Flysystem\FilesystemInterface
|
||||
*/
|
||||
protected function createFlysystem(AdapterInterface $adapter, array $config)
|
||||
{
|
||||
$cache = Arr::pull($config, 'cache');
|
||||
|
||||
$config = Arr::only($config, ['visibility', 'disable_asserts', 'url']);
|
||||
|
||||
if ($cache) {
|
||||
$adapter = new CachedAdapter($adapter, $this->createCacheStore($cache));
|
||||
}
|
||||
|
||||
return new Flysystem($adapter, count($config) > 0 ? $config : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a cache store instance.
|
||||
*
|
||||
* @param mixed $config
|
||||
* @return \League\Flysystem\Cached\CacheInterface
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected function createCacheStore($config)
|
||||
{
|
||||
if ($config === true) {
|
||||
return new MemoryStore;
|
||||
}
|
||||
|
||||
return new Cache(
|
||||
$this->app['cache']->store($config['store']),
|
||||
$config['prefix'] ?? 'flysystem',
|
||||
$config['expire'] ?? null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapt the filesystem implementation.
|
||||
*
|
||||
* @param \League\Flysystem\FilesystemInterface $filesystem
|
||||
* @return \Illuminate\Contracts\Filesystem\Filesystem
|
||||
*/
|
||||
protected function adapt(FilesystemInterface $filesystem)
|
||||
{
|
||||
return new FilesystemAdapter($filesystem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the given disk instance.
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $disk
|
||||
* @return $this
|
||||
*/
|
||||
public function set($name, $disk)
|
||||
{
|
||||
$this->disks[$name] = $disk;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the filesystem connection configuration.
|
||||
*
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
protected function getConfig($name)
|
||||
{
|
||||
return $this->app['config']["filesystems.disks.{$name}"];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default driver name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultDriver()
|
||||
{
|
||||
return $this->app['config']['filesystems.default'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default cloud driver name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultCloudDriver()
|
||||
{
|
||||
return $this->app['config']['filesystems.cloud'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset the given disk instances.
|
||||
*
|
||||
* @param array|string $disk
|
||||
* @return $this
|
||||
*/
|
||||
public function forgetDisk($disk)
|
||||
{
|
||||
foreach ((array) $disk as $diskName) {
|
||||
unset($this->disks[$diskName]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a custom driver creator Closure.
|
||||
*
|
||||
* @param string $driver
|
||||
* @param \Closure $callback
|
||||
* @return $this
|
||||
*/
|
||||
public function extend($driver, Closure $callback)
|
||||
{
|
||||
$this->customCreators[$driver] = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically call the default driver instance.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
return $this->disk()->$method(...$parameters);
|
||||
}
|
||||
}
|
82
vendor/illuminate/filesystem/FilesystemServiceProvider.php
vendored
Normal file
82
vendor/illuminate/filesystem/FilesystemServiceProvider.php
vendored
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Filesystem;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class FilesystemServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->registerNativeFilesystem();
|
||||
|
||||
$this->registerFlysystem();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the native filesystem implementation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerNativeFilesystem()
|
||||
{
|
||||
$this->app->singleton('files', function () {
|
||||
return new Filesystem;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the driver based filesystem.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerFlysystem()
|
||||
{
|
||||
$this->registerManager();
|
||||
|
||||
$this->app->singleton('filesystem.disk', function () {
|
||||
return $this->app['filesystem']->disk($this->getDefaultDriver());
|
||||
});
|
||||
|
||||
$this->app->singleton('filesystem.cloud', function () {
|
||||
return $this->app['filesystem']->disk($this->getCloudDriver());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the filesystem manager.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerManager()
|
||||
{
|
||||
$this->app->singleton('filesystem', function () {
|
||||
return new FilesystemManager($this->app);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default file driver.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getDefaultDriver()
|
||||
{
|
||||
return $this->app['config']['filesystems.default'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default cloud based file driver.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getCloudDriver()
|
||||
{
|
||||
return $this->app['config']['filesystems.cloud'];
|
||||
}
|
||||
}
|
21
vendor/illuminate/filesystem/LICENSE.md
vendored
Normal file
21
vendor/illuminate/filesystem/LICENSE.md
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Taylor Otwell
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
43
vendor/illuminate/filesystem/composer.json
vendored
Normal file
43
vendor/illuminate/filesystem/composer.json
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "illuminate/filesystem",
|
||||
"description": "The Illuminate Filesystem package.",
|
||||
"license": "MIT",
|
||||
"homepage": "https://laravel.com",
|
||||
"support": {
|
||||
"issues": "https://github.com/laravel/framework/issues",
|
||||
"source": "https://github.com/laravel/framework"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylor@laravel.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.1.3",
|
||||
"illuminate/contracts": "5.8.*",
|
||||
"illuminate/support": "5.8.*",
|
||||
"symfony/finder": "^4.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Illuminate\\Filesystem\\": ""
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "5.8-dev"
|
||||
}
|
||||
},
|
||||
"suggest": {
|
||||
"league/flysystem": "Required to use the Flysystem local and FTP drivers (^1.0).",
|
||||
"league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (^1.0).",
|
||||
"league/flysystem-cached-adapter": "Required to use the Flysystem cache (^1.0).",
|
||||
"league/flysystem-rackspace": "Required to use the Flysystem Rackspace driver (^1.0).",
|
||||
"league/flysystem-sftp": "Required to use the Flysystem SFTP driver (^1.0)."
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
Reference in New Issue
Block a user