This repository has been archived by the owner on Mar 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '3.0-event-overhaul' into 1.1.0
Conflicts: src/Model/Table/FileStorageTable.php tests/TestCase/Model/Table/FileStorageTest.php
- Loading branch information
Showing
71 changed files
with
4,137 additions
and
572 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
/vendor | ||
/plugins | ||
/tmp | ||
/tmp | ||
/composer.lock | ||
/nbproject |
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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
language: php | ||
sudo: false | ||
|
||
php: | ||
- 5.4 | ||
|
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
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
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 |
---|---|---|
@@ -1,10 +1,8 @@ | ||
<?php | ||
use \Cake\Event\EventManager; | ||
use \Burzum\FileStorage\Event\ImageProcessingListener; | ||
use \Burzum\FileStorage\Event\LocalFileStorageListener; | ||
use Burzum\FileStorage\Storage\Listener\LocalListener; | ||
use Cake\Event\EventManager; | ||
|
||
$listener = new ImageProcessingListener(); | ||
EventManager::instance()->on($listener); | ||
|
||
$listener = new LocalFileStorageListener(); | ||
$listener = new LocalListener([ | ||
'imageProcessing' => true | ||
]); | ||
EventManager::instance()->on($listener); |
This file was deleted.
Oops, something went wrong.
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
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,8 @@ | ||
How it works | ||
------------ | ||
|
||
The whole plugin is build with clear [Separation of Concerns](https://en.wikipedia.org/wiki/Separation_of_concerns) in mind: A file is *always* an entry in the `file_storage` table from the app perspective. | ||
|
||
The table is the *reference* to the real place of where the file is stored and keeps some meta information like mime type, filename, file hash (optional) and size as well. You associate the `file_storage` table with your model using the FileStorage or ImageStorage model from the plugin via hasOne, hasMany or HABTM. | ||
|
||
When you upload a file you save it to the FileStorage model through the associations, `Documents.file` for example. The FileStorage model dispatches then file storage specific events. The listeners listening to these events process the file and put it in the configured storage backend using adapters for different backends and build the storage path using a path builder class. |
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 |
---|---|---|
@@ -1,46 +1,55 @@ | ||
Included Event Listeners | ||
======================== | ||
|
||
LocalFileStorageListener | ||
------------------------ | ||
**[For the deprecated event listeners please click here](Legacy-Event-Listeners.md)** | ||
|
||
The file and folder structure it will generate looks like that: | ||
--- | ||
|
||
``` | ||
basePath/files/xx/xx/xx/<uuid>/<uuid>.<extension> | ||
``` | ||
Introduction | ||
------------ | ||
|
||
ImageProcessingListener | ||
----------------------- | ||
The included event listeners will throw a StorageException when something went wrong. It's your duty to handle them. Also you can configure a logger to the `storage` log scope to filter logs by this scope. | ||
|
||
This listener will create versions of images if Configure::read('Media.imageSizes.' . $model); is not empty. If no processing operations for that model were specified it will just save the image. | ||
Each listener has a configured *Path Builder*, check the [path builder documentation] to see what they do and what their purpose is. | ||
|
||
This adapter replaces LocalImageProcessingListener and currently supports the Local and AmazonS3 adapter. | ||
To change the path builder config for a listener check what path builder the listener is using and pass the path builder config to the constructor of the listener: | ||
|
||
```php | ||
$listener = new LocalListener([ | ||
'pathBuilderOptions' => [ | ||
// options go here | ||
] | ||
]); | ||
``` | ||
|
||
The file and folder structure it will generate looks like that: | ||
If you want to implement your own listeners you'll have to extend them from the [AbstractListener](../../src/Storage/Listener/AbstractListener.php) and implement the event callbacks. | ||
|
||
Local Listener | ||
-------------- | ||
|
||
The local listener will store files by default in this kind of path: | ||
|
||
``` | ||
basePath/images/xx/xx/xx/<uuid>/<uuid>.<extension> | ||
<basePath>/<model>/<randomPath>/<uuid>/<uuid>.<extension> | ||
``` | ||
|
||
Versioned images will look like that | ||
Example: | ||
|
||
``` | ||
basePath/images/xx/xx/xx/<uuid>/<uuid>.<hash>.<extension> | ||
/var/www/my_app/files/Documents/05/51/68/38f684612c6f11e5a2cb0800200c9a66/38f684612c6f11e5a2cb0800200c9a66.jpg | ||
``` | ||
|
||
* For the Local adapter basePath is the value configured for this adapter, by default the `TMP` constant. | ||
* For AmazonS3 the basePath will be the bucket and Amazon S3 URL prefix. | ||
|
||
xx stands for a semi random alphanumerical value calculated based on the given file name if the Local adapter was used. | ||
The listener is using by default the `LocalPathBuilder` to generate the path. | ||
|
||
**Some important notes about the path the processor generates:** | ||
The reason for the UUID folder name is simply to ensure it is unique per file and it makes it easy to store versions of the same file in the same folder. | ||
|
||
The path stored to the database is **not** going to be the complete path, it won't add the filename for a reason. | ||
AWS S3 Listener | ||
--------------- | ||
|
||
The filename is generated by the processor on the fly when adding/deleting/modifying images because the versions are build on the fly and not stored to the database. See `ImageProcessingListener::_buildPath()`. | ||
There is no new AWS S3 listener yet, you can either use the old legacy listener or write your own based on the new listeners. A contribution of a new listener is highly welcome! | ||
|
||
LocalImageProcessingListener (deprecated) | ||
----------------------------------------- | ||
Legacy Local File Storage Listener | ||
---------------------------------- | ||
|
||
The LocalImageProcessingListener is **deprecated**, use ImageProcessingListener. | ||
This listener mimics the behavior of the deprecated `LocalFileStorageEventListener`. | ||
|
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
Oops, something went wrong.