diff options
-rw-r--r-- | lib/private/EventDispatcher/ServiceEventListener.php | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/lib/private/EventDispatcher/ServiceEventListener.php b/lib/private/EventDispatcher/ServiceEventListener.php index 045d7391ac1..a7e15f1df1b 100644 --- a/lib/private/EventDispatcher/ServiceEventListener.php +++ b/lib/private/EventDispatcher/ServiceEventListener.php @@ -24,13 +24,15 @@ declare(strict_types=1); * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ + namespace OC\EventDispatcher; use OCP\AppFramework\QueryException; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; -use OCP\IContainer; +use OCP\IServerContainer; use Psr\Log\LoggerInterface; +use function sprintf; /** * Lazy service event listener @@ -40,7 +42,7 @@ use Psr\Log\LoggerInterface; */ final class ServiceEventListener { - /** @var IContainer */ + /** @var IServerContainer */ private $container; /** @var string */ @@ -52,7 +54,7 @@ final class ServiceEventListener { /** @var null|IEventListener */ private $service; - public function __construct(IContainer $container, + public function __construct(IServerContainer $container, string $class, LoggerInterface $logger) { $this->container = $container; @@ -63,11 +65,21 @@ final class ServiceEventListener { public function __invoke(Event $event) { if ($this->service === null) { try { + // 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); } catch (QueryException $e) { - $this->logger->error("Could not load event listener service " . $this->class, [ - 'exception' => $e, - ]); + $this->logger->error( + sprintf( + 'Could not load event listener service %s: %s. Make sure the class is auto-loadable by the Nextcloud server container', + $this->class, + $e->getMessage() + ), + [ + 'exception' => $e, + ] + ); return; } } |