├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .php_cs.dist ├── .styleci.yml ├── API.md ├── CHANGELOG.md ├── CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── composer.json ├── composer.lock └── src ├── AbstractFsComponent.php ├── AwsS3FsComponent.php ├── AzureFsComponent.php ├── DropboxFsComponent.php ├── FtpFsComponent.php ├── GoogleCloudFsComponent.php ├── GridFSFsComponent.php ├── LocalFsComponent.php ├── MemoryFsComponent.php ├── NullFsComponent.php ├── RackspaceFsComponent.php ├── SftpFsComponent.php ├── WebDAVFsComponent.php ├── ZipArchiveFsComponent.php └── cache └── YiiCache.php /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### What steps will reproduce the problem? 2 | 3 | ### What is the expected result? 4 | 5 | ### What do you get instead? 6 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | | Q | A 2 | | ------------- | --- 3 | | Is bugfix? | yes/no 4 | | New feature? | yes/no 5 | | Breaks BC? | yes/no 6 | | Tests pass? | yes/no 7 | | Fixed issues | comma-separated list of tickets # fixed by the PR, if any 8 | -------------------------------------------------------------------------------- /.php_cs.dist: -------------------------------------------------------------------------------- 1 | exclude([ 5 | '.github', 6 | 'docs', 7 | 'temp', 8 | 'tests', 9 | 'vendor', 10 | ]) 11 | ->in(__DIR__); 12 | 13 | return PhpCsFixer\Config::create() 14 | ->setRules(array( 15 | '@PSR1' => true, 16 | '@PSR2' => true, 17 | 'array_syntax' => array('syntax' => 'short'), 18 | 'combine_consecutive_unsets' => true, 19 | 'no_extra_consecutive_blank_lines' => array( 20 | 'break', 21 | 'continue', 22 | 'extra', 23 | 'return', 24 | 'throw', 25 | 'use', 26 | 'parenthesis_brace_block', 27 | 'square_brace_block', 28 | 'curly_brace_block' 29 | ), 30 | 'no_useless_else' => true, 31 | 'no_useless_return' => true, 32 | 'ordered_class_elements' => true, 33 | 'ordered_imports' => true, 34 | 'phpdoc_add_missing_param_annotation' => true 35 | )) 36 | ->setFinder($finder); 37 | -------------------------------------------------------------------------------- /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: psr2 2 | -------------------------------------------------------------------------------- /API.md: -------------------------------------------------------------------------------- 1 | # API 2 | 3 | The following exposes the use of Flysystem's API methods throughout the component. The examples shown assume that you 4 | have [configured](README.md#usage) your component properly and its name is `fs`. Examples listed: 5 | 6 | - [Writing Files](#writing-files) 7 | - [Updating Files](#updating-files) 8 | - [Writing or Updating Files](#writing-or-updating-files) 9 | - [Reading Files](#reading-files) 10 | - [Checking File Existence](#checking-file-existence) 11 | - [Deleting Files](#deleting-files) 12 | - [Reading and Deleting Files](#reading-and-deleting-files) 13 | - [Renaming Files](#renaming-files) 14 | - [Getting Files Mimetype](#getting-files-mimetype) 15 | - [Getting Files TimeStamp](#getting-files-timestamp) 16 | - [Getting Files Size](#getting-files-size) 17 | - [Creating Directories](#getting-directories) 18 | - [Deleting Directories](#deleting-directories) 19 | - [Managing visibility](#managing-visibility) 20 | - [Listing Contents](#listing-contents) 21 | - [Listing Paths](#listing-paths) 22 | - [Listing with Specific Metadata](#listing-with-specific-metadata) 23 | - [Get File Info with Explicit Metadata](#getting-file-info-with-explicit-metadata) 24 | 25 | ### Writing files 26 | 27 | To write file 28 | 29 | ```php 30 | Yii::$app->fs->write('filename.ext', 'contents'); 31 | ``` 32 | 33 | To write file using stream contents 34 | 35 | ```php 36 | $stream = fopen('/path/to/somefile.ext', 'r+'); 37 | Yii::$app->fs->writeStream('filename.ext', $stream); 38 | ``` 39 | 40 | ### Updating files 41 | 42 | To update file 43 | 44 | ```php 45 | Yii::$app->fs->update('filename.ext', 'contents'); 46 | ``` 47 | 48 | To update file using stream contents 49 | 50 | ```php 51 | $stream = fopen('/path/to/somefile.ext', 'r+'); 52 | Yii::$app->fs->updateStream('filename.ext', $stream); 53 | ``` 54 | 55 | ### Writing or updating files 56 | 57 | To write or update file 58 | 59 | ```php 60 | Yii::$app->fs->put('filename.ext', 'contents'); 61 | ``` 62 | 63 | To write or update file using stream contents 64 | 65 | ```php 66 | $stream = fopen('/path/to/somefile.ext', 'r+'); 67 | Yii::$app->fs->putStream('filename.ext', $stream); 68 | ``` 69 | 70 | ### Reading files 71 | 72 | To read file 73 | 74 | ```php 75 | $contents = Yii::$app->fs->read('filename.ext'); 76 | ``` 77 | 78 | To retrieve a read-stream 79 | 80 | ```php 81 | $stream = Yii::$app->fs->readStream('filename.ext'); 82 | $contents = stream_get_contents($stream); 83 | fclose($stream); 84 | ``` 85 | 86 | ### Checking file existence 87 | 88 | To check if a file exists 89 | 90 | ```php 91 | $exists = Yii::$app->fs->has('filename.ext'); 92 | ``` 93 | 94 | ### Deleting files 95 | 96 | To delete file 97 | 98 | ```php 99 | Yii::$app->fs->delete('filename.ext'); 100 | ``` 101 | 102 | ### Reading and deleting files 103 | 104 | To read and delete file 105 | 106 | ```php 107 | $contents = Yii::$app->fs->readAndDelete('filename.ext'); 108 | ``` 109 | 110 | ### Renaming files 111 | 112 | To rename file 113 | 114 | ```php 115 | Yii::$app->fs->rename('filename.ext', 'newname.ext'); 116 | ``` 117 | 118 | ### Getting files mimetype 119 | 120 | To get file mimetype 121 | 122 | ```php 123 | $mimetype = Yii::$app->fs->getMimetype('filename.ext'); 124 | ``` 125 | 126 | ### Getting files timestamp 127 | 128 | To get file timestamp 129 | 130 | ```php 131 | $timestamp = Yii::$app->fs->getTimestamp('filename.ext'); 132 | ``` 133 | 134 | ### Getting files size 135 | 136 | To get file size 137 | 138 | ```php 139 | $timestamp = Yii::$app->fs->getSize('filename.ext'); 140 | ``` 141 | 142 | ### Creating directories 143 | 144 | To create directory 145 | 146 | ```php 147 | Yii::$app->fs->createDir('path/to/directory'); 148 | ``` 149 | 150 | Directories are also made implicitly when writing to a deeper path 151 | 152 | ```php 153 | Yii::$app->fs->write('path/to/filename.ext'); 154 | ``` 155 | 156 | ### Deleting directories 157 | 158 | To delete directory 159 | 160 | ```php 161 | Yii::$app->fs->deleteDir('path/to/filename.ext'); 162 | ``` 163 | 164 | ### Managing visibility 165 | 166 | Visibility is the abstraction of file permissions across multiple platforms. Visibility can be either public or private. 167 | 168 | ```php 169 | use League\Flysystem\AdapterInterface; 170 | 171 | Yii::$app->fs->write('filename.ext', 'contents', [ 172 | 'visibility' => AdapterInterface::VISIBILITY_PRIVATE 173 | ]); 174 | ``` 175 | 176 | You can also change and check visibility of existing files 177 | 178 | ```php 179 | use League\Flysystem\AdapterInterface; 180 | 181 | if (Yii::$app->fs->getVisibility('filename.ext') === AdapterInterface::VISIBILITY_PRIVATE) { 182 | Yii::$app->fs->setVisibility('filename.ext', AdapterInterface::VISIBILITY_PUBLIC); 183 | } 184 | ``` 185 | 186 | ### Listing contents 187 | 188 | To list contents 189 | 190 | ```php 191 | $contents = Yii::$app->fs->listContents(); 192 | 193 | foreach ($contents as $object) { 194 | echo $object['basename'] 195 | . ' is located at' . $object['path'] 196 | . ' and is a ' . $object['type']; 197 | } 198 | ``` 199 | 200 | By default Flysystem lists the top directory non-recursively. You can supply a directory name and recursive boolean to get more precise results 201 | 202 | ```php 203 | $contents = Yii::$app->fs->listContents('path/to/directory', true); 204 | ``` 205 | 206 | ### Listing paths 207 | 208 | To list paths 209 | 210 | ```php 211 | $paths = Yii::$app->fs->listPaths(); 212 | 213 | foreach ($paths as $path) { 214 | echo $path; 215 | } 216 | ``` 217 | 218 | ### Listing with specific metadata 219 | 220 | To list with ensured presence of specific metadata 221 | 222 | ```php 223 | $listing = Yii::$app->fs->listWith( 224 | ['mimetype', 'size', 'timestamp'], 225 | 'optional/path/to/directory', 226 | true 227 | ); 228 | 229 | foreach ($listing as $object) { 230 | echo $object['path'] . ' has mimetype: ' . $object['mimetype']; 231 | } 232 | ``` 233 | 234 | ### Getting file info with explicit metadata 235 | 236 | To get file info with explicit metadata 237 | 238 | ```php 239 | $info = Yii::$app->fs->getWithMetadata('path/to/filename.ext', ['timestamp', 'mimetype']); 240 | echo $info['mimetype']; 241 | echo $info['timestamp']; 242 | ``` 243 | 244 |
245 |249 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All Notable changes to `yii2-flysystem-component` will be documented in this file 4 | 5 | ## NEXT - YYYY-MM-DD 6 | 7 | ## Changed 8 | - Nothing 9 | 10 | ### Added 11 | - Nothing 12 | 13 | ### Deprecated 14 | - Nothing 15 | 16 | ### Fixed 17 | - Nothing 18 | 19 | ### Removed 20 | - Nothing 21 | 22 | ### Security 23 | - Nothing 24 | -------------------------------------------------------------------------------- /CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to make participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at `hola@2amigos.us`. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at [http://contributor-covenant.org/version/1/4][version] 72 | 73 | [homepage]: http://contributor-covenant.org 74 | [version]: http://contributor-covenant.org/version/1/4/ 75 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | We accept contributions via Pull Requests on [Github](https://github.com/2amigos/yii2-flysystem-component). 6 | 7 | 8 | ## Pull Requests 9 | 10 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). 11 | 12 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 13 | 14 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 15 | 16 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. 17 | 18 | - **Create feature branches** - Don't ask us to pull from your master branch. 19 | 20 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 21 | 22 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting. 23 | 24 | 25 | ## Running Tests 26 | 27 | ``` bash 28 | $ ./vendor/bin/phpunit 29 | ``` 30 | 31 | 32 | **Happy coding**! 33 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The BSD License (BSD) 2 | 3 | Copyright (c) 2013-{year}, 2amigOS! Consulting Group LLC. 4 | 5 | > Redistribution and use in source and binary forms, with or without modification, 6 | > are permitted provided that the following conditions are met: 7 | > 8 | > Redistributions of source code must retain the above copyright notice, this 9 | > list of conditions and the following disclaimer. 10 | > 11 | > Redistributions in binary form must reproduce the above copyright notice, this 12 | > list of conditions and the following disclaimer in the documentation and/or 13 | > other materials provided with the distribution. 14 | > 15 | > Neither the name of 2amigOS! Consulting Group, LLC. nor the names of its 16 | > contributors may be used to endorse or promote products derived from 17 | > this software without specific prior written permission. 18 | > 19 | >THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | >ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | >WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | >DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 23 | >ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | >(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | >LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 | >ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | >(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | >SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Flysystem Component Wrappers for Yii 2 2 | 3 | [](https://packagist.org/packages/2amigos/yii2-flysystem-component) 4 | [](LICENSE.md) 5 | [](https://travis-ci.org/2amigos/yii2-flysystem-component) 6 | [](https://scrutinizer-ci.com/g/2amigos/yii2-flysystem-component) 7 | [](https://packagist.org/packages/2amigos/yii2-flysystem-component) 8 | 9 | 10 | > [Flysystem](http://flysystem.thephpleague.com/) is a file system abstraction which allows you to easily swap out a 11 | local filesystem for a remote one. 12 | 13 | This component library provides components that expose the [Flysystem](http://flysystem.thephpleague.com/) API to your 14 | Yii 2 applications. The following are the currently supported ones: 15 | 16 | - [AwsS3FsComponent](#awss3fscomponent): Interacts with Amazon S3 buckets. 17 | - [AzureFsComponent](#azurefscomponent): Interacts with Microsoft Azure. 18 | - [DropboxFsComponent](#dropboxfscomponent): Interacts with Dropbox. 19 | - [FtpFsComponent](#ftpfscomponent): Interacts with an FTP server. 20 | - [GoogleCloudFsComponent](#googlecloudfscomponent): Interacts with Google Cloud Storage. 21 | - [GridFSFsComponent](#gridfsfscomponent): Interacts with GridFS. 22 | - [LocalFsComponent](#localfscomponent): Interacts with your local server storage. 23 | - [MemoryFsComponent](#memoryfscomponent): Interacts with memory. Useful when you don't want anything persisted. 24 | - [NullFsComponent](#nullfscomponent): Used for testing. 25 | - [RackspaceFsComponent](#rackspacefscomponent): Interacts with Rackspace. 26 | - [SftpFsComponent](#sftpfscomponent): Interacts with an Sftp server. 27 | - [WebDAVFsComponent](#webdavfscomponent): Interacts with WebDAV. 28 | - [ZipArchiveFsComponent](#ziparchivefscomponent): Interacts with zip archives. 29 | 30 | ## Install 31 | 32 | The preferred way to install this extension is through [composer](http://getcomposer.org/download/). 33 | 34 | Either run 35 | 36 | ```bash 37 | $ composer require 2amigos/yii2-flysystem-component 38 | ``` 39 | 40 | or add 41 | 42 | ``` 43 | "2amigos/yii2-flysystem-component": "^1.0" 44 | ``` 45 | 46 | to the `require` section of your `composer.json` file. 47 | 48 | ## Usage 49 | 50 | ### AwsS3FsComponent 51 | 52 | Install dependency 53 | 54 | ```bash 55 | $ composer require league/flysystem-aws-s3-v3 56 | ``` 57 | 58 | Configure on the application `components` section: 59 | 60 | ```php 61 | return [ 62 | //... 63 | 'components' => [ 64 | //... 65 | 'fs' => [ 66 | 'class' => 'dosamigos\flysystem\AwsS3FsComponent', 67 | 'key' => 'your-key', 68 | 'secret' => 'your-secret', 69 | 'bucket' => 'your-bucket', 70 | 'region' => 'your-region', 71 | // 'version' => 'latest', 72 | // 'baseUrl' => 'your-base-url', 73 | // 'prefix' => 'your-prefix', 74 | // 'options' => [], 75 | ], 76 | ], 77 | ]; 78 | ``` 79 | 80 | When you application run, you will be able to use the component as: 81 | 82 | ```php 83 | Yii::$app->fs->read(....); 84 | ``` 85 | 86 | Check [http://flysystem.thephpleague.com/api/](http://flysystem.thephpleague.com/api/) for all the methods available. 87 | Same methods for all adapters. 88 | 89 | ### AzureFsComponent 90 | 91 | First ensure the pear repository is added to your `composer.json` file: 92 | 93 | ``` 94 | "repositories": [ 95 | { 96 | "type": "pear", 97 | "url": "http://pear.php.net" 98 | } 99 | ], 100 | ``` 101 | 102 | Then install the latest version of the plugin 103 | 104 | ```bash 105 | $ composer require league/flysystem-azure 106 | ``` 107 | 108 | Configure on the application `components` section: 109 | 110 | ```php 111 | return [ 112 | //... 113 | 'components' => [ 114 | //... 115 | 'fs' => [ 116 | 'class' => 'dosamigos\flysystem\AzureFsComponent', 117 | 'accountName' => 'your-account-name', 118 | 'accountKey' => 'your-account-key', 119 | 'container' => 'your-container', 120 | ], 121 | ], 122 | ]; 123 | ``` 124 | ### DropboxFsComponent 125 | 126 | Install dependency 127 | 128 | ```bash 129 | $ composer require spatie/flysystem-dropbox 130 | ``` 131 | 132 | Configure on the application `components` section: 133 | 134 | ```php 135 | return [ 136 | //... 137 | 'components' => [ 138 | //... 139 | 'fs' => [ 140 | 'class' => 'dosamigos\flysystem\DropboxFsComponent', 141 | 'token' => 'your-access-token', 142 | // 'prefix' => 'your-prefix', 143 | ], 144 | ], 145 | ]; 146 | ``` 147 | 148 | ### FtpFsComponent 149 | 150 | Configure application `components` as follows 151 | 152 | ```php 153 | return [ 154 | //... 155 | 'components' => [ 156 | //... 157 | 'ftpFs' => [ 158 | 'class' => 'dosamigos\flysystem\FtpFsComponent', 159 | 'host' => 'ftp.example.com', 160 | // 'port' => 21, 161 | // 'username' => 'your-username', 162 | // 'password' => 'your-password', 163 | // 'ssl' => true, 164 | // 'timeout' => 60, 165 | // 'root' => '/path/to/root', 166 | // 'permPrivate' => 0700, 167 | // 'permPublic' => 0744, 168 | // 'passive' => false, 169 | // 'transferMode' => FTP_TEXT, 170 | ], 171 | ], 172 | ]; 173 | ``` 174 | 175 | ### GoogleCloudFsComponent 176 | 177 | Install dependency 178 | 179 | ```bash 180 | $ composer require cedricziel/flysystem-gcs 181 | ``` 182 | 183 | Configure on the application `components` section: 184 | 185 | ```php 186 | return [ 187 | //... 188 | 'components' => [ 189 | //... 190 | 'fs' => [ 191 | 'class' => 'dosamigos\flysystem\GoogleCloudFsComponent', 192 | 'projectId' => 'your-project-id', 193 | 'bucket' => 'your-bucket', 194 | // 'prefix' => 'your-prefix', 195 | ], 196 | ], 197 | ]; 198 | ``` 199 | 200 | ### GridFSFsComponent 201 | 202 | Install dependency 203 | 204 | ```bash 205 | $ composer require league/flysystem-gridfs 206 | ``` 207 | 208 | Configure on the application `components` section: 209 | 210 | ```php 211 | return [ 212 | //... 213 | 'components' => [ 214 | //... 215 | 'fs' => [ 216 | 'class' => 'dosamigos\flysystem\GridFSFsComponent', 217 | 'server' => 'mongodb://localhost:27017', 218 | 'database' => 'your-database', 219 | ], 220 | ], 221 | ]; 222 | ``` 223 | 224 | ### LocalFsComponent 225 | 226 | Configure application `components` as follows 227 | 228 | ```php 229 | return [ 230 | //... 231 | 'components' => [ 232 | //... 233 | 'fs' => [ 234 | 'class' => 'dosamigos\flysystem\LocalFsComponent', 235 | 'path' => '@webroot/your-writable-folder-to-save-files', 236 | ], 237 | ], 238 | ]; 239 | ``` 240 | ### MemoryFsComponent 241 | 242 | Install dependency 243 | 244 | ```bash 245 | $ composer require league/flysystem-memory 246 | ``` 247 | 248 | Configure application `components` as follows 249 | 250 | ```php 251 | return [ 252 | //... 253 | 'components' => [ 254 | //... 255 | 'fs' => [ 256 | 'class' => 'dosamigos\flysystem\MemoryFsComponent', 257 | ], 258 | ], 259 | ]; 260 | ``` 261 | 262 | ### NullFsComponent 263 | 264 | Configure application `components` as follows 265 | 266 | ```php 267 | return [ 268 | //... 269 | 'components' => [ 270 | //... 271 | 'fs' => [ 272 | 'class' => 'dosamigos\flysystem\NullFsComponent', 273 | ], 274 | ], 275 | ]; 276 | ``` 277 | 278 | ### RackspaceFsComponent 279 | 280 | Install dependency 281 | 282 | ```bash 283 | $ composer require league/flysystem-rackspace 284 | ``` 285 | 286 | Configure application `components` as follows 287 | 288 | ```php 289 | return [ 290 | //... 291 | 'components' => [ 292 | //... 293 | 'fs' => [ 294 | 'class' => 'dosamigos\flysystem\RackspaceFsComponent', 295 | 'endpoint' => 'your-endpoint', 296 | 'region' => 'your-region', 297 | 'username' => 'your-username', 298 | 'apiKey' => 'your-api-key', 299 | 'container' => 'your-container', 300 | // 'prefix' => 'your-prefix', 301 | ], 302 | ], 303 | ]; 304 | ``` 305 | 306 | ### SftpFsComponent 307 | 308 | Install dependency 309 | 310 | ```bash 311 | $ composer require league/flysystem-sftp 312 | ``` 313 | 314 | Configure application `components` as follows 315 | 316 | ```php 317 | return [ 318 | //... 319 | 'components' => [ 320 | //... 321 | 'fs' => [ 322 | 'class' => 'dosamigos\flysystem\SftpFsComponent', 323 | 'host' => 'sftp.example.com', 324 | 'username' => 'your-username', 325 | 'password' => 'your-password', 326 | 'privateKey' => '/path/to/or/contents/of/privatekey', 327 | // 'port' => 22, 328 | // 'timeout' => 60, 329 | // 'root' => '/path/to/root', 330 | // 'permPrivate' => 0700, 331 | // 'permPublic' => 0744, 332 | ], 333 | ], 334 | ]; 335 | ``` 336 | 337 | ### WebDAVFsComponent 338 | 339 | Install dependency 340 | 341 | ```bash 342 | $ composer require league/flysystem-webdav 343 | ``` 344 | 345 | Configure application `components` as follows 346 | 347 | ```php 348 | return [ 349 | //... 350 | 'components' => [ 351 | //... 352 | 'fs' => [ 353 | 'class' => 'dosamigos\flysystem\WebDAVFsComponent', 354 | 'baseUri' => 'your-base-uri', 355 | // 'userName' => 'your-user-name', 356 | // 'password' => 'your-password', 357 | // 'proxy' => 'your-proxy', 358 | // 'authType' => \Sabre\DAV\Client::AUTH_BASIC, 359 | // 'encoding' => \Sabre\DAV\Client::ENCODING_IDENTITY, 360 | // 'prefix' => 'your-prefix', 361 | ], 362 | ], 363 | ]; 364 | ``` 365 | 366 | ### ZipArchiveFsComponent 367 | 368 | Install dependency 369 | 370 | ```bash 371 | $ composer require league/flysystem-ziparchive 372 | ``` 373 | 374 | Configure application `components` as follows 375 | 376 | ```php 377 | return [ 378 | //... 379 | 'components' => [ 380 | //... 381 | 'fs' => [ 382 | 'class' => 'dosamigos\flysystem\ZipArchiveFsComponent', 383 | 'path' => '@webroot/files/archive.zip', 384 | // 'prefix' => 'your-prefix', 385 | ], 386 | ], 387 | ]; 388 | ``` 389 | 390 | ## Cool Stuff 391 | 392 | ### Multiple Instances 393 | 394 | You can configure as many components as you need. Simply add them to the `components` section with different names. For 395 | example, I could have S3 and FTP at the same time: 396 | 397 | ```php 398 | return [ 399 | //... 400 | 'components' => [ 401 | //... 402 | 's3Fs' => [ 403 | 'class' => 'dosamigos\flysystem\AwsS3FsComponent', 404 | 'key' => 'your-key', 405 | 'secret' => 'your-secret', 406 | 'bucket' => 'your-bucket', 407 | 'region' => 'your-region', 408 | // 'version' => 'latest', 409 | // 'baseUrl' => 'your-base-url', 410 | // 'prefix' => 'your-prefix', 411 | // 'options' => [], 412 | ], 413 | 'ftpFs => [ 414 | 'class' => 'dosamigos\flysystem\FtpFsComponent', 415 | 'host' => 'ftp.example.com', 416 | ] 417 | ], 418 | ]; 419 | ``` 420 | 421 | Now, I could use them like `Yii::$app->s3Fs` and `Yii::$app->ftpFs` respectively. 422 | 423 | ### Caching 424 | 425 | If you wish to add caching functionality, first we need to include the dependencies on your `composer.json` file: 426 | 427 | ```bash 428 | $ composer require league/flysystem-cached-adapter 429 | ``` 430 | 431 | Next, configure the following attributes on your adapter: 432 | 433 | ```php 434 | return [ 435 | //... 436 | 'components' => [ 437 | //... 438 | 'fs' => [ 439 | //... 440 | 'cache' => 'cacheID', 441 | // 'cacheKey' => 'my-cache-key', 442 | // 'cacheDuration' => 7200, 443 | ], 444 | ], 445 | ]; 446 | ``` 447 | 448 | ### Replicating 449 | 450 | The replication facilitates transitions between adapters, allowing an application to stay functional and migrate its 451 | files from one adapter to another. The adapter takes two other adapters, a source and a replica. Every change is 452 | delegated to both adapters, while all the read operations are passed onto the source only. 453 | 454 | To use the replication feature first install its dependencies: 455 | 456 | ```bash 457 | $ composer require league/flysystem-replicate-adapter 458 | ``` 459 | 460 | Next, configure as follows: 461 | 462 | ```php 463 | return [ 464 | //... 465 | 'components' => [ 466 | //... 467 | 's3Fs' => [ 468 | 'class' => 'dosamigos\flysystem\AwsS3FsComponent', 469 | 'key' => 'your-key', 470 | 'secret' => 'your-secret', 471 | 'bucket' => 'your-bucket', 472 | 'region' => 'your-region', 473 | ], 474 | 'ftpFs => [ 475 | 'class' => 'dosamigos\flysystem\FtpFsComponent', 476 | 'host' => 'ftp.example.com', 477 | 'replica' => 's3Fs' // we have added the ID of the replica component 478 | ] 479 | ], 480 | ]; 481 | ``` 482 | 483 | ## Further Information 484 | 485 | - [API](API.md) 486 | - [Flysystem](http://flysystem.thephpleague.com/) 487 | 488 | ## Testing 489 | 490 | ```bash 491 | $ phpunit 492 | ``` 493 | 494 | ## Using code fixer 495 | 496 | We have added a PHP code fixer to standardize our code. It includes Symfony, PSR2 and some contributors rules. 497 | 498 | ```bash 499 | ./vendor/bin/php-cs-fixer fix ./src --config .php_cs 500 | ``` 501 | 502 | ## Contributing 503 | 504 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details. 505 | 506 | ## Credits 507 | 508 | - [crecoder](https://github.com/creocoder) for the original idea of flysystem wrappers 509 | - [2amigos](https://github.com/2amigos) 510 | - [All Contributors](../../contributors) 511 | 512 | ## License 513 | 514 | The BSD License (BSD). Please see [License File](LICENSE.md) for more information. 515 | 516 |
246 | Custom Software | Web & Mobile Software Development
247 | www.2amigos.us 248 |
517 |521 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "2amigos/yii2-flysystem-component", 3 | "description": "The League Flysystem integration for Yii Framework", 4 | "type": "yii2-extension", 5 | "keywords": [ 6 | "2amigos", 7 | "yii", 8 | "yii2", 9 | "yii 2", 10 | "flysystem", 11 | "filesystem", 12 | "files", 13 | "aws", 14 | "s3", 15 | "azure", 16 | "dropbox", 17 | "ftp", 18 | "gridfs", 19 | "rackspace", 20 | "sftp", 21 | "webdav", 22 | "extension", 23 | "yii2-extension", 24 | "yii2-flysystem-component" 25 | ], 26 | "homepage": "https://github.com/2amigos/yii2-flysystem-component", 27 | "license": "BSD-3-Clause", 28 | "authors": [ 29 | { 30 | "name": "2amigOS! Consulting Group", 31 | "email": "hola@2amigos.us", 32 | "homepage": "http://2amigos.us", 33 | "role": "Developer" 34 | } 35 | ], 36 | "support": { 37 | "issues": "https://github.com/2amigos/yii2-flysystem-component/issues", 38 | "source": "https://github.com/2amigos/yii2-flysystem-component" 39 | }, 40 | "minimum-stability": "dev", 41 | "prefer-stable": true, 42 | "require": { 43 | "yiisoft/yii2": "*", 44 | "league/flysystem": "^1.0" 45 | }, 46 | "require-dev": { 47 | "phpunit/phpunit": "^5.0", 48 | "friendsofphp/php-cs-fixer": "^2.0", 49 | "squizlabs/php_codesniffer": "*", 50 | "phpmd/phpmd": "@stable", 51 | "league/flysystem-aws-s3-v3": "^1.0", 52 | "spatie/flysystem-dropbox": "^1.0", 53 | "league/flysystem-rackspace": "^1.0", 54 | "league/flysystem-gridfs": "^1.0", 55 | "league/flysystem-sftp": "^1.0", 56 | "league/flysystem-webdav": "^1.0", 57 | "league/flysystem-ziparchive": "^1.0", 58 | "league/flysystem-cached-adapter": "^1.0", 59 | "league/flysystem-replicate-adapter": "^1.0", 60 | "league/flysystem-azure": "^1.0", 61 | "league/flysystem-memory": "^1.0", 62 | "cedricziel/flysystem-gcs": "^1.1" 63 | }, 64 | "autoload": { 65 | "psr-4": { 66 | "dosamigos\\flysystem\\": "src" 67 | } 68 | }, 69 | "extra": { 70 | "branch-alias": { 71 | "dev-master": "1.0-dev" 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/AbstractFsComponent.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view 8 | * the LICENSE file that was distributed with this source code. 9 | */ 10 | namespace dosamigos\flysystem; 11 | 12 | use dosamigos\flysystem\cache\YiiCache; 13 | use League\Flysystem\AdapterInterface; 14 | use League\Flysystem\Cached\CachedAdapter; 15 | use League\Flysystem\Filesystem; 16 | use League\Flysystem\Replicate\ReplicateAdapter; 17 | use Yii; 18 | use yii\base\Component; 19 | use yii\base\InvalidConfigException; 20 | use yii\caching\Cache; 21 | 22 | /** 23 | * Filesystem 24 | * 25 | * @method \League\Flysystem\FilesystemInterface addPlugin(\League\Flysystem\PluginInterface $plugin) 26 | * @method void assertAbsent(string $path) 27 | * @method void assertPresent(string $path) 28 | * @method boolean copy(string $path, string $newpath) 29 | * @method boolean createDir(string $dirname, array $config = null) 30 | * @method boolean delete(string $path) 31 | * @method boolean deleteDir(string $dirname) 32 | * @method \League\Flysystem\Handler get(string $path, \League\Flysystem\Handler $handler = null) 33 | * @method \League\Flysystem\AdapterInterface getAdapter() 34 | * @method \League\Flysystem\Config getConfig() 35 | * @method array|false getMetadata(string $path) 36 | * @method string|false getMimetype(string $path) 37 | * @method integer|false getSize(string $path) 38 | * @method integer|false getTimestamp(string $path) 39 | * @method string|false getVisibility(string $path) 40 | * @method array getWithMetadata(string $path, array $metadata) 41 | * @method boolean has(string $path) 42 | * @method array listContents(string $directory = '', boolean $recursive = false) 43 | * @method array listFiles(string $path = '', boolean $recursive = false) 44 | * @method array listPaths(string $path = '', boolean $recursive = false) 45 | * @method array listWith(array $keys = [], $directory = '', $recursive = false) 46 | * @method boolean put(string $path, string $contents, array $config = []) 47 | * @method boolean putStream(string $path, resource $resource, array $config = []) 48 | * @method string|false read(string $path) 49 | * @method string|false readAndDelete(string $path) 50 | * @method resource|false readStream(string $path) 51 | * @method boolean rename(string $path, string $newpath) 52 | * @method boolean setVisibility(string $path, string $visibility) 53 | * @method boolean update(string $path, string $contents, array $config = []) 54 | * @method boolean updateStream(string $path, resource $resource, array $config = []) 55 | * @method boolean write(string $path, string $contents, array $config = []) 56 | * @method boolean writeStream(string $path, resource $resource, array $config = []) 57 | */ 58 | abstract class AbstractFsComponent extends Component 59 | { 60 | /** 61 | * @var \League\Flysystem\Config|array|string|null 62 | */ 63 | public $config; 64 | /** 65 | * @var string|null 66 | */ 67 | public $cache; 68 | /** 69 | * @var string 70 | */ 71 | public $cacheKey = 'flysystem'; 72 | /** 73 | * @var integer 74 | */ 75 | public $cacheDuration = 3600; 76 | /** 77 | * @var string|null 78 | */ 79 | public $replica; 80 | /** 81 | * @var \League\Flysystem\FilesystemInterface 82 | */ 83 | protected $filesystem; 84 | 85 | /** 86 | * @inheritdoc 87 | */ 88 | public function __call($method, $parameters) 89 | { 90 | return call_user_func_array([$this->filesystem, $method], $parameters); 91 | } 92 | 93 | /** 94 | * @inheritdoc 95 | */ 96 | public function init() 97 | { 98 | $adapter = $this->checkReplica($this->checkCached($this->initAdapter())); 99 | 100 | $this->filesystem = new Filesystem($adapter, $this->config); 101 | } 102 | 103 | /** 104 | * @param AdapterInterface $adapter 105 | * 106 | * @return AdapterInterface|CachedAdapter 107 | * @throws InvalidConfigException 108 | */ 109 | protected function checkCached(AdapterInterface $adapter) 110 | { 111 | if (null !== $this->cache) { 112 | /* @var Cache $cache */ 113 | $cache = Yii::$app->get($this->cache); 114 | if (!$cache instanceof Cache) { 115 | throw new InvalidConfigException( 116 | printf('The "cache" property must be an instance of %s subclasses.', Cache::class) 117 | ); 118 | } 119 | $adapter = new CachedAdapter($adapter, new YiiCache($cache, $this->cacheKey, $this->cacheDuration)); 120 | } 121 | 122 | return $adapter; 123 | } 124 | 125 | /** 126 | * @param AdapterInterface $adapter 127 | * 128 | * @return ReplicateAdapter|AdapterInterface 129 | * @throws InvalidConfigException 130 | */ 131 | protected function checkReplica(AdapterInterface $adapter) 132 | { 133 | if ($this->replica !== null) { 134 | /* @var Filesystem $filesystem */ 135 | $filesystem = Yii::$app->get($this->replica); 136 | if (!$filesystem instanceof Filesystem) { 137 | throw new InvalidConfigException( 138 | printf('The "replica" property must be an instance of %s subclasses.', AbstractFsComponent::class) 139 | ); 140 | } 141 | $adapter = new ReplicateAdapter($adapter, $filesystem->getAdapter()); 142 | } 143 | 144 | return $adapter; 145 | } 146 | 147 | /** 148 | * @return AdapterInterface $adapter 149 | */ 150 | abstract protected function initAdapter(); 151 | } 152 | -------------------------------------------------------------------------------- /src/AwsS3FsComponent.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view 8 | * the LICENSE file that was distributed with this source code. 9 | */ 10 | namespace dosamigos\flysystem; 11 | 12 | use Aws\S3\S3Client; 13 | use League\Flysystem\AwsS3v3\AwsS3Adapter; 14 | use yii\base\InvalidConfigException; 15 | 16 | class AwsS3FsComponent extends AbstractFsComponent 17 | { 18 | /** 19 | * @var string 20 | */ 21 | public $key; 22 | /** 23 | * @var string 24 | */ 25 | public $secret; 26 | /** 27 | * @var string 28 | */ 29 | public $region; 30 | /** 31 | * @var string 32 | */ 33 | public $bucket; 34 | /** 35 | * @var string|null 36 | */ 37 | public $prefix; 38 | /** 39 | * @var string 40 | */ 41 | public $version = "latest"; 42 | /** 43 | * @var string for custom endpoints 44 | */ 45 | public $endpoint; 46 | /** 47 | * @var array 48 | */ 49 | public $options = []; 50 | 51 | /** 52 | * @inheritdoc 53 | */ 54 | public function init() 55 | { 56 | if ($this->key === null) { 57 | throw new InvalidConfigException('The "key" property must be set.'); 58 | } 59 | 60 | if ($this->secret === null) { 61 | throw new InvalidConfigException('The "secret" property must be set.'); 62 | } 63 | 64 | if ($this->bucket === null) { 65 | throw new InvalidConfigException('The "bucket" property must be set.'); 66 | } 67 | 68 | if ($this->region === null) { 69 | throw new InvalidConfigException('The "region" property must be set.'); 70 | } 71 | 72 | parent::init(); 73 | } 74 | 75 | /** 76 | * @return AwsS3Adapter 77 | */ 78 | protected function initAdapter() 79 | { 80 | $config = array_filter( 81 | [ 82 | 'credentials' => [ 83 | 'key' => $this->key, 84 | 'secret' => $this->secret 85 | ], 86 | 'region' => $this->region, 87 | 'version' => $this->version, 88 | 'endpoint' => $this->endpoint 89 | ] 90 | ); 91 | 92 | return new AwsS3Adapter( 93 | new S3Client($config), 94 | $this->bucket, 95 | $this->prefix 96 | ); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/AzureFsComponent.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view 8 | * the LICENSE file that was distributed with this source code. 9 | */ 10 | namespace dosamigos\flysystem; 11 | 12 | use League\Flysystem\Azure\AzureAdapter; 13 | use MicrosoftAzure\Storage\Common\ServicesBuilder; 14 | use yii\base\InvalidConfigException; 15 | 16 | class AzureFsComponent extends AbstractFsComponent 17 | { 18 | /** 19 | * @var string 20 | */ 21 | public $accountName; 22 | /** 23 | * @var string 24 | */ 25 | public $accountKey; 26 | /** 27 | * @var string 28 | */ 29 | public $container; 30 | /** 31 | * @inheritdoc 32 | */ 33 | public function init() 34 | { 35 | if ($this->accountName === null) { 36 | throw new InvalidConfigException('The "accountName" property must be set.'); 37 | } 38 | if ($this->accountKey === null) { 39 | throw new InvalidConfigException('The "accountKey" property must be set.'); 40 | } 41 | if ($this->container === null) { 42 | throw new InvalidConfigException('The "container" property must be set.'); 43 | } 44 | parent::init(); 45 | } 46 | /** 47 | * @return AzureAdapter 48 | */ 49 | protected function initAdapter() 50 | { 51 | return new AzureAdapter( 52 | ServicesBuilder::getInstance()->createBlobService(sprintf( 53 | 'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s', 54 | base64_encode($this->accountName), 55 | base64_encode($this->accountKey) 56 | )), 57 | $this->container 58 | ); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/DropboxFsComponent.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view 9 | * the LICENSE file that was distributed with this source code. 10 | */ 11 | 12 | namespace dosamigos\flysystem; 13 | 14 | use Spatie\Dropbox\Client; 15 | use Spatie\FlysystemDropbox\DropboxAdapter; 16 | use yii\base\InvalidConfigException; 17 | 18 | class DropboxFsComponent extends AbstractFsComponent 19 | { 20 | /** 21 | * @var string 22 | */ 23 | public $token; 24 | 25 | /** 26 | * @var string 27 | */ 28 | public $prefix = ''; 29 | 30 | /** 31 | * @inheritdoc 32 | */ 33 | public function init() 34 | { 35 | if ($this->token === null) { 36 | throw new InvalidConfigException('The "token" property must be set.'); 37 | } 38 | 39 | if (!is_string($this->prefix)) { 40 | throw new InvalidConfigException('The "prefix" property must be a string.'); 41 | } 42 | 43 | parent::init(); 44 | } 45 | 46 | /** 47 | * @return DropboxAdapter 48 | */ 49 | protected function initAdapter() 50 | { 51 | return new DropboxAdapter( 52 | new Client($this->token), $this->prefix 53 | ); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/FtpFsComponent.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view 8 | * the LICENSE file that was distributed with this source code. 9 | */ 10 | namespace dosamigos\flysystem; 11 | 12 | use League\Flysystem\Adapter\Ftp; 13 | use Yii; 14 | use yii\base\InvalidConfigException; 15 | 16 | class FtpFsComponent extends AbstractFsComponent 17 | { 18 | /** 19 | * @var string 20 | */ 21 | public $host; 22 | /** 23 | * @var integer 24 | */ 25 | public $port; 26 | /** 27 | * @var string 28 | */ 29 | public $username; 30 | /** 31 | * @var string 32 | */ 33 | public $password; 34 | /** 35 | * @var boolean 36 | */ 37 | public $ssl; 38 | /** 39 | * @var integer 40 | */ 41 | public $timeout; 42 | /** 43 | * @var string 44 | */ 45 | public $root; 46 | /** 47 | * @var integer 48 | */ 49 | public $permPrivate; 50 | /** 51 | * @var integer 52 | */ 53 | public $permPublic; 54 | /** 55 | * @var boolean 56 | */ 57 | public $passive; 58 | /** 59 | * @var integer 60 | */ 61 | public $transferMode; 62 | 63 | /** 64 | * @inheritdoc 65 | */ 66 | public function init() 67 | { 68 | if ($this->host === null) { 69 | throw new InvalidConfigException('The "host" property must be set.'); 70 | } 71 | if ($this->root !== null) { 72 | $this->root = Yii::getAlias($this->root); 73 | } 74 | parent::init(); 75 | } 76 | 77 | /** 78 | * @return Ftp 79 | */ 80 | protected function initAdapter() 81 | { 82 | $config = array_filter( 83 | [ 84 | 'host' => $this->host, 85 | 'port' => $this->port, 86 | 'username' => $this->username, 87 | 'password' => $this->password, 88 | 'ssl' => $this->ssl, 89 | 'timeout' => $this->timeout, 90 | 'root' => $this->root, 91 | 'permPrivate' => $this->permPrivate, 92 | 'permPublic' => $this->permPublic, 93 | 'passive' => $this->passive, 94 | 'transferMode' => $this->transferMode, 95 | ] 96 | ); 97 | 98 | return new Ftp($config); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/GoogleCloudFsComponent.php: -------------------------------------------------------------------------------- 1 | projectId === null) { 29 | throw new InvalidConfigException('The "projectId" property must be set.'); 30 | } 31 | 32 | if ($this->bucket === null) { 33 | throw new InvalidConfigException('The "bucket" property must be set.'); 34 | } 35 | 36 | parent::init(); 37 | } 38 | 39 | /** 40 | * @return GoogleCloudStorageAdapter 41 | */ 42 | protected function initAdapter() 43 | { 44 | $config = array_filter( 45 | [ 46 | 'projectId' => $this->projectId, 47 | 'bucket' => $this->bucket, 48 | 'prefix' => $this->prefix 49 | ] 50 | ); 51 | 52 | return new GoogleCloudStorageAdapter(null, $config); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/GridFSFsComponent.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view 8 | * the LICENSE file that was distributed with this source code. 9 | */ 10 | namespace dosamigos\flysystem; 11 | 12 | use League\Flysystem\GridFS\GridFSAdapter; 13 | use MongoClient; 14 | use yii\base\InvalidConfigException; 15 | 16 | class GridFSFsComponent extends AbstractFsComponent 17 | { 18 | /** 19 | * @var string 20 | */ 21 | public $server; 22 | /** 23 | * @var string 24 | */ 25 | public $database; 26 | 27 | /** 28 | * @inheritdoc 29 | */ 30 | public function init() 31 | { 32 | if ($this->server === null) { 33 | throw new InvalidConfigException('The "server" property must be set.'); 34 | } 35 | 36 | if ($this->database === null) { 37 | throw new InvalidConfigException('The "database" property must be set.'); 38 | } 39 | 40 | parent::init(); 41 | } 42 | 43 | /** 44 | * @return GridFSAdapter 45 | */ 46 | protected function initAdapter() 47 | { 48 | $mongo = new MongoClient($this->server); 49 | 50 | return new GridFSAdapter($mongo->selectDB($this->database)->getGridFS()); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/LocalFsComponent.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view 8 | * the LICENSE file that was distributed with this source code. 9 | */ 10 | 11 | namespace dosamigos\flysystem; 12 | 13 | use League\Flysystem\Adapter\Local; 14 | use Yii; 15 | use yii\base\InvalidConfigException; 16 | 17 | class LocalFsComponent extends AbstractFsComponent 18 | { 19 | /** 20 | * @var string 21 | */ 22 | public $path; 23 | /** 24 | * @var int 25 | */ 26 | public $writeFlags = LOCK_EX; 27 | /** 28 | * @var int 29 | */ 30 | public $linkHandling = Local::DISALLOW_LINKS; 31 | /** 32 | * @var array 33 | */ 34 | public $permissions = []; 35 | 36 | /** 37 | * @inheritdoc 38 | */ 39 | public function init() 40 | { 41 | if ($this->path === null) { 42 | throw new InvalidConfigException('The "path" property must be set.'); 43 | } 44 | $this->path = Yii::getAlias($this->path); 45 | parent::init(); 46 | } 47 | 48 | /** 49 | * @return Local 50 | */ 51 | protected function initAdapter() 52 | { 53 | return new Local($this->path, $this->writeFlags, $this->linkHandling, $this->permissions); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/MemoryFsComponent.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view 8 | * the LICENSE file that was distributed with this source code. 9 | */ 10 | namespace dosamigos\flysystem; 11 | 12 | use League\Flysystem\Memory\MemoryAdapter; 13 | 14 | /** 15 | * This adapter keeps the filesystem completely in memory. This is useful when you need a filesystem, but don’t want it 16 | * persisted. 17 | */ 18 | class MemoryFsComponent extends AbstractFsComponent 19 | { 20 | /** 21 | * @return MemoryAdapter 22 | */ 23 | protected function initAdapter() 24 | { 25 | return new MemoryAdapter(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/NullFsComponent.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view 8 | * the LICENSE file that was distributed with this source code. 9 | */ 10 | namespace dosamigos\flysystem; 11 | 12 | use League\Flysystem\Adapter\NullAdapter; 13 | 14 | /** 15 | * Used mostly for testing. Acts like "/dev/null" 16 | */ 17 | class NullFsComponent extends AbstractFsComponent 18 | { 19 | /** 20 | * @return NullAdapter 21 | */ 22 | protected function initAdapter() 23 | { 24 | return new NullAdapter(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/RackspaceFsComponent.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view 8 | * the LICENSE file that was distributed with this source code. 9 | */ 10 | namespace dosamigos\flysystem; 11 | 12 | use League\Flysystem\Rackspace\RackspaceAdapter; 13 | use OpenCloud\Rackspace; 14 | use yii\base\InvalidConfigException; 15 | 16 | class RackspaceFsComponent extends AbstractFsComponent 17 | { 18 | /** 19 | * @var string 20 | */ 21 | public $endpoint; 22 | /** 23 | * @var string 24 | */ 25 | public $username; 26 | /** 27 | * @var string 28 | */ 29 | public $apiKey; 30 | /** 31 | * @var string 32 | */ 33 | public $region; 34 | /** 35 | * @var string 36 | */ 37 | public $container; 38 | /** 39 | * @var string|null 40 | */ 41 | public $prefix; 42 | 43 | /** 44 | * @inheritdoc 45 | */ 46 | public function init() 47 | { 48 | if ($this->endpoint === null) { 49 | throw new InvalidConfigException('The "endpoint" property must be set.'); 50 | } 51 | if ($this->username === null) { 52 | throw new InvalidConfigException('The "username" property must be set.'); 53 | } 54 | if ($this->apiKey === null) { 55 | throw new InvalidConfigException('The "apiKey" property must be set.'); 56 | } 57 | if ($this->region === null) { 58 | throw new InvalidConfigException('The "region" property must be set.'); 59 | } 60 | if ($this->container === null) { 61 | throw new InvalidConfigException('The "container" property must be set.'); 62 | } 63 | parent::init(); 64 | } 65 | 66 | /** 67 | * @return RackspaceAdapter 68 | */ 69 | protected function initAdapter() 70 | { 71 | $client = new Rackspace($this->endpoint, ['username' => $this->username, 'apiKey' => $this->apiKey]); 72 | $container = $client 73 | ->objectStoreService('cloudFiles', $this->region) 74 | ->getContainer($this->container); 75 | 76 | return new RackspaceAdapter( 77 | $container, 78 | $this->prefix 79 | ); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/SftpFsComponent.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view 8 | * the LICENSE file that was distributed with this source code. 9 | */ 10 | namespace dosamigos\flysystem; 11 | 12 | use League\Flysystem\Sftp\SftpAdapter; 13 | use Yii; 14 | use yii\base\InvalidConfigException; 15 | 16 | class SftpFsComponent extends AbstractFsComponent 17 | { 18 | /** 19 | * @var string 20 | */ 21 | public $host; 22 | /** 23 | * @var string 24 | */ 25 | public $port; 26 | /** 27 | * @var string 28 | */ 29 | public $username; 30 | /** 31 | * @var string 32 | */ 33 | public $password; 34 | /** 35 | * @var integer 36 | */ 37 | public $timeout; 38 | /** 39 | * @var string 40 | */ 41 | public $root; 42 | /** 43 | * @var string 44 | */ 45 | public $privateKey; 46 | /** 47 | * @var integer 48 | */ 49 | public $permPrivate; 50 | /** 51 | * @var integer 52 | */ 53 | public $permPublic; 54 | 55 | /** 56 | * @inheritdoc 57 | */ 58 | public function init() 59 | { 60 | if ($this->host === null) { 61 | throw new InvalidConfigException('The "host" property must be set.'); 62 | } 63 | if ($this->username === null) { 64 | throw new InvalidConfigException('The "username" property must be set.'); 65 | } 66 | if ($this->password === null && $this->privateKey === null) { 67 | throw new InvalidConfigException('Either "password" or "privateKey" property must be set.'); 68 | } 69 | if ($this->root !== null) { 70 | $this->root = Yii::getAlias($this->root); 71 | } 72 | parent::init(); 73 | } 74 | 75 | /** 76 | * @return SftpAdapter 77 | */ 78 | protected function initAdapter() 79 | { 80 | $config = array_filter( 81 | [ 82 | 'host' => $this->host, 83 | 'port' => $this->port, 84 | 'username' => $this->username, 85 | 'password' => $this->password, 86 | 'timeout' => $this->timeout, 87 | 'root' => $this->root, 88 | 'permPrivate' => $this->permPrivate, 89 | 'permPublic' => $this->permPublic, 90 | 'privatekey' => $this->privateKey 91 | ] 92 | ); 93 | 94 | return new SftpAdapter($config); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/WebDAVFsComponent.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view 8 | * the LICENSE file that was distributed with this source code. 9 | */ 10 | namespace dosamigos\flysystem; 11 | 12 | use League\Flysystem\WebDAV\WebDAVAdapter; 13 | use Sabre\DAV\Client; 14 | use yii\base\InvalidConfigException; 15 | 16 | class WebDAVFsComponent extends AbstractFsComponent 17 | { 18 | /** 19 | * @var string 20 | */ 21 | public $baseUri; 22 | /** 23 | * @var string 24 | */ 25 | public $userName; 26 | /** 27 | * @var string 28 | */ 29 | public $password; 30 | /** 31 | * @var string 32 | */ 33 | public $proxy; 34 | /** 35 | * @var integer 36 | */ 37 | public $authType; 38 | /** 39 | * @var integer 40 | */ 41 | public $encoding; 42 | /** 43 | * @var string|null 44 | */ 45 | public $prefix; 46 | 47 | /** 48 | * @inheritdoc 49 | */ 50 | public function init() 51 | { 52 | if ($this->baseUri === null) { 53 | throw new InvalidConfigException('The "baseUri" property must be set.'); 54 | } 55 | 56 | parent::init(); 57 | } 58 | 59 | /** 60 | * @return WebDAVAdapter 61 | */ 62 | protected function initAdapter() 63 | { 64 | $config = array_filter( 65 | [ 66 | 'baseUri' => $this->baseUri, 67 | 'userName' => $this->userName, 68 | 'password' => $this->password, 69 | 'proxy' => $this->proxy, 70 | 'authType' => $this->authType, 71 | 'encoding' => $this->encoding, 72 | ] 73 | ); 74 | 75 | return new WebDAVAdapter(new Client($config), $this->prefix); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/ZipArchiveFsComponent.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view 8 | * the LICENSE file that was distributed with this source code. 9 | */ 10 | namespace dosamigos\flysystem; 11 | 12 | use League\Flysystem\ZipArchive\ZipArchiveAdapter; 13 | use Yii; 14 | use yii\base\InvalidConfigException; 15 | 16 | class ZipArchiveFsComponent extends AbstractFsComponent 17 | { 18 | /** 19 | * @var string 20 | */ 21 | public $path; 22 | /** 23 | * @var string|null 24 | */ 25 | public $prefix; 26 | 27 | /** 28 | * @inheritdoc 29 | */ 30 | public function init() 31 | { 32 | if ($this->path === null) { 33 | throw new InvalidConfigException('The "path" property must be set.'); 34 | } 35 | $this->path = Yii::getAlias($this->path); 36 | parent::init(); 37 | } 38 | 39 | /** 40 | * @return ZipArchiveAdapter 41 | */ 42 | protected function initAdapter() 43 | { 44 | return new ZipArchiveAdapter($this->path, null, $this->prefix); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/cache/YiiCache.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * For the full copyright and license information, please view 8 | * the LICENSE file that was distributed with this source code. 9 | */ 10 | namespace dosamigos\flysystem\cache; 11 | 12 | use League\Flysystem\Cached\Storage\AbstractCache; 13 | use yii\caching\Cache; 14 | 15 | class YiiCache extends AbstractCache 16 | { 17 | /** 18 | * @var Cache 19 | */ 20 | protected $yiiCache; 21 | /** 22 | * @var string 23 | */ 24 | protected $key; 25 | /** 26 | * @var integer 27 | */ 28 | protected $duration; 29 | /** 30 | * @param Cache $cache 31 | * @param string $key 32 | * @param integer $duration 33 | */ 34 | public function __construct(Cache $cache, $key = 'flysystem', $duration = 0) 35 | { 36 | $this->cache = $cache; 37 | $this->key = $key; 38 | $this->duration = $duration; 39 | } 40 | /** 41 | * @inheritdoc 42 | */ 43 | public function load() 44 | { 45 | $contents = $this->cache->get($this->key); 46 | if ($contents !== false) { 47 | $this->setFromStorage($contents); 48 | } 49 | } 50 | /** 51 | * @inheritdoc 52 | */ 53 | public function save() 54 | { 55 | $this->cache->set($this->key, $this->getForStorage(), $this->duration); 56 | } 57 | } 58 | --------------------------------------------------------------------------------
518 | Custom Software | Web & Mobile Software Development
519 | www.2amigos.us 520 |