Skip to content
This repository has been archived by the owner on Mar 5, 2022. It is now read-only.

Commit

Permalink
Merge 1e2acf3 into 2bda670
Browse files Browse the repository at this point in the history
  • Loading branch information
stripthis committed Apr 3, 2019
2 parents 2bda670 + 1e2acf3 commit b2b3036
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 87 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ php:
- 7.0
- 7.1
- 7.2
- 7.3
- nightly

env:
Expand All @@ -13,6 +14,7 @@ env:

matrix:
allow_failures:
- php: 7.3
- php: nightly

fast_finish: true
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "burzum/cakephp-file-storage",
"type": "cakephp-plugin",
"description": "This plugin is giving you the possibility to store files in virtually and kind of storage backend. This plugin is wrapping the Gaufrette library (https://github.com/KnpLabs/Gaufrette) library in a CakePHP fashion and provides a simple way to use the storage adapters through the StorageManager class.",
"description": "This plugin is giving you the possibility to store files in virtually any kind of storage backend. This plugin is wrapping the Gaufrette library (https://github.com/KnpLabs/Gaufrette) library in a CakePHP fashion and provides a simple way to use the storage adapters through the StorageManager class.",
"keywords": ["file", "filesystem", "media", "abstraction", "upload", "cakephp", "storage"],
"homepage": "http://github.com/burzum/cakephp-file-storage-plugin",
"license": "MIT",
Expand All @@ -23,7 +23,7 @@
"cakephp/cakephp": "^3.6.0",
"cakephp/plugin-installer": "^1.0.0",
"cakephp/migrations": "^2.0.0",
"knplabs/gaufrette": "^0.7.0"
"knplabs/gaufrette": "^0.8.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7.14|^6.0",
Expand Down
104 changes: 78 additions & 26 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 17 additions & 8 deletions config/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
<?php
use Burzum\FileStorage\Storage\Listener\ImageProcessingListener;
use Burzum\FileStorage\Storage\Listener\LocalListener;
use Cake\Core\Configure;
use Cake\Core\Plugin;
use Cake\Event\EventManager;
use Cake\Log\Log;

$listener = new LocalListener();
EventManager::instance()->on($listener);

if (Plugin::loaded('Burzum/Imagine')) {
if (\version_compare(Configure::version(), '3.7.0', 'ge')) {
$imaginePluginIsLoaded = Plugin::isLoaded('Burzum/Imagine');
} else {
$imaginePluginIsLoaded = Plugin::loaded('Burzum/Imagine');
}

if ($imaginePluginIsLoaded) {
$listener = new ImageProcessingListener();
EventManager::instance()->on($listener);
}

Log::setConfig('FileStorage', [
'className' => 'File',
'path' => LOGS,
'levels' => [],
'scopes' => ['fileStorage'],
'file' => 'fileStorage.log',
]);
if (Log::getConfig('FileStorage') === null) {
Log::setConfig('FileStorage', [
'className' => 'File',
'path' => LOGS,
'levels' => [],
'scopes' => ['fileStorage'],
'file' => 'fileStorage.log',
]);
}
12 changes: 12 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Burzum\FileStorage;

use Cake\Core\BasePlugin;

/**
* FileStorage Plugin for CakePHP
*/
class Plugin extends BasePlugin
{
}
9 changes: 5 additions & 4 deletions src/Storage/Listener/BaseListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,11 @@ protected function _processImages(Event $event, $method) {
* @return array
*/
protected function _getVersionData($event) {
if (isset($event->data['versions'])) {
$versions = $event->data['versions'];
} elseif (isset($event->data['operations'])) {
$versions = array_keys($event->data['operations']);
$data = $event->getData();
if (isset($data['versions'])) {
$versions = $data['versions'];
} elseif (isset($data['operations'])) {
$versions = array_keys($data['operations']);
} else {
$versions = [];
}
Expand Down
12 changes: 8 additions & 4 deletions src/Storage/Listener/EventFilterTrait.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
namespace Burzum\FileStorage\Storage\Listener;
use Burzum\FileStorage\Storage\StorageManager;

use Cake\Event\Event;

Expand Down Expand Up @@ -40,34 +41,37 @@ public function filterBySubject($subject) {
}

public function filterByModel(Event $event) {
$data = $event->getData();
if (empty($this->_eventFilters['model'])) {
return true;
}
if (isset($event->data['entity']['adapter']) && in_array($event->data['entity']['adapter'], $this->_eventFilters['model'])) {
if (isset($data['entity']['adapter']) && in_array($data['entity']['adapter'], $this->_eventFilters['model'])) {
return true;
}

return false;
}

public function filterByAdaperConfig(Event $event) {
$data = $event->getData();
if (empty($this->_eventFilters['adapterConfig'])) {
return true;
}
if (isset($event->data['entity']['adapter']) && in_array($event->data['entity']['adapter'], $this->_eventFilters['adapterConfig'])) {
if (isset($data['entity']['adapter']) && in_array($data['entity']['adapter'], $this->_eventFilters['adapterConfig'])) {
return true;
}

return false;
}

public function filterByAdapterClass(Event $event) {
$data = $event->getData();
if (empty($this->_eventFilters['adapterClass'])) {
return true;
}
if (isset($event->data['entity']['adapter'])) {
if (isset($data['entity']['adapter'])) {
foreach ($this->_eventFilters['adapterClass'] as $adapterClass) {
$class = $this->_getAdapterClassFromConfig($event->data['entity']['adapter']);
$class = $this->_getAdapterClassFromConfig($data['entity']['adapter']);
if ($class === $adapterClass) {
return true;
}
Expand Down
Loading

0 comments on commit b2b3036

Please sign in to comment.