Skip to content

Commit 11d6e49

Browse files
committed
#16 add docs
1 parent c2a626e commit 11d6e49

File tree

2 files changed

+65
-3
lines changed

2 files changed

+65
-3
lines changed

README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
This is a [Flysystem adapter](https://github.com/thephpleague/flysystem) for [Cloudinary API](http://cloudinary.com/documentation/php_integration).
77

8-
# Installation
8+
## Installation
99

1010
```bash
1111
composer require enl/flysystem-cloudinary '~1.0'
@@ -21,7 +21,7 @@ Or just add the following string to `require` part of your `composer.json`:
2121
}
2222
```
2323

24-
# Bootstrap
24+
## Bootstrap
2525

2626
``` php
2727
<?php
@@ -44,10 +44,14 @@ $adapter = new CloudinaryAdapter($client);
4444
$filesystem = new Filesystem($adapter, ['disable_asserts' => true]);
4545
```
4646

47-
# Cloudinary features
47+
## Cloudinary features
4848

4949
Please, keep in mind three possible pain-in-asses of Cloudinary:
5050

5151
* It adds automatically file extension to its public_id. In terms of Flysystem, cloudinary's public_id is considered as filename. But if you set public_id as 'test.jpg' Cloudinary will save the file as 'test.jpg.jpg'. In order to work it around, you can use [PathConverterInterface](doc/path_converter.md).
5252
* It does not support folders creation through the API
5353
* If you want to save your files using folder you should set public_ids like 'test/test.jpg' and allow automated folders creation in your account settings in Cloudinary dashboard.
54+
55+
#### Good news!
56+
57+
The library supports [Cloudinary Transformations](doc/transformations.md)!

doc/transformations.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
Cloudinary Transformations Support
2+
==================================
3+
4+
In order to fully utilize Cloudinary features, you definitely will want to use their [Image Transformations API](https://cloudinary.com/documentation/image_transformations).
5+
6+
That is possible, but requires a bit hackish approach to work with Flysystem.
7+
8+
Flysystem Plugins
9+
-----------------
10+
11+
As you might know Flysystem supports plugins system: all you need is implement `League\Flysystem\PluginInterface`, register new plugin and then call it as normal method:
12+
13+
```php
14+
$flysystem->addPlugin(new Acme\WhateverPlugin());
15+
$flysystem->whatever();
16+
```
17+
18+
Disclaimer
19+
----------
20+
21+
When you use plugins from this package, you MUST consider that this vendor-locks you to Cloudinary and Flysystem becomes _leaky abstraction_ layer. That means you won't change adapter that easy. You will need to implement these plugins (or get rid of their use) for you new underlying service, which will be tricky if not impossible.
22+
23+
Plugins
24+
-------
25+
26+
There are two plugins: one of them returns `url` of transformed image, another one returns content of this transformed image:
27+
28+
``` php
29+
<?php
30+
use Enl\Flysystem\Cloudinary\ApiFacade as CloudinaryClient;
31+
use Enl\Flysystem\Cloudinary\CloudinaryAdapter;
32+
use Enl\Flysystem\Cloudinary\Plugin\ReadTransformation;
33+
use Enl\Flysystem\Cloudinary\Plugin\GetUrl;
34+
use League\Flysystem\Filesystem;
35+
36+
include __DIR__ . '/vendor/autoload.php';
37+
38+
$client = new CloudinaryClient([
39+
'cloud_name' => 'your-cloudname-here',
40+
'api_key' => 'api-key',
41+
'api_secret' => 'You-know-what-to-do',
42+
'overwrite' => true, // set this to true if you want to overwrite existing files using $filesystem->write();
43+
]);
44+
45+
$adapter = new CloudinaryAdapter($client);
46+
// This option disables assert that file is absent before calling `write`.
47+
// It is necessary if you want to overwrite files on `write` as Cloudinary does it by default.
48+
$filesystem = new Filesystem($adapter, ['disable_asserts' => true]);
49+
$filesystem->addPlugin(new ReadTransformation($client));
50+
$filesystem->addPlugin(new GetUrl($client));
51+
```
52+
53+
And then all you need is just call:
54+
55+
```php
56+
$url = $filesystem->getUrl('test.jpg', ['width' => 600, 'height' => 400, 'format' => 'png']);
57+
$content = $filesystem->readTransformation('test.jpg', ['width' => 600, 'height' => 400, 'format' => 'png']);
58+
```

0 commit comments

Comments
 (0)