chore!: Remove legacy SymfonyAdapter

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2023-07-27 23:22:33 +02:00
parent c5dcf3c849
commit b9e2f494a1
No known key found for this signature in database
GPG Key ID: C400AAF20C1BB6FC
7 changed files with 0 additions and 553 deletions

View File

@ -1228,9 +1228,7 @@ return array(
'OC\\Encryption\\Update' => $baseDir . '/lib/private/Encryption/Update.php',
'OC\\Encryption\\Util' => $baseDir . '/lib/private/Encryption/Util.php',
'OC\\EventDispatcher\\EventDispatcher' => $baseDir . '/lib/private/EventDispatcher/EventDispatcher.php',
'OC\\EventDispatcher\\GenericEventWrapper' => $baseDir . '/lib/private/EventDispatcher/GenericEventWrapper.php',
'OC\\EventDispatcher\\ServiceEventListener' => $baseDir . '/lib/private/EventDispatcher/ServiceEventListener.php',
'OC\\EventDispatcher\\SymfonyAdapter' => $baseDir . '/lib/private/EventDispatcher/SymfonyAdapter.php',
'OC\\EventSourceFactory' => $baseDir . '/lib/private/EventSourceFactory.php',
'OC\\Federation\\CloudFederationFactory' => $baseDir . '/lib/private/Federation/CloudFederationFactory.php',
'OC\\Federation\\CloudFederationNotification' => $baseDir . '/lib/private/Federation/CloudFederationNotification.php',

View File

@ -1261,9 +1261,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Encryption\\Update' => __DIR__ . '/../../..' . '/lib/private/Encryption/Update.php',
'OC\\Encryption\\Util' => __DIR__ . '/../../..' . '/lib/private/Encryption/Util.php',
'OC\\EventDispatcher\\EventDispatcher' => __DIR__ . '/../../..' . '/lib/private/EventDispatcher/EventDispatcher.php',
'OC\\EventDispatcher\\GenericEventWrapper' => __DIR__ . '/../../..' . '/lib/private/EventDispatcher/GenericEventWrapper.php',
'OC\\EventDispatcher\\ServiceEventListener' => __DIR__ . '/../../..' . '/lib/private/EventDispatcher/ServiceEventListener.php',
'OC\\EventDispatcher\\SymfonyAdapter' => __DIR__ . '/../../..' . '/lib/private/EventDispatcher/SymfonyAdapter.php',
'OC\\EventSourceFactory' => __DIR__ . '/../../..' . '/lib/private/EventSourceFactory.php',
'OC\\Federation\\CloudFederationFactory' => __DIR__ . '/../../..' . '/lib/private/Federation/CloudFederationFactory.php',
'OC\\Federation\\CloudFederationNotification' => __DIR__ . '/../../..' . '/lib/private/Federation/CloudFederationNotification.php',

View File

@ -1,124 +0,0 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020, Roeland Jago Douma <roeland@famdouma.nl>
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @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 Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
class GenericEventWrapper extends GenericEvent {
private LoggerInterface $logger;
/** @var GenericEvent */
private $event;
/** @var string */
private $eventName;
/** @var bool */
private $deprecationNoticeLogged = false;
public function __construct(LoggerInterface $logger, string $eventName, ?GenericEvent $event) {
parent::__construct($eventName);
$this->logger = $logger;
$this->event = $event;
$this->eventName = $eventName;
}
private function log() {
if ($this->deprecationNoticeLogged) {
return;
}
$class = ($this->event !== null && is_object($this->event)) ? get_class($this->event) : 'null';
$this->logger->debug(
'Deprecated event type for {name}: {class} is used',
[ 'name' => $this->eventName, 'class' => $class]
);
$this->deprecationNoticeLogged = true;
}
public function isPropagationStopped(): bool {
$this->log();
return $this->event->isPropagationStopped();
}
public function stopPropagation(): void {
$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);
}
/**
* @return mixed
*/
#[\ReturnTypeWillChange]
public function offsetGet($key) {
return $this->event->offsetGet($key);
}
public function offsetSet($key, $value): void {
$this->event->offsetSet($key, $value);
}
public function offsetUnset($key): void {
$this->event->offsetUnset($key);
}
public function offsetExists($key): bool {
return $this->event->offsetExists($key);
}
public function getIterator() {
return$this->event->getIterator();
}
}

