diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2020-05-11 09:27:17 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2020-05-22 14:56:35 +0200 |
commit | 4dacbbd66dcee2f7d8684ba2929025139735893f (patch) | |
tree | 71730509b81654a0efcad88f3f6cc1a16005ba39 /lib/private/EventDispatcher | |
parent | fd805a03883a21cc5642b57b1cda334d58a01191 (diff) | |
download | nextcloud-server-4dacbbd66dcee2f7d8684ba2929025139735893f.tar.gz nextcloud-server-4dacbbd66dcee2f7d8684ba2929025139735893f.zip |
Log usage of a deprecated event instead of emitting
This way we can track down what is being used and migrate them over. And
slowly kill the old way in a release or 2.
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private/EventDispatcher')
-rw-r--r-- | lib/private/EventDispatcher/GenericEventWrapper.php | 111 | ||||
-rw-r--r-- | lib/private/EventDispatcher/SymfonyAdapter.php | 19 |
2 files changed, 124 insertions, 6 deletions
diff --git a/lib/private/EventDispatcher/GenericEventWrapper.php b/lib/private/EventDispatcher/GenericEventWrapper.php new file mode 100644 index 00000000000..d1d136affc0 --- /dev/null +++ b/lib/private/EventDispatcher/GenericEventWrapper.php @@ -0,0 +1,111 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright (c) 2020, Roeland Jago Douma <roeland@famdouma.nl> + * + * @author Roeland Jago Douma <roeland@famdouma.nl> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OC\EventDispatcher; + +use OCP\ILogger; +use Symfony\Component\EventDispatcher\GenericEvent; + +class GenericEventWrapper extends GenericEvent { + + /** @var ILogger */ + private $logger; + + /** @var GenericEvent */ + private $event; + + /** @var string */ + private $eventName; + + public function __construct(ILogger $logger, string $eventName, ?GenericEvent $event) { + $this->logger = $logger; + $this->event = $event; + $this->eventName = $eventName; + } + + private function log() { + $this->logger->info( + 'Deprecated event type for {name}: {class} is used', + [ 'name' => $this->eventName, 'class' => is_object($this->event) ? get_class($this->event) : 'null' ] + ); + } + + public function isPropagationStopped() { + $this->log(); + return $this->event->isPropagationStopped(); + } + + public function stopPropagation() { + $this->log(); + $this->event->stopPropagation(); + } + + public function getSubject() { + $this->log(); + return $this->event->getSubject(); + } + + public function getArgument($key) { + $this->log(); + return $this->event->getArgument($key); + } + + public function setArgument($key, $value) { + $this->log(); + return $this->event->setArgument($key, $value); + } + + public function getArguments() { + return $this->event->getArguments(); + } + + public function setArguments(array $args = []) { + return $this->event->setArguments($args); + } + + public function hasArgument($key) { + return $this->event->hasArgument($key); + } + + public function offsetGet($key) { + return $this->event->offsetGet($key); + } + + public function offsetSet($key, $value) { + return $this->event->offsetSet($key, $value); + } + + public function offsetUnset($key) { + return $this->event->offsetUnset($key); + } + + public function offsetExists($key) { + return $this->event->offsetExists($key); + } + + public function getIterator() { + return$this->event->getIterator(); + } +} diff --git a/lib/private/EventDispatcher/SymfonyAdapter.php b/lib/private/EventDispatcher/SymfonyAdapter.php index b1a39a79131..10e953be843 100644 --- a/lib/private/EventDispatcher/SymfonyAdapter.php +++ b/lib/private/EventDispatcher/SymfonyAdapter.php @@ -28,6 +28,7 @@ declare(strict_types=1); namespace OC\EventDispatcher; +use Symfony\Component\EventDispatcher\GenericEvent; use function is_callable; use OCP\EventDispatcher\Event; use OCP\ILogger; @@ -62,12 +63,18 @@ class SymfonyAdapter implements EventDispatcherInterface { if ($event instanceof Event) { $this->eventDispatcher->dispatch($eventName, $event); } else { - // Legacy event - $this->logger->info( - 'Deprecated event type for {name}: {class}', - [ 'name' => $eventName, 'class' => is_object($event) ? get_class($event) : 'null' ] - ); - $this->eventDispatcher->getSymfonyDispatcher()->dispatch($eventName, $event); + if ($event instanceof GenericEvent) { + $newEvent = new GenericEventWrapper($this->logger, $eventName, $event); + } else { + $newEvent = $event; + + // Legacy event + $this->logger->info( + 'Deprecated event type for {name}: {class}', + ['name' => $eventName, 'class' => is_object($event) ? get_class($event) : 'null'] + ); + } + $this->eventDispatcher->getSymfonyDispatcher()->dispatch($eventName, $newEvent); } } |