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

Commit

Permalink
Merge cd81cf1 into 2bda670
Browse files Browse the repository at this point in the history
  • Loading branch information
stripthis authored Apr 3, 2019
2 parents 2bda670 + cd81cf1 commit 0c619f6
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 75 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
2 changes: 1 addition & 1 deletion 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 Down
81 changes: 66 additions & 15 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
52 changes: 28 additions & 24 deletions src/Storage/Listener/LegacyImageProcessingListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,16 @@ protected function _removeVersions(Event $Event) {
}
}

/**
* afterDelete
*
* @param Event $Event
* @return boolean|null
*/
/**
* afterDelete
*
* @param Event $Event
* @return boolean|null
* @throws \Burzum\FileStorage\Storage\StorageException
*/
public function afterDelete(Event $Event) {
if ($this->_checkEvent($Event)) {
$record = $Event->data['record'];
$record = $Event->getData('record');
$string = $this->_buildPath($record, true, null);
if ($this->adapterClass === 'AmazonS3' || $this->adapterClass === 'AwsS3') {
$string = str_replace('\\', '/', $string);
Expand All @@ -252,7 +253,7 @@ public function afterDelete(Event $Event) {
}
$operations = Configure::read('FileStorage.imageSizes.' . $record['model']);
if (!empty($operations)) {
$Event->data['operations'] = $operations;
$Event->setData('operations', $operations);
$this->_removeVersions($Event);
}
$Event->stopPropagation();
Expand All @@ -262,12 +263,13 @@ public function afterDelete(Event $Event) {
}
}

/**
* beforeSave
*
* @param Event $Event
* @return void
*/
/**
* beforeSave
*
* @param Event $Event
* @return void
* @throws \Burzum\FileStorage\Storage\StorageException
*/
public function beforeSave(Event $Event) {
if ($this->_checkEvent($Event)) {
$data = $Event->getData();
Expand All @@ -280,12 +282,13 @@ public function beforeSave(Event $Event) {
}
}

/**
* afterSave
*
* @param Event $Event
* @return void
*/
/**
* afterSave
*
* @param Event $Event
* @return void
* @throws \Burzum\FileStorage\Storage\StorageException
*/
public function afterSave(Event $Event) {
if ($this->_checkEvent($Event)) {
$table = $Event->getSubject();
Expand Down Expand Up @@ -398,14 +401,15 @@ protected function _buildAmazonS3Path(Event $Event) {
}

$http = 'http';
if (!empty($Event->data['options']['ssl']) && $Event->data['options']['ssl'] === true) {
$data = $Event->getData();
if (!empty($data['options']['ssl']) && $data['options']['ssl'] === true) {
$http = 'https';
}

$path = str_replace('\\', '/', $path);
$bucketPrefix = !empty($Event->data['options']['bucketPrefix']) && $Event->data['options']['bucketPrefix'] === true;

$Event->data['path'] = $Event->result = $this->_buildCloudFrontDistributionUrl($http, $path, $bucket, $bucketPrefix, $cfDist);
$bucketPrefix = !empty($data['options']['bucketPrefix']) && $data['options']['bucketPrefix'] === true;
$Event->result = $this->_buildCloudFrontDistributionUrl($http, $path, $bucket, $bucketPrefix, $cfDist);
$Event->setData('path', $Event->result);
$Event->stopPropagation();
}

Expand Down
Loading

0 comments on commit 0c619f6

Please sign in to comment.