From 4650ea080eb7e59138cdc2da7f7531071b114781 Mon Sep 17 00:00:00 2001 From: Remy Bertot Date: Fri, 8 Feb 2019 18:59:43 +0100 Subject: [PATCH] Fix deprecated warnings for CakePHP 3.7 --- composer.json | 2 +- config/bootstrap.php | 2 +- src/Storage/Listener/BaseListener.php | 9 ++-- src/Storage/Listener/EventFilterTrait.php | 12 +++-- .../LegacyImageProcessingListener.php | 52 ++++++++++--------- .../TestCase/View/Helper/ImageHelperTest.php | 4 +- .../View/Helper/LegacyImageHelperTest.php | 4 +- 7 files changed, 47 insertions(+), 38 deletions(-) diff --git a/composer.json b/composer.json index 2a8d454c..d319bb48 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/config/bootstrap.php b/config/bootstrap.php index 071d552a..9677b9e3 100644 --- a/config/bootstrap.php +++ b/config/bootstrap.php @@ -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); } diff --git a/src/Storage/Listener/BaseListener.php b/src/Storage/Listener/BaseListener.php index 209b0f64..4738f8a6 100644 --- a/src/Storage/Listener/BaseListener.php +++ b/src/Storage/Listener/BaseListener.php @@ -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 = []; } diff --git a/src/Storage/Listener/EventFilterTrait.php b/src/Storage/Listener/EventFilterTrait.php index b4cfba05..8c4b2af0 100644 --- a/src/Storage/Listener/EventFilterTrait.php +++ b/src/Storage/Listener/EventFilterTrait.php @@ -1,5 +1,6 @@ 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; } @@ -51,10 +53,11 @@ public function filterByModel(Event $event) { } 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; } @@ -62,12 +65,13 @@ public function filterByAdaperConfig(Event $event) { } 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; } diff --git a/src/Storage/Listener/LegacyImageProcessingListener.php b/src/Storage/Listener/LegacyImageProcessingListener.php index 2a887d5f..ace28366 100644 --- a/src/Storage/Listener/LegacyImageProcessingListener.php +++ b/src/Storage/Listener/LegacyImageProcessingListener.php @@ -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); @@ -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(); @@ -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(); @@ -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(); @@ -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(); } diff --git a/tests/TestCase/View/Helper/ImageHelperTest.php b/tests/TestCase/View/Helper/ImageHelperTest.php index 3a0ca9c3..c0abaeb3 100644 --- a/tests/TestCase/View/Helper/ImageHelperTest.php +++ b/tests/TestCase/View/Helper/ImageHelperTest.php @@ -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); } /** diff --git a/tests/TestCase/View/Helper/LegacyImageHelperTest.php b/tests/TestCase/View/Helper/LegacyImageHelperTest.php index c926faef..8c9b5f77 100644 --- a/tests/TestCase/View/Helper/LegacyImageHelperTest.php +++ b/tests/TestCase/View/Helper/LegacyImageHelperTest.php @@ -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); } /**