Pressroom template verwijderd, website naar root van repo

This commit is contained in:
2020-03-22 15:30:52 +01:00
parent 2cb6a77425
commit f3d1c41e91
7620 changed files with 0 additions and 186900 deletions

View File

@@ -0,0 +1,570 @@
<?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
*/
public function put($path, $contents, $lock = false)
{
return file_put_contents($path, $contents, $lock ? LOCK_EX : 0);
}
/**
* 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 $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} \"{$link}\" \"{$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
* @return array
*/
public function files($directory)
{
$glob = glob($directory.DIRECTORY_SEPARATOR.'*');
if ($glob === false) {
return [];
}
// To get the appropriate files, we'll simply glob the directory and filter
// out any "files" that are not truly files so we do not end up with any
// directories in our list, but only true files within the directory.
return array_filter($glob, function ($file) {
return filetype($file) == 'file';
});
}
/**
* Get all of the files from the given directory (recursive).
*
* @param string $directory
* @param bool $hidden
* @return array
*/
public function allFiles($directory, $hidden = false)
{
return iterator_to_array(Finder::create()->files()->ignoreDotFiles(! $hidden)->in($directory), 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) 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)) {
if (! $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 $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;
}
/**
* Empty the specified directory of all files and folders.
*
* @param string $directory
* @return bool
*/
public function cleanDirectory($directory)
{
return $this->deleteDirectory($directory, true);
}
}

View File

@@ -0,0 +1,504 @@
<?php
namespace Illuminate\Filesystem;
use RuntimeException;
use Illuminate\Http\File;
use Illuminate\Support\Str;
use InvalidArgumentException;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Collection;
use League\Flysystem\AdapterInterface;
use PHPUnit\Framework\Assert as PHPUnit;
use League\Flysystem\FilesystemInterface;
use League\Flysystem\AwsS3v3\AwsS3Adapter;
use League\Flysystem\FileNotFoundException;
use League\Flysystem\Adapter\Local as LocalAdapter;
use Illuminate\Contracts\Filesystem\Cloud as CloudFilesystemContract;
use Illuminate\Contracts\Filesystem\Filesystem as FilesystemContract;
use Illuminate\Contracts\Filesystem\FileNotFoundException as ContractFileNotFoundException;
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 $path
* @return void
*/
public function assertExists($path)
{
PHPUnit::assertTrue(
$this->exists($path), "Unable to find a file at path [{$path}]."
);
}
/**
* Assert that the given file does not exist.
*
* @param string $path
* @return void
*/
public function assertMissing($path)
{
PHPUnit::assertFalse(
$this->exists($path), "Found unexpected file at path [{$path}]."
);
}
/**
* Determine if a file exists.
*
* @param string $path
* @return bool
*/
public function exists($path)
{
return $this->driver->has($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);
}
}
/**
* Write the contents of a file.
*
* @param string $path
* @param string|resource $contents
* @param array $options
* @return bool
*/
public function put($path, $contents, $options = [])
{
if (is_string($options)) {
$options = ['visibility' => $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 void
*/
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 int
*/
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 int
*/
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
*/
public function url($path)
{
$adapter = $this->driver->getAdapter();
if (method_exists($adapter, 'getUrl')) {
return $adapter->getUrl($path);
} elseif ($adapter instanceof AwsS3Adapter) {
return $this->getAwsUrl($adapter, $path);
} elseif ($adapter instanceof LocalAdapter) {
return $this->getLocalUrl($path);
} else {
throw new RuntimeException('This driver does not support retrieving URLs.');
}
}
/**
* 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)
{
return $adapter->getClient()->getObjectUrl(
$adapter->getBucket(), $adapter->getPathPrefix().$path
);
}
/**
* 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 rtrim($config->get('url'), '/').'/'.ltrim($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);
} else {
return $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);
}
/**
* 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);
}
}

View File

@@ -0,0 +1,342 @@
<?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\FilesystemInterface;
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 Illuminate\Contracts\Filesystem\Factory as FactoryContract;
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 $name
* @return \Illuminate\Contracts\Filesystem\Filesystem
*/
public function drive($name = null)
{
return $this->disk($name);
}
/**
* Get a filesystem instance.
*
* @param string $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 isset($this->disks[$name]) ? $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 = isset($config['permissions']) ? $config['permissions'] : [];
$links = Arr::get($config, 'links') === 'skip'
? LocalAdapter::SKIP_LINKS
: LocalAdapter::DISALLOW_LINKS;
return $this->adapt($this->createFlysystem(new LocalAdapter(
$config['root'], 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)
{
$ftpConfig = Arr::only($config, [
'host', 'username', 'password', 'port', 'root', 'passive', 'ssl', 'timeout',
]);
return $this->adapt($this->createFlysystem(
new FtpAdapter($ftpConfig), $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 = isset($s3Config['root']) ? $s3Config['root'] : null;
$options = isset($config['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 ($config['key'] && $config['secret']) {
$config['credentials'] = Arr::only($config, ['key', 'secret']);
}
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'],
]);
$root = isset($config['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 = Arr::get($config, 'url_type');
$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\FlysystemInterface
*/
protected function createFlysystem(AdapterInterface $adapter, array $config)
{
$config = Arr::only($config, ['visibility', 'disable_asserts', 'url']);
return new Flysystem($adapter, count($config) > 0 ? $config : 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 void
*/
public function set($name, $disk)
{
$this->disks[$name] = $disk;
}
/**
* 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'];
}
/**
* 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);
}
}

View 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'];
}
}

View File

@@ -0,0 +1,41 @@
{
"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": ">=5.6.4",
"illuminate/contracts": "5.4.*",
"illuminate/support": "5.4.*",
"symfony/finder": "~3.2"
},
"autoload": {
"psr-4": {
"Illuminate\\Filesystem\\": ""
}
},
"extra": {
"branch-alias": {
"dev-master": "5.4-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-rackspace": "Required to use the Flysystem Rackspace driver (~1.0)."
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev"
}