├── LICENSE ├── composer.json ├── config └── flysystem.php └── src ├── Adapter ├── ConnectionFactory.php └── Connector │ ├── AwsS3Connector.php │ ├── AzureConnector.php │ ├── DropboxConnector.php │ ├── FtpConnector.php │ ├── GoogleCloudStorageConnector.php │ ├── GridFSConnector.php │ ├── LocalConnector.php │ ├── NullConnector.php │ ├── SftpConnector.php │ ├── WebDavConnector.php │ └── ZipConnector.php ├── Cache ├── ConnectionFactory.php ├── Connector │ ├── AdapterConnector.php │ └── IlluminateConnector.php └── Storage │ └── IlluminateStorage.php ├── Facades └── Flysystem.php ├── FlysystemFactory.php ├── FlysystemManager.php └── FlysystemServiceProvider.php /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2021 Graham Campbell 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "graham-campbell/flysystem", 3 | "description": "Flysystem Is A Flysystem Bridge For Laravel", 4 | "keywords": ["laravel", "framework", "files", "aws", "s3", "dropbox", "flysystem", "Flysystem", "Laravel Flysystem", "Laravel-Flysystem", "Graham Campbell", "GrahamCampbell"], 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Graham Campbell", 9 | "email": "hello@gjcampbell.co.uk", 10 | "homepage": "https://github.com/GrahamCampbell" 11 | } 12 | ], 13 | "require": { 14 | "php": "^7.4.15 || ^8.0.2", 15 | "graham-campbell/manager": "^4.7", 16 | "illuminate/contracts": "^8.75", 17 | "illuminate/support": "^8.75", 18 | "league/flysystem": "^1.1.9" 19 | }, 20 | "require-dev": { 21 | "alcaeus/mongo-php-adapter": "^1.1", 22 | "graham-campbell/analyzer": "^3.1", 23 | "graham-campbell/testbench": "^5.6", 24 | "league/flysystem-aws-s3-v3": "^1.0", 25 | "league/flysystem-azure-blob-storage": "^0.1.6", 26 | "league/flysystem-cached-adapter": "^1.0", 27 | "spatie/flysystem-dropbox": "^1.0", 28 | "league/flysystem-eventable-filesystem": "^1.0", 29 | "league/flysystem-gridfs": "^1.0", 30 | "league/flysystem-sftp": "^1.0", 31 | "league/flysystem-webdav": "^1.0", 32 | "league/flysystem-ziparchive": "^1.0", 33 | "superbalist/flysystem-google-storage": "^7.2", 34 | "mockery/mockery": "^1.5", 35 | "phpunit/phpunit": "^9.5" 36 | }, 37 | "suggest": { 38 | "alcaeus/mongo-php-adapter": "GridFS adapter support.", 39 | "league/flysystem-aws-s3-v3": "AwsS3 adapter support.", 40 | "league/flysystem-azure-blob-storage": "Azure adapter support.", 41 | "league/flysystem-cached-adapter": "Adapter caching support.", 42 | "spatie/flysystem-dropbox": "Dropbox adapter support.", 43 | "league/flysystem-eventable-filesystem": "Eventable filesystem support.", 44 | "league/flysystem-gridfs": "GridFS adapter support.", 45 | "league/flysystem-replicate-adapter": "Replicate adapter support.", 46 | "league/flysystem-sftp": "Sftp adapter support.", 47 | "league/flysystem-webdav": "WebDav adapter support.", 48 | "league/flysystem-ziparchive": "ZipArchive adapter support.", 49 | "superbalist/flysystem-google-storage": "GoogleCloudStorage adapter support." 50 | }, 51 | "autoload": { 52 | "psr-4": { 53 | "GrahamCampbell\\Flysystem\\": "src/" 54 | } 55 | }, 56 | "autoload-dev": { 57 | "psr-4": { 58 | "GrahamCampbell\\Tests\\Flysystem\\": "tests/" 59 | } 60 | }, 61 | "config": { 62 | "preferred-install": "dist" 63 | }, 64 | "extra": { 65 | "laravel": { 66 | "providers": [ 67 | "GrahamCampbell\\Flysystem\\FlysystemServiceProvider" 68 | ] 69 | } 70 | }, 71 | "minimum-stability": "dev", 72 | "prefer-stable": true 73 | } 74 | -------------------------------------------------------------------------------- /config/flysystem.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | return [ 15 | 16 | /* 17 | |-------------------------------------------------------------------------- 18 | | Default Connection Name 19 | |-------------------------------------------------------------------------- 20 | | 21 | | Here you may specify which of the connections below you wish to use as 22 | | your default connection for all work. Of course, you may use many 23 | | connections at once using the manager class. 24 | | 25 | */ 26 | 27 | 'default' => 'local', 28 | 29 | /* 30 | |-------------------------------------------------------------------------- 31 | | Flysystem Connections 32 | |-------------------------------------------------------------------------- 33 | | 34 | | Here are each of the connections setup for your application. Examples of 35 | | configuring each supported driver is shown below. You can of course have 36 | | multiple connections per driver. 37 | | 38 | */ 39 | 40 | 'connections' => [ 41 | 42 | 'awss3' => [ 43 | 'driver' => 'awss3', 44 | 'key' => 'your-key', 45 | 'secret' => 'your-secret', 46 | 'bucket' => 'your-bucket', 47 | 'region' => 'your-region', 48 | 'version' => 'latest', 49 | // 'bucket_endpoint' => false, 50 | // 'calculate_md5' => true, 51 | // 'scheme' => 'https', 52 | // 'endpoint' => 'your-url', 53 | // 'prefix' => 'your-prefix', 54 | // 'visibility' => 'public', 55 | // 'pirate' => false, 56 | // 'eventable' => true, 57 | // 'cache' => 'foo' 58 | ], 59 | 60 | 'azure' => [ 61 | 'driver' => 'azure', 62 | 'account-name' => 'your-account-name', 63 | 'api-key' => 'your-api-key', 64 | 'container' => 'your-container', 65 | // 'visibility' => 'public', 66 | // 'pirate' => false, 67 | // 'eventable' => true, 68 | // 'cache' => 'foo' 69 | ], 70 | 71 | 'dropbox' => [ 72 | 'driver' => 'dropbox', 73 | 'token' => 'your-token', 74 | // 'prefix' => 'your-prefix', 75 | // 'visibility' => 'public', 76 | // 'pirate' => false, 77 | // 'eventable' => true, 78 | // 'cache' => 'foo' 79 | ], 80 | 81 | 'ftp' => [ 82 | 'driver' => 'ftp', 83 | 'host' => 'ftp.example.com', 84 | 'port' => 21, 85 | 'username' => 'your-username', 86 | 'password' => 'your-password', 87 | // 'root' => '/path/to/root', 88 | // 'passive' => true, 89 | // 'ssl' => true, 90 | // 'timeout' => 20, 91 | // 'visibility' => 'public', 92 | // 'pirate' => false, 93 | // 'eventable' => true, 94 | // 'cache' => 'foo' 95 | ], 96 | 97 | 'gcs' => [ 98 | 'driver' => 'gcs', 99 | 'projectId' => 'your-project-id', 100 | 'keyFile' => 'your-key-file', 101 | 'bucket' => 'your-bucket', 102 | // 'prefix' => 'your-prefix', 103 | // 'apiUri' => 'http://your-domain.com', 104 | ], 105 | 106 | 'gridfs' => [ 107 | 'driver' => 'gridfs', 108 | 'server' => 'mongodb://localhost:27017', 109 | 'database' => 'your-database', 110 | // 'visibility' => 'public', 111 | // 'pirate' => false, 112 | // 'eventable' => true, 113 | // 'cache' => 'foo' 114 | ], 115 | 116 | 'local' => [ 117 | 'driver' => 'local', 118 | 'path' => storage_path('files'), 119 | // 'visibility' => 'public', 120 | // 'pirate' => false, 121 | // 'eventable' => true, 122 | // 'cache' => 'foo' 123 | ], 124 | 125 | 'null' => [ 126 | 'driver' => 'null', 127 | // 'eventable' => true, 128 | // 'cache' => 'foo' 129 | ], 130 | 131 | 'replicate' => [ 132 | 'driver' => 'replicate', 133 | 'source' => 'your-source-adapter', 134 | 'replica' => 'your-replica-adapter', 135 | // 'visibility' => 'public', 136 | // 'pirate' => false, 137 | // 'eventable' => true, 138 | // 'cache' => 'foo' 139 | ], 140 | 141 | 'sftp' => [ 142 | 'driver' => 'sftp', 143 | 'host' => 'sftp.example.com', 144 | 'port' => 22, 145 | 'username' => 'your-username', 146 | 'password' => 'your-password', 147 | // 'privateKey' => 'path/to/or/contents/of/privatekey', 148 | // 'root' => '/path/to/root', 149 | // 'timeout' => 20, 150 | // 'visibility' => 'public', 151 | // 'pirate' => false, 152 | // 'eventable' => true, 153 | // 'cache' => 'foo' 154 | ], 155 | 156 | 'webdav' => [ 157 | 'driver' => 'webdav', 158 | 'baseUri' => 'http://example.org/dav/', 159 | 'userName' => 'your-username', 160 | 'password' => 'your-password', 161 | // 'visibility' => 'public', 162 | // 'pirate' => false, 163 | // 'eventable' => true, 164 | // 'cache' => 'foo' 165 | ], 166 | 167 | 'zip' => [ 168 | 'driver' => 'zip', 169 | 'path' => storage_path('files.zip'), 170 | // 'visibility' => 'public', 171 | // 'pirate' => false, 172 | // 'eventable' => true, 173 | // 'cache' => 'foo' 174 | ], 175 | 176 | ], 177 | 178 | /* 179 | |-------------------------------------------------------------------------- 180 | | Flysystem Cache 181 | |-------------------------------------------------------------------------- 182 | | 183 | | Here are each of the cache configurations setup for your application. 184 | | There are currently two drivers: illuminate and adapter. Examples of 185 | | configuration are included. You can of course have multiple connections 186 | | per driver as shown. 187 | | 188 | */ 189 | 190 | 'cache' => [ 191 | 192 | 'foo' => [ 193 | 'driver' => 'illuminate', 194 | 'connector' => null, // null means use default driver 195 | 'key' => 'foo', 196 | // 'ttl' => 300 197 | ], 198 | 199 | 'bar' => [ 200 | 'driver' => 'illuminate', 201 | 'connector' => 'redis', // config/cache.php 202 | 'key' => 'bar', 203 | 'ttl' => 600, 204 | ], 205 | 206 | 'adapter' => [ 207 | 'driver' => 'adapter', 208 | 'adapter' => 'local', // as defined in connections 209 | 'file' => 'flysystem.json', 210 | 'ttl' => 600, 211 | ], 212 | 213 | ], 214 | 215 | ]; 216 | -------------------------------------------------------------------------------- /src/Adapter/ConnectionFactory.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace GrahamCampbell\Flysystem\Adapter; 15 | 16 | use InvalidArgumentException; 17 | 18 | /** 19 | * This is the adapter connection factory class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class ConnectionFactory 24 | { 25 | /** 26 | * Establish an adapter connection. 27 | * 28 | * @param array $config 29 | * 30 | * @throws \InvalidArgumentException 31 | * 32 | * @return \League\Flysystem\AdapterInterface 33 | */ 34 | public function make(array $config) 35 | { 36 | return $this->createConnector($config)->connect($config); 37 | } 38 | 39 | /** 40 | * Create a connector instance based on the configuration. 41 | * 42 | * @param array $config 43 | * 44 | * @throws \InvalidArgumentException 45 | * 46 | * @return \GrahamCampbell\Manager\ConnectorInterface 47 | */ 48 | public function createConnector(array $config) 49 | { 50 | if (!isset($config['driver'])) { 51 | throw new InvalidArgumentException('A driver must be specified.'); 52 | } 53 | 54 | switch ($config['driver']) { 55 | case 'awss3': 56 | return new Connector\AwsS3Connector(); 57 | case 'azure': 58 | return new Connector\AzureConnector(); 59 | case 'dropbox': 60 | return new Connector\DropboxConnector(); 61 | case 'ftp': 62 | return new Connector\FtpConnector(); 63 | case 'gcs': 64 | return new Connector\GoogleCloudStorageConnector(); 65 | case 'gridfs': 66 | return new Connector\GridFSConnector(); 67 | case 'local': 68 | return new Connector\LocalConnector(); 69 | case 'null': 70 | return new Connector\NullConnector(); 71 | case 'sftp': 72 | return new Connector\SftpConnector(); 73 | case 'webdav': 74 | return new Connector\WebDavConnector(); 75 | case 'zip': 76 | return new Connector\ZipConnector(); 77 | } 78 | 79 | throw new InvalidArgumentException("Unsupported driver [{$config['driver']}]."); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/Adapter/Connector/AwsS3Connector.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace GrahamCampbell\Flysystem\Adapter\Connector; 15 | 16 | use Aws\S3\S3Client; 17 | use GrahamCampbell\Manager\ConnectorInterface; 18 | use Illuminate\Support\Arr; 19 | use InvalidArgumentException; 20 | use League\Flysystem\AwsS3v3\AwsS3Adapter; 21 | 22 | /** 23 | * This is the awss3 connector class. 24 | * 25 | * @author Graham Campbell 26 | * @author Raul Ruiz 27 | */ 28 | final class AwsS3Connector implements ConnectorInterface 29 | { 30 | /** 31 | * Establish an adapter connection. 32 | * 33 | * @param string[] $config 34 | * 35 | * @throws \InvalidArgumentException 36 | * 37 | * @return \League\Flysystem\AwsS3v3\AwsS3Adapter 38 | */ 39 | public function connect(array $config) 40 | { 41 | $auth = self::getAuth($config); 42 | $client = self::getClient($auth); 43 | $config = self::getConfig($config); 44 | 45 | return self::getAdapter($client, $config); 46 | } 47 | 48 | /** 49 | * Get the authentication data. 50 | * 51 | * @param string[] $config 52 | * 53 | * @throws \InvalidArgumentException 54 | * 55 | * @return string[] 56 | */ 57 | private static function getAuth(array $config) 58 | { 59 | if (!array_key_exists('version', $config)) { 60 | throw new InvalidArgumentException('The awss3 connector requires version configuration.'); 61 | } 62 | 63 | if (!array_key_exists('region', $config)) { 64 | throw new InvalidArgumentException('The awss3 connector requires region configuration.'); 65 | } 66 | 67 | $auth = [ 68 | 'region' => $config['region'], 69 | 'version' => $config['version'], 70 | ]; 71 | 72 | if (isset($config['key'])) { 73 | if (!array_key_exists('secret', $config)) { 74 | throw new InvalidArgumentException('The awss3 connector requires authentication.'); 75 | } 76 | $auth['credentials'] = Arr::only($config, ['key', 'secret']); 77 | } 78 | 79 | if (array_key_exists('bucket_endpoint', $config)) { 80 | $auth['bucket_endpoint'] = $config['bucket_endpoint']; 81 | } 82 | 83 | if (array_key_exists('calculate_md5', $config)) { 84 | $auth['calculate_md5'] = $config['calculate_md5']; 85 | } 86 | 87 | if (array_key_exists('scheme', $config)) { 88 | $auth['scheme'] = $config['scheme']; 89 | } 90 | 91 | if (array_key_exists('endpoint', $config)) { 92 | $auth['endpoint'] = $config['endpoint']; 93 | } 94 | 95 | return $auth; 96 | } 97 | 98 | /** 99 | * Get the awss3 client. 100 | * 101 | * @param string[] $auth 102 | * 103 | * @return \Aws\S3\S3Client 104 | */ 105 | private static function getClient(array $auth) 106 | { 107 | return new S3Client($auth); 108 | } 109 | 110 | /** 111 | * Get the configuration. 112 | * 113 | * @param string[] $config 114 | * 115 | * @throws \InvalidArgumentException 116 | * 117 | * @return array 118 | */ 119 | private static function getConfig(array $config) 120 | { 121 | if (!array_key_exists('prefix', $config)) { 122 | $config['prefix'] = null; 123 | } 124 | 125 | if (!array_key_exists('bucket', $config)) { 126 | throw new InvalidArgumentException('The awss3 connector requires bucket configuration.'); 127 | } 128 | 129 | return Arr::only($config, ['bucket', 'prefix']); 130 | } 131 | 132 | /** 133 | * Get the awss3 adapter. 134 | * 135 | * @param \Aws\S3\S3Client $client 136 | * @param string[] $config 137 | * 138 | * @return \League\Flysystem\AwsS3v3\AwsS3Adapter 139 | */ 140 | private static function getAdapter(S3Client $client, array $config) 141 | { 142 | return new AwsS3Adapter($client, $config['bucket'], $config['prefix']); 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /src/Adapter/Connector/AzureConnector.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace GrahamCampbell\Flysystem\Adapter\Connector; 15 | 16 | use GrahamCampbell\Manager\ConnectorInterface; 17 | use Illuminate\Support\Arr; 18 | use InvalidArgumentException; 19 | use League\Flysystem\AzureBlobStorage\AzureBlobStorageAdapter; 20 | use MicrosoftAzure\Storage\Blob\BlobRestProxy; 21 | 22 | /** 23 | * This is the azure connector class. 24 | * 25 | * @author Graham Campbell 26 | */ 27 | final class AzureConnector implements ConnectorInterface 28 | { 29 | /** 30 | * Establish an adapter connection. 31 | * 32 | * @param string[] $config 33 | * 34 | * @throws \InvalidArgumentException 35 | * 36 | * @return \League\Flysystem\AzureBlobStorage\AzureBlobStorageAdapter 37 | */ 38 | public function connect(array $config) 39 | { 40 | $auth = self::getAuth($config); 41 | $client = self::getClient($auth); 42 | $config = self::getConfig($config); 43 | 44 | return self::getAdapter($client, $config); 45 | } 46 | 47 | /** 48 | * Get the authentication data. 49 | * 50 | * @param string[] $config 51 | * 52 | * @throws \InvalidArgumentException 53 | * 54 | * @return string[] 55 | */ 56 | private static function getAuth(array $config) 57 | { 58 | if (!array_key_exists('account-name', $config) || !array_key_exists('api-key', $config)) { 59 | throw new InvalidArgumentException('The azure connector requires authentication.'); 60 | } 61 | 62 | return Arr::only($config, ['account-name', 'api-key']); 63 | } 64 | 65 | /** 66 | * Get the azure client. 67 | * 68 | * @param string[] $auth 69 | * 70 | * @return \MicrosoftAzure\Storage\Blob\BlobRestProxy 71 | */ 72 | private static function getClient(array $auth) 73 | { 74 | $endpoint = sprintf('DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s', $auth['account-name'], $auth['api-key']); 75 | 76 | return BlobRestProxy::createBlobService($endpoint); 77 | } 78 | 79 | /** 80 | * Get the configuration. 81 | * 82 | * @param string[] $config 83 | * 84 | * @return string[] 85 | */ 86 | private static function getConfig(array $config) 87 | { 88 | if (!array_key_exists('container', $config)) { 89 | throw new InvalidArgumentException('The azure connector requires container configuration.'); 90 | } 91 | 92 | return Arr::only($config, ['container']); 93 | } 94 | 95 | /** 96 | * Get the container adapter. 97 | * 98 | * @param \MicrosoftAzure\Storage\Blob\BlobRestProxy $client 99 | * @param string[] $config 100 | * 101 | * @return \League\Flysystem\AzureBlobStorage\AzureBlobStorageAdapter 102 | */ 103 | private static function getAdapter(BlobRestProxy $client, array $config) 104 | { 105 | return new AzureBlobStorageAdapter($client, $config['container']); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/Adapter/Connector/DropboxConnector.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace GrahamCampbell\Flysystem\Adapter\Connector; 15 | 16 | use GrahamCampbell\Manager\ConnectorInterface; 17 | use Illuminate\Support\Arr; 18 | use InvalidArgumentException; 19 | use Spatie\Dropbox\Client; 20 | use Spatie\FlysystemDropbox\DropboxAdapter; 21 | 22 | /** 23 | * This is the dropbox connector class. 24 | * 25 | * @author Graham Campbell 26 | */ 27 | final class DropboxConnector implements ConnectorInterface 28 | { 29 | /** 30 | * Establish an adapter connection. 31 | * 32 | * @param string[] $config 33 | * 34 | * @throws \InvalidArgumentException 35 | * 36 | * @return \Spatie\FlysystemDropbox\DropboxAdapter 37 | */ 38 | public function connect(array $config) 39 | { 40 | $auth = self::getAuth($config); 41 | $client = self::getClient($auth); 42 | $config = self::getConfig($config); 43 | 44 | return self::getAdapter($client, $config); 45 | } 46 | 47 | /** 48 | * Get the authentication data. 49 | * 50 | * @param string[] $config 51 | * 52 | * @throws \InvalidArgumentException 53 | * 54 | * @return string[] 55 | */ 56 | private static function getAuth(array $config) 57 | { 58 | if (!array_key_exists('token', $config)) { 59 | throw new InvalidArgumentException('The dropbox connector requires authentication.'); 60 | } 61 | 62 | return Arr::only($config, ['token']); 63 | } 64 | 65 | /** 66 | * Get the dropbox client. 67 | * 68 | * @param string[] $auth 69 | * 70 | * @return \Spatie\Dropbox\Client 71 | */ 72 | private static function getClient(array $auth) 73 | { 74 | return new Client($auth['token']); 75 | } 76 | 77 | /** 78 | * Get the configuration. 79 | * 80 | * @param string[] $config 81 | * 82 | * @return string[] 83 | */ 84 | private static function getConfig(array $config) 85 | { 86 | if (!array_key_exists('prefix', $config)) { 87 | $config['prefix'] = null; 88 | } 89 | 90 | return Arr::only($config, ['prefix']); 91 | } 92 | 93 | /** 94 | * Get the dropbox adapter. 95 | * 96 | * @param \Spatie\Dropbox\Client $client 97 | * @param string[] $config 98 | * 99 | * @return \Spatie\FlysystemDropbox\DropboxAdapter 100 | */ 101 | private static function getAdapter(Client $client, array $config) 102 | { 103 | return new DropboxAdapter($client, (string) $config['prefix']); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/Adapter/Connector/FtpConnector.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace GrahamCampbell\Flysystem\Adapter\Connector; 15 | 16 | use GrahamCampbell\Manager\ConnectorInterface; 17 | use League\Flysystem\Adapter\Ftp; 18 | 19 | /** 20 | * This is the ftp connector class. 21 | * 22 | * @author Graham Campbell 23 | */ 24 | final class FtpConnector implements ConnectorInterface 25 | { 26 | /** 27 | * Establish an adapter connection. 28 | * 29 | * @param string[] $config 30 | * 31 | * @throws \InvalidArgumentException 32 | * 33 | * @return \League\Flysystem\Adapter\Ftp 34 | */ 35 | public function connect(array $config) 36 | { 37 | return self::getAdapter($config); 38 | } 39 | 40 | /** 41 | * Get the ftp adapter. 42 | * 43 | * @param string[] $config 44 | * 45 | * @return \League\Flysystem\Adapter\Ftp 46 | */ 47 | private static function getAdapter(array $config) 48 | { 49 | return new Ftp($config); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Adapter/Connector/GoogleCloudStorageConnector.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace GrahamCampbell\Flysystem\Adapter\Connector; 15 | 16 | use Google\Cloud\Storage\StorageClient; 17 | use GrahamCampbell\Manager\ConnectorInterface; 18 | use Illuminate\Support\Arr; 19 | use InvalidArgumentException; 20 | use Superbalist\Flysystem\GoogleStorage\GoogleStorageAdapter; 21 | 22 | /** 23 | * This is the gcs connector class. 24 | * 25 | * @author Graham Campbell 26 | * @author Nir Radian 27 | */ 28 | final class GoogleCloudStorageConnector implements ConnectorInterface 29 | { 30 | /** 31 | * Establish an adapter connection. 32 | * 33 | * @param string[] $config 34 | * 35 | * @throws \InvalidArgumentException 36 | * 37 | * @return \Superbalist\Flysystem\GoogleStorage\GoogleStorageAdapter 38 | */ 39 | public function connect(array $config) 40 | { 41 | $auth = self::getAuth($config); 42 | $client = self::getClient($auth); 43 | $config = self::getConfig($config); 44 | 45 | return self::getAdapter($client, $config); 46 | } 47 | 48 | /** 49 | * Get the authentication data. 50 | * 51 | * @param string[] $config 52 | * 53 | * @throws \InvalidArgumentException 54 | * 55 | * @return string[] 56 | */ 57 | private static function getAuth(array $config) 58 | { 59 | if (!array_key_exists('projectId', $config)) { 60 | throw new InvalidArgumentException('The gcs connector requires project id configuration.'); 61 | } 62 | 63 | $auth = [ 64 | 'projectId' => $config['projectId'], 65 | ]; 66 | 67 | if (array_key_exists('keyFile', $config)) { 68 | $auth['keyFilePath'] = $config['keyFile']; 69 | } 70 | 71 | return $auth; 72 | } 73 | 74 | /** 75 | * Get the gcs client. 76 | * 77 | * @param string[] $auth 78 | * 79 | * @return \Google\Cloud\Storage\StorageClient 80 | */ 81 | private static function getClient(array $auth) 82 | { 83 | return new StorageClient($auth); 84 | } 85 | 86 | /** 87 | * Get the configuration. 88 | * 89 | * @param string[] $config 90 | * 91 | * @throws \InvalidArgumentException 92 | * 93 | * @return array 94 | */ 95 | private static function getConfig(array $config) 96 | { 97 | if (!array_key_exists('bucket', $config)) { 98 | throw new InvalidArgumentException('The gcs connector requires bucket configuration.'); 99 | } 100 | 101 | return Arr::only($config, ['bucket', 'prefix', 'apiUri']); 102 | } 103 | 104 | /** 105 | * Get the gcs adapter. 106 | * 107 | * @param \Google\Cloud\Storage\StorageClient $client 108 | * @param string[] $config 109 | * 110 | * @return \Superbalist\Flysystem\GoogleStorage\GoogleStorageAdapter 111 | */ 112 | private static function getAdapter(StorageClient $client, array $config) 113 | { 114 | $bucket = $client->bucket($config['bucket']); 115 | 116 | $adapter = new GoogleStorageAdapter($client, $bucket); 117 | 118 | if (array_key_exists('prefix', $config)) { 119 | $adapter->setPathPrefix($config['prefix']); 120 | } 121 | 122 | if (array_key_exists('apiUri', $config)) { 123 | $adapter->setStorageApiUri($config['apiUri']); 124 | } 125 | 126 | return $adapter; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/Adapter/Connector/GridFSConnector.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace GrahamCampbell\Flysystem\Adapter\Connector; 15 | 16 | use GrahamCampbell\Manager\ConnectorInterface; 17 | use Illuminate\Support\Arr; 18 | use InvalidArgumentException; 19 | use League\Flysystem\GridFS\GridFSAdapter; 20 | use MongoClient; 21 | 22 | /** 23 | * This is the gridfs connector class. 24 | * 25 | * @author Graham Campbell 26 | */ 27 | final class GridFSConnector implements ConnectorInterface 28 | { 29 | /** 30 | * Establish an adapter connection. 31 | * 32 | * @param string[] $config 33 | * 34 | * @throws \InvalidArgumentException 35 | * 36 | * @return \League\Flysystem\GridFS\GridFSAdapter 37 | */ 38 | public function connect(array $config) 39 | { 40 | $auth = self::getAuth($config); 41 | $client = self::getClient($auth); 42 | $config = self::getConfig($config); 43 | 44 | return self::getAdapter($client, $config); 45 | } 46 | 47 | /** 48 | * Get the authentication data. 49 | * 50 | * @param string[] $config 51 | * 52 | * @throws \InvalidArgumentException 53 | * 54 | * @return string[] 55 | */ 56 | private static function getAuth(array $config) 57 | { 58 | if (!array_key_exists('server', $config)) { 59 | throw new InvalidArgumentException('The gridfs connector requires server configuration.'); 60 | } 61 | 62 | return Arr::only($config, ['server']); 63 | } 64 | 65 | /** 66 | * Get the gridfs client. 67 | * 68 | * @param string[] $auth 69 | * 70 | * @return \MongoClient 71 | */ 72 | private static function getClient(array $auth) 73 | { 74 | return new MongoClient($auth['server']); 75 | } 76 | 77 | /** 78 | * Get the configuration. 79 | * 80 | * @param string[] $config 81 | * 82 | * @return string[] 83 | */ 84 | private static function getConfig(array $config) 85 | { 86 | if (!array_key_exists('database', $config)) { 87 | throw new InvalidArgumentException('The gridfs connector requires database configuration.'); 88 | } 89 | 90 | return Arr::only($config, ['database']); 91 | } 92 | 93 | /** 94 | * Get the gridfs adapter. 95 | * 96 | * @param \MongoClient $client 97 | * @param string[] $config 98 | * 99 | * @return \League\Flysystem\GridFS\GridFSAdapter 100 | */ 101 | private static function getAdapter(MongoClient $client, array $config) 102 | { 103 | $fs = $client->selectDB($config['database'])->getGridFS(); 104 | 105 | return new GridFSAdapter($fs); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/Adapter/Connector/LocalConnector.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace GrahamCampbell\Flysystem\Adapter\Connector; 15 | 16 | use GrahamCampbell\Manager\ConnectorInterface; 17 | use Illuminate\Support\Arr; 18 | use InvalidArgumentException; 19 | use League\Flysystem\Adapter\Local; 20 | 21 | /** 22 | * This is the local connector class. 23 | * 24 | * @author Graham Campbell 25 | */ 26 | final class LocalConnector implements ConnectorInterface 27 | { 28 | /** 29 | * Establish an adapter connection. 30 | * 31 | * @param string[] $config 32 | * 33 | * @throws \InvalidArgumentException 34 | * 35 | * @return \League\Flysystem\Adapter\Local 36 | */ 37 | public function connect(array $config) 38 | { 39 | $config = self::getConfig($config); 40 | 41 | return self::getAdapter($config); 42 | } 43 | 44 | /** 45 | * Get the configuration. 46 | * 47 | * @param string[] $config 48 | * 49 | * @throws \InvalidArgumentException 50 | * 51 | * @return string[] 52 | */ 53 | private static function getConfig(array $config) 54 | { 55 | if (!array_key_exists('path', $config)) { 56 | throw new InvalidArgumentException('The local connector requires path configuration.'); 57 | } 58 | 59 | return Arr::only($config, ['path', 'write_flags', 'link_handling', 'permissions']); 60 | } 61 | 62 | /** 63 | * Get the local adapter. 64 | * 65 | * @param string[] $config 66 | * 67 | * @return \League\Flysystem\Adapter\Local 68 | */ 69 | private static function getAdapter(array $config) 70 | { 71 | // Pull parameters from config and set defaults for optional values 72 | $path = $config['path']; 73 | $writeFlags = Arr::get($config, 'write_flags', LOCK_EX); 74 | $linkHandling = Arr::get($config, 'link_handling', Local::DISALLOW_LINKS); 75 | $permissions = Arr::get($config, 'permissions', []); 76 | 77 | return new Local($path, $writeFlags, $linkHandling, $permissions); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/Adapter/Connector/NullConnector.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace GrahamCampbell\Flysystem\Adapter\Connector; 15 | 16 | use GrahamCampbell\Manager\ConnectorInterface; 17 | use League\Flysystem\Adapter\NullAdapter; 18 | 19 | /** 20 | * This is the null connector class. 21 | * 22 | * @author Graham Campbell 23 | */ 24 | final class NullConnector implements ConnectorInterface 25 | { 26 | /** 27 | * Establish an adapter connection. 28 | * 29 | * @param string[] $config 30 | * 31 | * @throws \InvalidArgumentException 32 | * 33 | * @return \League\Flysystem\Adapter\NullAdapter 34 | */ 35 | public function connect(array $config) 36 | { 37 | return self::getAdapter(); 38 | } 39 | 40 | /** 41 | * Get the null adapter. 42 | * 43 | * @return \League\Flysystem\Adapter\NullAdapter 44 | */ 45 | private static function getAdapter() 46 | { 47 | return new NullAdapter(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Adapter/Connector/SftpConnector.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace GrahamCampbell\Flysystem\Adapter\Connector; 15 | 16 | use GrahamCampbell\Manager\ConnectorInterface; 17 | use League\Flysystem\Sftp\SftpAdapter; 18 | 19 | /** 20 | * This is the sftp connector class. 21 | * 22 | * @author Graham Campbell 23 | */ 24 | final class SftpConnector implements ConnectorInterface 25 | { 26 | /** 27 | * Establish an adapter connection. 28 | * 29 | * @param string[] $config 30 | * 31 | * @throws \InvalidArgumentException 32 | * 33 | * @return \League\Flysystem\Sftp\SftpAdapter 34 | */ 35 | public function connect(array $config) 36 | { 37 | return self::getAdapter($config); 38 | } 39 | 40 | /** 41 | * Get the sftp adapter. 42 | * 43 | * @param string[] $config 44 | * 45 | * @return \League\Flysystem\Sftp\SftpAdapter 46 | */ 47 | private static function getAdapter(array $config) 48 | { 49 | return new SftpAdapter($config); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Adapter/Connector/WebDavConnector.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace GrahamCampbell\Flysystem\Adapter\Connector; 15 | 16 | use GrahamCampbell\Manager\ConnectorInterface; 17 | use Illuminate\Support\Arr; 18 | use League\Flysystem\WebDAV\WebDAVAdapter; 19 | use Sabre\DAV\Client; 20 | 21 | /** 22 | * This is the webdav connector class. 23 | * 24 | * @author Graham Campbell 25 | */ 26 | final class WebDavConnector implements ConnectorInterface 27 | { 28 | /** 29 | * Establish an adapter connection. 30 | * 31 | * @param string[] $config 32 | * 33 | * @throws \InvalidArgumentException 34 | * 35 | * @return \League\Flysystem\WebDAV\WebDAVAdapter 36 | */ 37 | public function connect(array $config) 38 | { 39 | $client = self::getClient($config); 40 | $config = self::getConfig($config); 41 | 42 | return self::getAdapter($client, $config); 43 | } 44 | 45 | /** 46 | * Get the webdav client. 47 | * 48 | * @param string[] $config 49 | * 50 | * @return \Sabre\DAV\Client 51 | */ 52 | private static function getClient(array $config) 53 | { 54 | return new Client($config); 55 | } 56 | 57 | /** 58 | * Get the configuration. 59 | * 60 | * @param string[] $config 61 | * 62 | * @return string[] 63 | */ 64 | private static function getConfig(array $config) 65 | { 66 | if (!array_key_exists('prefix', $config)) { 67 | $config['prefix'] = null; 68 | } 69 | 70 | return Arr::only($config, ['prefix']); 71 | } 72 | 73 | /** 74 | * Get the webdav adapter. 75 | * 76 | * @param \Sabre\DAV\Client $client 77 | * @param string[] $config 78 | * 79 | * @return \League\Flysystem\WebDAV\WebDAVAdapter 80 | */ 81 | private static function getAdapter(Client $client, array $config) 82 | { 83 | return new WebDAVAdapter($client, $config['prefix']); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/Adapter/Connector/ZipConnector.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace GrahamCampbell\Flysystem\Adapter\Connector; 15 | 16 | use GrahamCampbell\Manager\ConnectorInterface; 17 | use Illuminate\Support\Arr; 18 | use InvalidArgumentException; 19 | use League\Flysystem\ZipArchive\ZipArchiveAdapter; 20 | 21 | /** 22 | * This is the zip connector class. 23 | * 24 | * @author Graham Campbell 25 | */ 26 | final class ZipConnector implements ConnectorInterface 27 | { 28 | /** 29 | * Establish an adapter connection. 30 | * 31 | * @param string[] $config 32 | * 33 | * @throws \InvalidArgumentException 34 | * 35 | * @return \League\Flysystem\ZipArchive\ZipArchiveAdapter 36 | */ 37 | public function connect(array $config) 38 | { 39 | $config = self::getConfig($config); 40 | 41 | return self::getAdapter($config); 42 | } 43 | 44 | /** 45 | * Get the configuration. 46 | * 47 | * @param string[] $config 48 | * 49 | * @throws \InvalidArgumentException 50 | * 51 | * @return string[] 52 | */ 53 | private static function getConfig(array $config) 54 | { 55 | if (!array_key_exists('path', $config)) { 56 | throw new InvalidArgumentException('The zip connector requires path configuration.'); 57 | } 58 | 59 | return Arr::only($config, ['path']); 60 | } 61 | 62 | /** 63 | * Get the zip adapter. 64 | * 65 | * @param string[] $config 66 | * 67 | * @return \League\Flysystem\ZipArchive\ZipArchiveAdapter 68 | */ 69 | private static function getAdapter(array $config) 70 | { 71 | return new ZipArchiveAdapter($config['path']); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Cache/ConnectionFactory.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace GrahamCampbell\Flysystem\Cache; 15 | 16 | use GrahamCampbell\Flysystem\FlysystemManager; 17 | use Illuminate\Contracts\Cache\Factory; 18 | use InvalidArgumentException; 19 | 20 | /** 21 | * This is the cache connection factory class. 22 | * 23 | * @author Graham Campbell 24 | */ 25 | class ConnectionFactory 26 | { 27 | /** 28 | * The cache factory instance. 29 | * 30 | * @var \Illuminate\Contracts\Cache\Factory|null 31 | */ 32 | protected $cache; 33 | 34 | /** 35 | * Create a new connection factory instance. 36 | * 37 | * @param \Illuminate\Contracts\Cache\Factory|null $cache 38 | * 39 | * @return void 40 | */ 41 | public function __construct(Factory $cache = null) 42 | { 43 | $this->cache = $cache; 44 | } 45 | 46 | /** 47 | * Establish a cache connection. 48 | * 49 | * @param array $config 50 | * @param \GrahamCampbell\Flysystem\FlysystemManager $manager 51 | * 52 | * @throws \InvalidArgumentException 53 | * 54 | * @return \League\Flysystem\Cached\CacheInterface 55 | */ 56 | public function make(array $config, FlysystemManager $manager) 57 | { 58 | return $this->createConnector($config, $manager)->connect($config); 59 | } 60 | 61 | /** 62 | * Create a connector instance based on the configuration. 63 | * 64 | * @param array $config 65 | * @param \GrahamCampbell\Flysystem\FlysystemManager $manager 66 | * 67 | * @throws \InvalidArgumentException 68 | * 69 | * @return \GrahamCampbell\Manager\ConnectorInterface 70 | */ 71 | public function createConnector(array $config, FlysystemManager $manager) 72 | { 73 | if (!isset($config['driver'])) { 74 | throw new InvalidArgumentException('A driver must be specified.'); 75 | } 76 | 77 | switch ($config['driver']) { 78 | case 'illuminate': 79 | return new Connector\IlluminateConnector($this->cache); 80 | case 'adapter': 81 | return new Connector\AdapterConnector($manager); 82 | } 83 | 84 | throw new InvalidArgumentException("Unsupported driver [{$config['driver']}]."); 85 | } 86 | 87 | /** 88 | * Get the cache factory instance. 89 | * 90 | * @return \Illuminate\Contracts\Cache\Factory|null 91 | */ 92 | public function getCache() 93 | { 94 | return $this->cache; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/Cache/Connector/AdapterConnector.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace GrahamCampbell\Flysystem\Cache\Connector; 15 | 16 | use GrahamCampbell\Flysystem\FlysystemManager; 17 | use GrahamCampbell\Manager\ConnectorInterface; 18 | use Illuminate\Support\Arr; 19 | use InvalidArgumentException; 20 | use League\Flysystem\AdapterInterface; 21 | use League\Flysystem\Cached\Storage\Adapter; 22 | 23 | /** 24 | * This is the adapter connector class. 25 | * 26 | * @author Graham Campbell 27 | */ 28 | final class AdapterConnector implements ConnectorInterface 29 | { 30 | /** 31 | * The flysysten manager instance. 32 | * 33 | * @var \GrahamCampbell\Flysystem\FlysystemManager 34 | */ 35 | private $manager; 36 | 37 | /** 38 | * Create a new adapter connector instance. 39 | * 40 | * @param \GrahamCampbell\Flysystem\FlysystemManager $manager 41 | * 42 | * @return void 43 | */ 44 | public function __construct(FlysystemManager $manager) 45 | { 46 | $this->manager = $manager; 47 | } 48 | 49 | /** 50 | * Establish a cache connection. 51 | * 52 | * @param string[] $config 53 | * 54 | * @throws \InvalidArgumentException 55 | * 56 | * @return \League\Flysystem\Cached\Storage\Adapter 57 | */ 58 | public function connect(array $config) 59 | { 60 | $config = self::getConfig($config); 61 | $client = $this->getClient($config); 62 | 63 | return self::getAdapter($client, $config); 64 | } 65 | 66 | /** 67 | * Get the configuration. 68 | * 69 | * @param string[] $config 70 | * 71 | * @throws \InvalidArgumentException 72 | * 73 | * @return string[] 74 | */ 75 | private static function getConfig(array $config) 76 | { 77 | if (!array_key_exists('adapter', $config)) { 78 | throw new InvalidArgumentException('The adapter connector requires adapter configuration.'); 79 | } 80 | 81 | return $config; 82 | } 83 | 84 | /** 85 | * Get the cache client. 86 | * 87 | * @param string[] $config 88 | * 89 | * @return \League\Flysystem\AdapterInterface 90 | */ 91 | private function getClient(array $config) 92 | { 93 | $name = Arr::get($config, 'adapter'); 94 | $config = $this->manager->getConnectionConfig($name); 95 | 96 | return $this->manager->getFactory()->createAdapter($config); 97 | } 98 | 99 | /** 100 | * Get the adapter cache adapter. 101 | * 102 | * @param \League\Flysystem\AdapterInterface $client 103 | * @param string[] $config 104 | * 105 | * @return \League\Flysystem\Cached\Storage\Adapter 106 | */ 107 | private static function getAdapter(AdapterInterface $client, array $config) 108 | { 109 | $file = Arr::get($config, 'file', 'flysystem.json'); 110 | $ttl = Arr::get($config, 'ttl'); 111 | 112 | return new Adapter($client, $file, $ttl); 113 | } 114 | 115 | /** 116 | * Get the flysystem manager instance. 117 | * 118 | * @return \GrahamCampbell\Flysystem\FlysystemManager 119 | */ 120 | public function getManager() 121 | { 122 | return $this->manager; 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /src/Cache/Connector/IlluminateConnector.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace GrahamCampbell\Flysystem\Cache\Connector; 15 | 16 | use GrahamCampbell\Flysystem\Cache\Storage\IlluminateStorage; 17 | use GrahamCampbell\Manager\ConnectorInterface; 18 | use Illuminate\Contracts\Cache\Factory; 19 | use Illuminate\Contracts\Cache\Store; 20 | use Illuminate\Support\Arr; 21 | use InvalidArgumentException; 22 | 23 | /** 24 | * This is the illuminate connector class. 25 | * 26 | * @author Graham Campbell 27 | */ 28 | final class IlluminateConnector implements ConnectorInterface 29 | { 30 | /** 31 | * The cache factory instance. 32 | * 33 | * @var \Illuminate\Contracts\Cache\Factory|null 34 | */ 35 | private $cache; 36 | 37 | /** 38 | * Create a new illuminate connector instance. 39 | * 40 | * @param \Illuminate\Contracts\Cache\Factory|null $cache 41 | * 42 | * @return void 43 | */ 44 | public function __construct(Factory $cache = null) 45 | { 46 | $this->cache = $cache; 47 | } 48 | 49 | /** 50 | * Establish a cache connection. 51 | * 52 | * @param string[] $config 53 | * 54 | * @throws \InvalidArgumentException 55 | * 56 | * @return \GrahamCampbell\Flysystem\Cache\Storage\IlluminateStorage 57 | */ 58 | public function connect(array $config) 59 | { 60 | $store = $this->getStore($config); 61 | 62 | return self::getAdapter($store, $config); 63 | } 64 | 65 | /** 66 | * Get the cache store. 67 | * 68 | * @param string[] $config 69 | * 70 | * @throws \InvalidArgumentException 71 | * 72 | * @return \Illuminate\Contracts\Cache\Store 73 | */ 74 | private function getStore(array $config) 75 | { 76 | if (!$this->cache) { 77 | throw new InvalidArgumentException('Illuminate caching support not available.'); 78 | } 79 | 80 | $name = Arr::get($config, 'connector'); 81 | 82 | return $this->cache->store($name)->getStore(); 83 | } 84 | 85 | /** 86 | * Get the illuminate cache adapter. 87 | * 88 | * @param \Illuminate\Contracts\Cache\Store $store 89 | * @param string[] $config 90 | * 91 | * @return \GrahamCampbell\Flysystem\Cache\Storage\IlluminateStorage 92 | */ 93 | private static function getAdapter(Store $store, array $config) 94 | { 95 | $key = Arr::get($config, 'key', 'flysystem'); 96 | $ttl = Arr::get($config, 'ttl'); 97 | 98 | return new IlluminateStorage($store, $key, $ttl); 99 | } 100 | 101 | /** 102 | * Get the cache instance. 103 | * 104 | * @return \Illuminate\Contracts\Cache\Factory|null 105 | */ 106 | public function getCache() 107 | { 108 | return $this->cache; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/Cache/Storage/IlluminateStorage.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace GrahamCampbell\Flysystem\Cache\Storage; 15 | 16 | use Illuminate\Contracts\Cache\Store; 17 | use League\Flysystem\Cached\Storage\AbstractCache; 18 | 19 | /** 20 | * This is the illuminate storage class. 21 | * 22 | * @author Graham Campbell 23 | */ 24 | class IlluminateStorage extends AbstractCache 25 | { 26 | /** 27 | * The cache store instance. 28 | * 29 | * @var \Illuminate\Contracts\Cache\Store 30 | */ 31 | private $store; 32 | 33 | /** 34 | * The cache key. 35 | * 36 | * @var string 37 | */ 38 | private $key; 39 | 40 | /** 41 | * The cache ttl in seconds. 42 | * 43 | * @var int|null 44 | */ 45 | private $ttl; 46 | 47 | /** 48 | * Create a new illuminate storage instance. 49 | * 50 | * @param \Illuminate\Contracts\Cache\Store $store 51 | * @param string $key 52 | * @param int|null $ttl 53 | */ 54 | public function __construct(Store $store, string $key = 'flysystem', int $ttl = null) 55 | { 56 | $this->store = $store; 57 | $this->key = $key; 58 | $this->ttl = $ttl; 59 | } 60 | 61 | /** 62 | * Load the cache. 63 | * 64 | * @return void 65 | */ 66 | public function load() 67 | { 68 | $contents = $this->store->get($this->key); 69 | 70 | if ($contents !== null) { 71 | $this->setFromStorage($contents); 72 | } 73 | } 74 | 75 | /** 76 | * Store the cache. 77 | * 78 | * @return void 79 | */ 80 | public function save() 81 | { 82 | $contents = $this->getForStorage(); 83 | 84 | if ($this->ttl !== null) { 85 | $this->store->put($this->key, $contents, $this->ttl); 86 | } else { 87 | $this->store->forever($this->key, $contents); 88 | } 89 | } 90 | 91 | /** 92 | * Get the cache store instance. 93 | * 94 | * @return \Illuminate\Contracts\Cache\Store 95 | */ 96 | public function getStore() 97 | { 98 | return $this->store; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/Facades/Flysystem.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace GrahamCampbell\Flysystem\Facades; 15 | 16 | use Illuminate\Support\Facades\Facade; 17 | 18 | /** 19 | * This is the flysystem facade class. 20 | * 21 | * @author Graham Campbell 22 | */ 23 | class Flysystem extends Facade 24 | { 25 | /** 26 | * Get the registered name of the component. 27 | * 28 | * @return string 29 | */ 30 | protected static function getFacadeAccessor() 31 | { 32 | return 'flysystem'; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/FlysystemFactory.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace GrahamCampbell\Flysystem; 15 | 16 | use GrahamCampbell\Flysystem\Adapter\ConnectionFactory as AdapterFactory; 17 | use GrahamCampbell\Flysystem\Cache\ConnectionFactory as CacheFactory; 18 | use Illuminate\Support\Arr; 19 | use League\Flysystem\Cached\CachedAdapter; 20 | use League\Flysystem\EventableFilesystem\EventableFilesystem; 21 | use League\Flysystem\Filesystem; 22 | 23 | /** 24 | * This is the filesystem factory class. 25 | * 26 | * @author Graham Campbell 27 | */ 28 | class FlysystemFactory 29 | { 30 | /** 31 | * The adapter factory instance. 32 | * 33 | * @var \GrahamCampbell\Flysystem\Adapter\ConnectionFactory 34 | */ 35 | protected $adapter; 36 | 37 | /** 38 | * The cache factory instance. 39 | * 40 | * @var \GrahamCampbell\Flysystem\Cache\ConnectionFactory 41 | */ 42 | protected $cache; 43 | 44 | /** 45 | * Create a new filesystem factory instance. 46 | * 47 | * @param \GrahamCampbell\Flysystem\Adapter\ConnectionFactory $adapter 48 | * @param \GrahamCampbell\Flysystem\Cache\ConnectionFactory $cache 49 | * 50 | * @return void 51 | */ 52 | public function __construct(AdapterFactory $adapter, CacheFactory $cache) 53 | { 54 | $this->adapter = $adapter; 55 | $this->cache = $cache; 56 | } 57 | 58 | /** 59 | * Make a new flysystem instance. 60 | * 61 | * @param array $config 62 | * @param \GrahamCampbell\Flysystem\FlysystemManager $manager 63 | * 64 | * @throws \InvalidArgumentException 65 | * 66 | * @return \League\Flysystem\FilesystemInterface 67 | */ 68 | public function make(array $config, FlysystemManager $manager) 69 | { 70 | $adapter = $this->createAdapter($config); 71 | 72 | if (is_array($cache = Arr::get($config, 'cache', false))) { 73 | $adapter = new CachedAdapter($adapter, $this->createCache($cache, $manager)); 74 | } 75 | 76 | $options = $this->getOptions($config); 77 | 78 | if (Arr::get($config, 'eventable', false)) { 79 | return new EventableFilesystem($adapter, $options); 80 | } 81 | 82 | return new Filesystem($adapter, $options); 83 | } 84 | 85 | /** 86 | * Establish an adapter connection. 87 | * 88 | * @param array $config 89 | * 90 | * @return \League\Flysystem\AdapterInterface 91 | */ 92 | public function createAdapter(array $config) 93 | { 94 | $config = Arr::except($config, ['cache', 'eventable', 'visibility']); 95 | 96 | return $this->adapter->make($config); 97 | } 98 | 99 | /** 100 | * Establish a cache connection. 101 | * 102 | * @param array $config 103 | * @param \GrahamCampbell\Flysystem\FlysystemManager $manager 104 | * 105 | * @return \League\Flysystem\Cached\CacheInterface 106 | */ 107 | public function createCache(array $config, FlysystemManager $manager) 108 | { 109 | return $this->cache->make($config, $manager); 110 | } 111 | 112 | /** 113 | * Get the flysystem options. 114 | * 115 | * @param array $config 116 | * 117 | * @return array|null 118 | */ 119 | protected function getOptions(array $config) 120 | { 121 | $options = []; 122 | 123 | if ($visibility = Arr::get($config, 'visibility')) { 124 | $options['visibility'] = $visibility; 125 | } 126 | 127 | if ($pirate = Arr::get($config, 'pirate')) { 128 | $options['disable_asserts'] = $pirate; 129 | } 130 | 131 | return $options; 132 | } 133 | 134 | /** 135 | * Get the adapter factory instance. 136 | * 137 | * @return \GrahamCampbell\Flysystem\Adapter\ConnectionFactory 138 | */ 139 | public function getAdapter() 140 | { 141 | return $this->adapter; 142 | } 143 | 144 | /** 145 | * Get the cache factory instance. 146 | * 147 | * @return \GrahamCampbell\Flysystem\Cache\ConnectionFactory 148 | */ 149 | public function getCache() 150 | { 151 | return $this->cache; 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /src/FlysystemManager.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace GrahamCampbell\Flysystem; 15 | 16 | use GrahamCampbell\Manager\AbstractManager; 17 | use Illuminate\Contracts\Config\Repository; 18 | use Illuminate\Support\Arr; 19 | 20 | /** 21 | * This is the flysystem manager class. 22 | * 23 | * @method \League\Flysystem\FilesystemInterface connection(string|null $name = null) 24 | * @method \League\Flysystem\FilesystemInterface reconnect(string|null $name = null) 25 | * @method void disconnect(string|null $name = null) 26 | * @method array getConnections() 27 | * @method bool has(string $path) 28 | * @method false|string read(string $path) 29 | * @method false|resource readStream(string $path) 30 | * @method array listContents(string $directory = '', bool $recursive = false) 31 | * @method false|array getMetadata(string $path) 32 | * @method false|int getSize(string $path) 33 | * @method false|string getMimetype(string $path) 34 | * @method false|int getTimestamp(string $path) 35 | * @method false|string getVisibility(string $path) 36 | * @method bool write(string $path, string $contents, array $config = []) 37 | * @method bool writeStream(string $path, resource $resource, array $config = []) 38 | * @method bool update(string $path, string $contents, array $config = []) 39 | * @method bool updateStream(string $path, resource $resource, array $config = []) 40 | * @method bool rename(string $path, string $newpath) 41 | * @method bool copy(string $path, string $newpath) 42 | * @method bool delete(string $path) 43 | * @method bool deleteDir(string $dirname) 44 | * @method bool createDir(string $dirname, array $config = []) 45 | * @method bool setVisibility(string $path, string $visibility) 46 | * @method bool put(string $path, string $contents, array $config = []) 47 | * @method bool putStream(string $path, resource $resource, array $config = []) 48 | * @method string readAndDelete(string $path) 49 | * @method \League\Flysystem\Handler get(string $path, \League\Flysystem\Handler $handler = null) 50 | * @method \League\Flysystem\FilesystemInterface addPlugin(\League\Flysystem\PluginInterface $plugin) 51 | * 52 | * @author Graham Campbell 53 | */ 54 | class FlysystemManager extends AbstractManager 55 | { 56 | /** 57 | * The factory instance. 58 | * 59 | * @var \GrahamCampbell\Flysystem\FlysystemFactory 60 | */ 61 | protected $factory; 62 | 63 | /** 64 | * Create a new flysystem manager instance. 65 | * 66 | * @param \Illuminate\Contracts\Config\Repository $config 67 | * @param \GrahamCampbell\Flysystem\FlysystemFactory $factory 68 | * 69 | * @return void 70 | */ 71 | public function __construct(Repository $config, FlysystemFactory $factory) 72 | { 73 | $this->config = $config; 74 | $this->factory = $factory; 75 | } 76 | 77 | /** 78 | * Create the connection instance. 79 | * 80 | * @param array $config 81 | * 82 | * @return \League\Flysystem\FilesystemInterface 83 | */ 84 | protected function createConnection(array $config) 85 | { 86 | return $this->factory->make($config, $this); 87 | } 88 | 89 | /** 90 | * Get the configuration name. 91 | * 92 | * @return string 93 | */ 94 | protected function getConfigName() 95 | { 96 | return 'flysystem'; 97 | } 98 | 99 | /** 100 | * Get the configuration for a connection. 101 | * 102 | * @param string|null $name 103 | * 104 | * @throws \InvalidArgumentException 105 | * 106 | * @return array 107 | */ 108 | public function getConnectionConfig(string $name = null) 109 | { 110 | $name = $name ?: $this->getDefaultConnection(); 111 | 112 | $config = $this->getNamedConfig('connections', 'Adapter', $name); 113 | 114 | if (is_string($cache = Arr::get($config, 'cache'))) { 115 | $config['cache'] = $this->getNamedConfig('cache', 'Cache', $cache); 116 | } 117 | 118 | return $config; 119 | } 120 | 121 | /** 122 | * Get the factory instance. 123 | * 124 | * @return \GrahamCampbell\Flysystem\FlysystemFactory 125 | */ 126 | public function getFactory() 127 | { 128 | return $this->factory; 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /src/FlysystemServiceProvider.php: -------------------------------------------------------------------------------- 1 | 9 | * 10 | * For the full copyright and license information, please view the LICENSE 11 | * file that was distributed with this source code. 12 | */ 13 | 14 | namespace GrahamCampbell\Flysystem; 15 | 16 | use GrahamCampbell\Flysystem\Adapter\ConnectionFactory as AdapterFactory; 17 | use GrahamCampbell\Flysystem\Cache\ConnectionFactory as CacheFactory; 18 | use Illuminate\Contracts\Container\Container; 19 | use Illuminate\Foundation\Application as LaravelApplication; 20 | use Illuminate\Support\ServiceProvider; 21 | use Laravel\Lumen\Application as LumenApplication; 22 | use League\Flysystem\Filesystem; 23 | use League\Flysystem\FilesystemInterface; 24 | 25 | /** 26 | * This is the flysystem service provider class. 27 | * 28 | * @author Graham Campbell 29 | */ 30 | class FlysystemServiceProvider extends ServiceProvider 31 | { 32 | /** 33 | * Boot the service provider. 34 | * 35 | * @return void 36 | */ 37 | public function boot() 38 | { 39 | $this->setupConfig(); 40 | } 41 | 42 | /** 43 | * Setup the config. 44 | * 45 | * @return void 46 | */ 47 | protected function setupConfig() 48 | { 49 | $source = realpath($raw = __DIR__.'/../config/flysystem.php') ?: $raw; 50 | 51 | if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) { 52 | $this->publishes([$source => config_path('flysystem.php')]); 53 | } elseif ($this->app instanceof LumenApplication) { 54 | $this->app->configure('flysystem'); 55 | } 56 | 57 | $this->mergeConfigFrom($source, 'flysystem'); 58 | } 59 | 60 | /** 61 | * Register the service provider. 62 | * 63 | * @return void 64 | */ 65 | public function register() 66 | { 67 | $this->registerAdapterFactory(); 68 | $this->registerCacheFactory(); 69 | $this->registerFlysystemFactory(); 70 | $this->registerManager(); 71 | $this->registerBindings(); 72 | } 73 | 74 | /** 75 | * Register the adapter factory class. 76 | * 77 | * @return void 78 | */ 79 | protected function registerAdapterFactory() 80 | { 81 | $this->app->singleton('flysystem.adapterfactory', function () { 82 | return new AdapterFactory(); 83 | }); 84 | 85 | $this->app->alias('flysystem.adapterfactory', AdapterFactory::class); 86 | } 87 | 88 | /** 89 | * Register the cache factory class. 90 | * 91 | * @return void 92 | */ 93 | protected function registerCacheFactory() 94 | { 95 | $this->app->singleton('flysystem.cachefactory', function (Container $app) { 96 | $cache = $app->bound('cache') ? $app->make('cache') : null; 97 | 98 | return new CacheFactory($cache); 99 | }); 100 | 101 | $this->app->alias('flysystem.cachefactory', CacheFactory::class); 102 | } 103 | 104 | /** 105 | * Register the flysystem factory class. 106 | * 107 | * @return void 108 | */ 109 | protected function registerFlysystemFactory() 110 | { 111 | $this->app->singleton('flysystem.factory', function (Container $app) { 112 | $adapter = $app['flysystem.adapterfactory']; 113 | $cache = $app['flysystem.cachefactory']; 114 | 115 | return new FlysystemFactory($adapter, $cache); 116 | }); 117 | 118 | $this->app->alias('flysystem.factory', FlysystemFactory::class); 119 | } 120 | 121 | /** 122 | * Register the manager class. 123 | * 124 | * @return void 125 | */ 126 | protected function registerManager() 127 | { 128 | $this->app->singleton('flysystem', function (Container $app) { 129 | $config = $app['config']; 130 | $factory = $app['flysystem.factory']; 131 | 132 | return new FlysystemManager($config, $factory); 133 | }); 134 | 135 | $this->app->alias('flysystem', FlysystemManager::class); 136 | } 137 | 138 | /** 139 | * Register the bindings. 140 | * 141 | * @return void 142 | */ 143 | protected function registerBindings() 144 | { 145 | $this->app->bind('flysystem.connection', function (Container $app) { 146 | $manager = $app['flysystem']; 147 | 148 | return $manager->connection(); 149 | }); 150 | 151 | $this->app->alias('flysystem.connection', Filesystem::class); 152 | $this->app->alias('flysystem.connection', FilesystemInterface::class); 153 | } 154 | 155 | /** 156 | * Get the services provided by the provider. 157 | * 158 | * @return string[] 159 | */ 160 | public function provides() 161 | { 162 | return [ 163 | 'flysystem.adapterfactory', 164 | 'flysystem.cachefactory', 165 | 'flysystem.factory', 166 | 'flysystem', 167 | 'flysystem.connection', 168 | ]; 169 | } 170 | } 171 | --------------------------------------------------------------------------------