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

Commit

Permalink
Fix deprecated warnings for CakePHP 3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
stripthis committed Feb 8, 2019
1 parent 2bda670 commit 4650ea0
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 38 deletions.
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
2 changes: 1 addition & 1 deletion config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
$listener = new LocalListener();
EventManager::instance()->on($listener);

if (Plugin::loaded('Burzum/Imagine')) {
if (Plugin::isLoaded('Burzum/Imagine')) {
$listener = new ImageProcessingListener();
EventManager::instance()->on($listener);
}
Expand Down
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
4 changes: 2 additions & 2 deletions tests/TestCase/View/Helper/ImageHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public function setUp() {
$this->Image = new ImageHelper($this->View);
$this->Image->Html = new HtmlHelper($this->View);

$request = (new Request('contacts/add', false))
$request = (new Request(['url' => 'contacts/add']))
->withAttribute('webroot', '/')
->withAttribute('base', '/');

$this->Image->Html->request = $request;
$this->Image->Html->getView()->setRequest($request);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/View/Helper/LegacyImageHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public function setUp() {
$this->Image = new LegacyImageHelper($this->View);
$this->Image->Html = new HtmlHelper($this->View);

$request = (new Request('contacts/add', false))
$request = (new Request(['url' => 'contacts/add']))
->withAttribute('webroot', '/')
->withAttribute('base', '/');

$this->Image->Html->request = $request;
$this->Image->Html->getView()->setRequest($request);
}

/**
Expand Down

0 comments on commit 4650ea0

Please sign in to comment.