Skip to content

Commit

Permalink
chore: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasvantuycom committed Jan 25, 2024
0 parents commit 9267de0
Show file tree
Hide file tree
Showing 7 changed files with 696 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
composer.lock
vendor
12 changes: 12 additions & 0 deletions CHANGELOG.md
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.
21 changes: 21 additions & 0 deletions LICENSE.md
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.
75 changes: 75 additions & 0 deletions README.md
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.
62 changes: 62 additions & 0 deletions composer.json
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
}
}
Loading

0 comments on commit 9267de0

Please sign in to comment.