-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9267de0
Showing
7 changed files
with
696 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
composer.lock | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## Unreleased | ||
|
||
## 1.0.0 - 2024-01-26 | ||
|
||
- Initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Thomas Vantuycom | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Flysystem adapter for Cloudinary | ||
|
||
This is a [Flysystem](https://flysystem.thephpleague.com/docs/) adapter for [Cloudinary](https://cloudinary.com/). Although not the first of its kind, this package strives to be the ultimate and dependable Flysystem adapter for Cloudinary. | ||
|
||
## Installation | ||
|
||
```bash | ||
composer require thomasvantuycom/flysystem-cloudinary | ||
``` | ||
|
||
## Usage | ||
|
||
Configure a Cloudinary client by supplying the cloud name, API key, and API secret accessible in the [Cloudinary console](https://console.cloudinary.com/pm/getting-started/). Then, pass the client to the adapter and initialize a new filesystem using the adapter. | ||
|
||
```php | ||
use Cloudinary\Cloudinary; | ||
use League\Flysystem\Filesystem; | ||
use ThomasVantuycom\FlysystemCloudinary\CloudinaryAdapter; | ||
|
||
$client = new Cloudinary([ | ||
'cloud' => [ | ||
'cloud_name' => 'CLOUD_NAME', | ||
'api_key' => 'API_KEY', | ||
'api_secret' => 'API_SECRET', | ||
], | ||
'url' => [ | ||
'forceVersion' => false, | ||
], | ||
]); | ||
|
||
$adapter = new CloudinaryAdapter($client); | ||
|
||
$filesystem = new Filesystem($adapater); | ||
``` | ||
|
||
### Storing assets in a subfolder | ||
|
||
By default, the root folder of the filesystem corresponds to Cloudinary's root folder. If you prefer to store your assets in a subfolder on Cloudinary, you can provide a second argument to the Cloudinary adapter. | ||
|
||
```php | ||
$adapter = new CloudinaryAdapter($client, 'path/to/folder'); | ||
``` | ||
|
||
### Customizing mime type detection | ||
|
||
By default, the adapter employs `League\MimeTypeDetection\FinfoMimeTypeDetector` for mime type detection and setting the resource type accordingly. If you wish to modify this behavior, you can supply a third argument to the Cloudinary adapter, implementing `League\MimeTypeDetection\MimeTypeDetector`. | ||
|
||
```php | ||
$adapter = new CloudinaryAdapter($client, '', $mimeTypeDetector); | ||
``` | ||
|
||
### Enabling dynamic folders mode. | ||
|
||
By default, the adapter operates under the assumption that your Cloudinary cloud uses fixed folder mode. If you wish to support [dynamic folders](https://cloudinary.com/documentation/dynamic_folders), set the fourth argument to `true`. | ||
|
||
```php | ||
$adapter = new CloudinaryAdapter($client, '', null, true); | ||
``` | ||
|
||
## Limitations | ||
|
||
- The adapter heavily relies on the Cloudinary admin API to implement most of Flysystem's operations. Because the admin API has rate limits, you may run into timeouts. The Cloudinary API poses challenges in how it distinguishes between images, videos, and other assets, making the task of ensuring seamless operation across all file types quite intricate and expensive in API calls. It's important to highlight that deleting folders can be particularly resource-intensive. | ||
- The adapter is compatible with Cloudinary's dynamic folders mode. However, it operates on the assumption that the public IDs of your assets do not include a path. | ||
|
||
## Testing | ||
|
||
```bash | ||
composer test | ||
``` | ||
|
||
The tests exhibit some flakiness due to delays in Cloudinary's upload and delete responses. | ||
|
||
## License | ||
|
||
The MIT License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
"name": "thomasvantuycom/flysystem-cloudinary", | ||
"description": "Cloudinary filesystem adapter for Flysystem.", | ||
"type": "library", | ||
"keywords": [ | ||
"cloudinary", | ||
"flysystem", | ||
"filesystem", | ||
"storage", | ||
"file", | ||
"files" | ||
], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Thomas Vantuycom", | ||
"email": "[email protected]", | ||
"homepage": "https://thomasvantuycom.com", | ||
"role": "Developer" | ||
} | ||
], | ||
"support": { | ||
"email": "[email protected]", | ||
"issues": "https://github.com/thomasvantuycom/flysystem-cloudinary/issues", | ||
"source": "https://github.com/thomasvantuycom/flysystem-cloudinary", | ||
"docs": "https://github.com/thomasvantuycom/flysystem-cloudinary", | ||
"rss": "https://github.com/thomasvantuycom/flysystem-cloudinary/releases.atom" | ||
}, | ||
"funding": [ | ||
{ | ||
"type": "github", | ||
"url": "https://github.com/sponsors/thomasvantuycom" | ||
} | ||
], | ||
"require": { | ||
"php": "^8.0.2", | ||
"league/flysystem": "^3.23", | ||
"cloudinary/cloudinary_php": "^2.12" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^10.5", | ||
"phpstan/phpstan": "^1.10", | ||
"league/flysystem-adapter-test-utilities": "^3.21" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"ThomasVantuycom\\FlysystemCloudinary\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"ThomasVantuycom\\FlysystemCloudinary\\Tests\\": "tests/" | ||
} | ||
}, | ||
"scripts": { | ||
"test": "phpunit tests", | ||
"phpstan": "phpstan analyse --level=4 src" | ||
}, | ||
"config": { | ||
"sort-packages": true | ||
} | ||
} |
Oops, something went wrong.