View File

@ -1,208 +0,0 @@
<?php
declare(strict_types=1);
/**
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @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\EventDispatcher\Event;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use function is_callable;
use function is_object;
use function is_string;
/**
* @deprecated 20.0.0 use \OCP\EventDispatcher\IEventDispatcher
*/
class SymfonyAdapter implements EventDispatcherInterface {
/** @var EventDispatcher */
private $eventDispatcher;
private LoggerInterface $logger;
/**
* @deprecated 20.0.0
*/
public function __construct(EventDispatcher $eventDispatcher, LoggerInterface $logger) {
$this->eventDispatcher = $eventDispatcher;
$this->logger = $logger;
}
private static function detectEventAndName($a, $b) {
if (is_object($a) && (is_string($b) || $b === null)) {
// a is the event, the other one is the optional name
return [$a, $b];
}
if (is_object($b) && (is_string($a) || $a === null)) {
// b is the event, the other one is the optional name
return [$b, $a];
}
if (is_string($a) && $b === null) {
// a is a payload-less event
return [null, $a];
}
if (is_string($b) && $a === null) {
// b is a payload-less event
return [null, $b];
}
// Anything else we can't detect
return [$a, $b];
}
/**
* Dispatches an event to all registered listeners.
*
* @param string $eventName The name of the event to dispatch. The name of
* the event is the name of the method that is
* invoked on listeners.
* @param Event|null $event The event to pass to the event handlers/listeners
* If not supplied, an empty Event instance is created
*
* @return object the emitted event
* @deprecated 20.0.0
*/
public function dispatch($eventName, $event = null): object {
[$event, $eventName] = self::detectEventAndName($event, $eventName);
// type hinting is not possible, due to usage of GenericEvent
if ($event instanceof Event && $eventName === null) {
$this->eventDispatcher->dispatchTyped($event);
return $event;
}
if ($event instanceof Event) {
$this->eventDispatcher->dispatch($eventName, $event);
return $event;
}
if ($event instanceof GenericEvent && get_class($event) === GenericEvent::class) {
$newEvent = new GenericEventWrapper($this->logger, $eventName, $event);
} else {
$newEvent = $event;
// Legacy event
$this->logger->debug(
'Deprecated event type for {name}: {class}',
['name' => $eventName, 'class' => is_object($event) ? get_class($event) : 'null']
);
}
// Event with no payload (object) need special handling
if ($newEvent === null) {
$newEvent = new Event();
}
// Flip the argument order for Symfony to prevent a trigger_error
return $this->eventDispatcher->getSymfonyDispatcher()->dispatch($newEvent, $eventName);
}
/**
* Adds an event listener that listens on the specified events.
*
* @param string $eventName The event to listen on
* @param callable $listener The listener
* @param int $priority The higher this value, the earlier an event
* listener will be triggered in the chain (defaults to 0)
* @deprecated 20.0.0
*/
public function addListener($eventName, $listener, $priority = 0) {
if (is_callable($listener)) {
$this->eventDispatcher->addListener($eventName, $listener, $priority);
} else {
// Legacy listener
$this->eventDispatcher->getSymfonyDispatcher()->addListener($eventName, $listener, $priority);
}
}
/**
* Adds an event subscriber.
*
* The subscriber is asked for all the events it is
* interested in and added as a listener for these events.
* @deprecated 20.0.0
*/
public function addSubscriber(EventSubscriberInterface $subscriber) {
$this->eventDispatcher->getSymfonyDispatcher()->addSubscriber($subscriber);
}
/**
* Removes an event listener from the specified events.
*
* @param string $eventName The event to remove a listener from
* @param callable $listener The listener to remove
* @deprecated 20.0.0
*/
public function removeListener($eventName, $listener) {
$this->eventDispatcher->getSymfonyDispatcher()->removeListener($eventName, $listener);
}
/**
* @deprecated 20.0.0
*/
public function removeSubscriber(EventSubscriberInterface $subscriber) {
$this->eventDispatcher->getSymfonyDispatcher()->removeSubscriber($subscriber);
}
/**
* Gets the listeners of a specific event or all listeners sorted by descending priority.
*
* @param string|null $eventName The name of the event
*
* @return array The event listeners for the specified event, or all event listeners by event name
* @deprecated 20.0.0
*/
public function getListeners($eventName = null) {
return $this->eventDispatcher->getSymfonyDispatcher()->getListeners($eventName);
}
/**
* Gets the listener priority for a specific event.
*
* Returns null if the event or the listener does not exist.
*
* @param string $eventName The name of the event
* @param callable $listener The listener
*
* @return int|null The event listener priority
* @deprecated 20.0.0
*/
public function getListenerPriority($eventName, $listener) {
return $this->eventDispatcher->getSymfonyDispatcher()->getListenerPriority($eventName, $listener);
}
/**
* Checks whether an event has any registered listeners.
*
* @param string|null $eventName The name of the event
*
* @return bool true if the specified event has any listeners, false otherwise
* @deprecated 20.0.0
*/
public function hasListeners($eventName = null) {
return $this->eventDispatcher->getSymfonyDispatcher()->hasListeners($eventName);
}
}

