fix: Do not use deprecated IServerContainer in EventDispatcher

This caused a call to logger too soon in init phase

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
pull/53523/head
Côme Chilliet 3 months ago
parent 3dd4ba854f
commit 580328507f
No known key found for this signature in database
GPG Key ID: A3E2F658B28C760A
  1. 4
      lib/private/EventDispatcher/EventDispatcher.php
  2. 27
      lib/private/EventDispatcher/ServiceEventListener.php

@ -14,7 +14,7 @@ use OCP\Broadcast\Events\IBroadcastEvent;
use OCP\EventDispatcher\ABroadcastedEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IServerContainer;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcher as SymfonyDispatcher;
use function get_class;
@ -22,7 +22,7 @@ use function get_class;
class EventDispatcher implements IEventDispatcher {
public function __construct(
private SymfonyDispatcher $dispatcher,
private IServerContainer $container,
private ContainerInterface $container,
private LoggerInterface $logger,
) {
// inject the event dispatcher into the logger

@ -12,7 +12,7 @@ namespace OC\EventDispatcher;
use OCP\AppFramework\QueryException;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IServerContainer;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use function sprintf;
@ -23,24 +23,13 @@ use function sprintf;
* created by the service container
*/
final class ServiceEventListener {
/** @var IServerContainer */
private $container;
private ?IEventListener $service = null;
/** @var string */
private $class;
/** @var LoggerInterface */
private $logger;
/** @var null|IEventListener */
private $service;
public function __construct(IServerContainer $container,
string $class,
LoggerInterface $logger) {
$this->container = $container;
$this->class = $class;
$this->logger = $logger;
public function __construct(
private ContainerInterface $container,
private string $class,
private LoggerInterface $logger,
) {
}
public function __invoke(Event $event) {
@ -49,7 +38,7 @@ final class ServiceEventListener {
// TODO: fetch from the app containers, otherwise any custom services,
// parameters and aliases won't be resolved.
// See https://github.com/nextcloud/server/issues/27793 for details.
$this->service = $this->container->query($this->class);
$this->service = $this->container->get($this->class);
} catch (QueryException $e) {
$this->logger->error(
sprintf(

Loading…
Cancel
Save