Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,7 @@
'OC\\Encryption\\Manager' => $baseDir . '/lib/private/Encryption/Manager.php',
'OC\\Encryption\\Update' => $baseDir . '/lib/private/Encryption/Update.php',
'OC\\Encryption\\Util' => $baseDir . '/lib/private/Encryption/Util.php',
'OC\\EventDispatcher\\CoreDispatcher' => $baseDir . '/lib/private/EventDispatcher/CoreDispatcher.php',
'OC\\EventDispatcher\\EventDispatcher' => $baseDir . '/lib/private/EventDispatcher/EventDispatcher.php',
'OC\\EventDispatcher\\ServiceEventListener' => $baseDir . '/lib/private/EventDispatcher/ServiceEventListener.php',
'OC\\EventSource' => $baseDir . '/lib/private/EventSource.php',
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Encryption\\Manager' => __DIR__ . '/../../..' . '/lib/private/Encryption/Manager.php',
'OC\\Encryption\\Update' => __DIR__ . '/../../..' . '/lib/private/Encryption/Update.php',
'OC\\Encryption\\Util' => __DIR__ . '/../../..' . '/lib/private/Encryption/Util.php',
'OC\\EventDispatcher\\CoreDispatcher' => __DIR__ . '/../../..' . '/lib/private/EventDispatcher/CoreDispatcher.php',
'OC\\EventDispatcher\\EventDispatcher' => __DIR__ . '/../../..' . '/lib/private/EventDispatcher/EventDispatcher.php',
'OC\\EventDispatcher\\ServiceEventListener' => __DIR__ . '/../../..' . '/lib/private/EventDispatcher/ServiceEventListener.php',
'OC\\EventSource' => __DIR__ . '/../../..' . '/lib/private/EventSource.php',
Expand Down
56 changes: 56 additions & 0 deletions lib/private/EventDispatcher/CoreDispatcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OC\EventDispatcher;

use Psr\EventDispatcher\StoppableEventInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;

/**
* Symfony Event Dispatcher Override
*/
class CoreDispatcher extends EventDispatcher {

public function __construct(
private LoggerInterface $logger
) {
parent::__construct();
}

/**
* Triggers the listeners of an event.
*
* This method can be overridden to add functionality that is executed
* for each listener.
*
* @param callable[] $listeners The event listeners
* @param string $eventName The name of the event to dispatch
* @param object $event The event object to pass to the event handlers/listeners
*
* @return void
*/
protected function callListeners(iterable $listeners, string $eventName, object $event)
{
$stoppable = $event instanceof StoppableEventInterface;

foreach ($listeners as $listener) {
if ($stoppable && $event->isPropagationStopped()) {
break;
}
// execute the listener and catch any exceptions to prevent an error in a listener from breaking the emitting process
try {
$listener($event, $eventName, $this);
} catch (\Throwable $e) {
$this->logger->error('Error occurred while executing an event listener ' . get_class($event), ['exception' => $e]);
}
}
}

}
7 changes: 3 additions & 4 deletions lib/private/EventDispatcher/EventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IServerContainer;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcher as SymfonyDispatcher;
use function get_class;

class EventDispatcher implements IEventDispatcher {
public function __construct(
private SymfonyDispatcher $dispatcher,
private CoreDispatcher $dispatcher,
private IServerContainer $container,
private LoggerInterface $logger,
) {
Expand Down Expand Up @@ -80,10 +79,10 @@ public function dispatchTyped(Event $event): void {
}

/**
* @return SymfonyDispatcher
* @return CoreDispatcher
* @deprecated 20.0.0
*/
public function getSymfonyDispatcher(): SymfonyDispatcher {
public function getSymfonyDispatcher(): CoreDispatcher {
return $this->dispatcher;
}
}
Loading