View File

@ -82,7 +82,6 @@ use OC\DB\Connection;
use OC\DB\ConnectionAdapter;
use OC\Diagnostics\EventLogger;
use OC\Diagnostics\QueryLogger;
use OC\EventDispatcher\SymfonyAdapter;
use OC\Federation\CloudFederationFactory;
use OC\Federation\CloudFederationProviderManager;
use OC\Federation\CloudIdManager;
@ -257,7 +256,6 @@ use OCP\User\Events\UserLoggedOutEvent;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use OCA\Files_External\Service\UserStoragesService;
use OCA\Files_External\Service\UserGlobalStoragesService;
use OCA\Files_External\Service\GlobalStoragesService;
@ -1181,9 +1179,6 @@ class Server extends ServerContainer implements IServerContainer {
);
});
$this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class);
/** @deprecated 19.0.0 */
$this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class);
$this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class);
$this->registerService('CryptoWrapper', function (ContainerInterface $c) {
// FIXME: Instantiated here due to cyclic dependency
@ -2044,17 +2039,6 @@ class Server extends ServerContainer implements IServerContainer {
return $this->get(CapabilitiesManager::class);
}
/**
* Get the EventDispatcher
*
* @return EventDispatcherInterface
* @since 8.2.0
* @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher
*/
public function getEventDispatcher() {
return $this->get(\OC\EventDispatcher\SymfonyAdapter::class);
}
/**
* Get the Notification Manager
*

View File

@ -46,7 +46,6 @@ use OCP\Federation\ICloudFederationProviderManager;
use OCP\Log\ILogFactory;
use OCP\Security\IContentSecurityPolicyManager;
use Psr\Container\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* This is a tagging interface for the server container
@ -516,15 +515,6 @@ interface IServerContainer extends ContainerInterface, IContainer {
*/
public function getMimeTypeLoader();
/**
* Get the EventDispatcher
*
* @return EventDispatcherInterface
* @deprecated 20.0.0 use \OCP\EventDispatcher\IEventDispatcher
* @since 8.2.0
*/
public function getEventDispatcher();
/**
* Get the Notification Manager
*

View File

@ -1,191 +0,0 @@
<?php
declare(strict_types=1);
/*
* @copyright 2021 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @author 2021 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @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 lib\EventDispatcher;
use OC\EventDispatcher\EventDispatcher;
use OC\EventDispatcher\GenericEventWrapper;
use OC\EventDispatcher\SymfonyAdapter;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\GenericEvent;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\Event as SymfonyEvent;
use Symfony\Component\EventDispatcher\EventDispatcher as SymfonyDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent as SymfonyGenericEvent;
use Test\TestCase;
class SymfonyAdapterTest extends TestCase {
/** @var EventDispatcher|MockObject */
private $eventDispatcher;
/** @var LoggerInterface|MockObject */
private $logger;
/** @var EventDispatcherInterface */
private $adapter;
protected function setUp(): void {
parent::setUp();
$this->eventDispatcher = $this->createMock(EventDispatcher::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->adapter = new SymfonyAdapter(
$this->eventDispatcher,
$this->logger
);
}
public function testDispatchTypedEvent(): void {
$event = new Event();
$eventName = 'symfony';
$this->eventDispatcher->expects(self::once())
->method('dispatch')
->with(
$eventName,
$event
)
->willReturnArgument(0);
$this->adapter->dispatch($eventName, $event);
}
public function testDispatchSymfonyGenericEvent(): void {
$eventName = 'symfony';
$event = new SymfonyGenericEvent();
$wrapped = new GenericEventWrapper(
$this->logger,
$eventName,
$event
);
$symfonyDispatcher = $this->createMock(SymfonyDispatcher::class);
$this->eventDispatcher->expects(self::once())
->method('getSymfonyDispatcher')
->willReturn($symfonyDispatcher);
$symfonyDispatcher->expects(self::once())
->method('dispatch')
->with(
self::equalTo($wrapped),
$eventName
)
->willReturnArgument(0);
$result = $this->adapter->dispatch($eventName, $event);
self::assertEquals($result, $wrapped);
}
public function testDispatchOldSymfonyEventWithFlippedArgumentOrder(): void {
$event = new SymfonyEvent();
$eventName = 'symfony';
$symfonyDispatcher = $this->createMock(SymfonyDispatcher::class);
$this->eventDispatcher->expects(self::once())
->method('getSymfonyDispatcher')
->willReturn($symfonyDispatcher);
$symfonyDispatcher->expects(self::once())
->method('dispatch')
->with(
$event,
$eventName
)
->willReturnArgument(0);
$result = $this->adapter->dispatch($event, $eventName);
self::assertSame($result, $event);
}
public function testDispatchOldSymfonyEvent(): void {
$event = new SymfonyEvent();
$eventName = 'symfony';
$symfonyDispatcher = $this->createMock(SymfonyDispatcher::class);
$this->eventDispatcher->expects(self::once())
->method('getSymfonyDispatcher')
->willReturn($symfonyDispatcher);
$symfonyDispatcher->expects(self::once())
->method('dispatch')
->with(
$event,
$eventName
)
->willReturnArgument(0);
$result = $this->adapter->dispatch($eventName, $event);
self::assertSame($result, $event);
}
public function testDispatchCustomGenericEventWithFlippedArgumentOrder(): void {
$event = new GenericEvent();
$eventName = 'symfony';
$this->eventDispatcher->expects(self::once())
->method('dispatch')
->with(
$eventName,
$event
)
->willReturnArgument(0);
$result = $this->adapter->dispatch($event, $eventName);
self::assertSame($result, $event);
}
public function testDispatchCustomGenericEvent(): void {
$event = new GenericEvent();
$eventName = 'symfony';
$this->eventDispatcher->expects(self::once())
->method('dispatch')
->with(
$eventName,
$event
);
$result = $this->adapter->dispatch($eventName, $event);
self::assertSame($result, $event);
}
public function testDispatchEventWithoutPayload(): void {
$eventName = 'symfony';
$symfonyDispatcher = $this->createMock(SymfonyDispatcher::class);
$this->eventDispatcher->expects(self::once())
->method('getSymfonyDispatcher')
->willReturn($symfonyDispatcher);
$symfonyDispatcher->expects(self::once())
->method('dispatch')
->with(
$this->anything(),
$eventName
)
->willReturnArgument(0);
$result = $this->adapter->dispatch($eventName);
self::assertNotNull($result);
}
}