Cache.php000064400000003055150145553630006272 0ustar00key = $key; $this->repository = $repository; if (! is_null($expire)) { $this->expire = (int) ceil($expire / 60); } } /** * 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(); if (! is_null($this->expire)) { $this->repository->put($this->key, $contents, $this->expire); } else { $this->repository->forever($this->key, $contents); } } } Filesystem.php000064400000033126150145553630007415 0ustar00isFile($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 * @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)) { 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; } /** * 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); } } FilesystemAdapter.php000064400000045123150145553630010716 0ustar00driver = $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 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; $disposition = $response->headers->makeDisposition($disposition, $name ?? basename($path)); $response->headers->replace($headers + [ 'Content-Type' => $this->mimeType($path), 'Content-Length' => $this->size($path), 'Content-Disposition' => $disposition, ]); $response->setCallback(function () use ($path) { $stream = $this->driver->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'); } /** * 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 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 ($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.'); } } /** * 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 */ 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); } } FilesystemManager.php000064400000023665150145553630010717 0ustar00app = $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 $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'], 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 ($config['key'] && $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); } } FilesystemServiceProvider.php000064400000003330150145553630012443 0ustar00registerNativeFilesystem(); $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']; } } composer.json000064400000002474150145553630007304 0ustar00{ "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.6.*", "illuminate/support": "5.6.*", "symfony/finder": "~4.0" }, "autoload": { "psr-4": { "Illuminate\\Filesystem\\": "" } }, "extra": { "branch-alias": { "dev-master": "5.6-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" }