summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Wurst <ChristophWurst@users.noreply.github.com>2021-07-05 21:13:53 +0200
committerGitHub <noreply@github.com>2021-07-05 21:13:53 +0200
commit26efbe982e634fb4b85b72d1126e994e12e010be (patch)
treeaa522a3b06feabcfee4f118139b8c4a9f1f6f22a
parent04441d501238f7d2b1514febf9af37068de94335 (diff)
parenta6a31bb419f5adda5f38b5ab5e93791e061ebbdc (diff)
downloadnextcloud-server-26efbe982e634fb4b85b72d1126e994e12e010be.tar.gz
nextcloud-server-26efbe982e634fb4b85b72d1126e994e12e010be.zip
Merge pull request #27794 from nextcloud/fix/clarify-lazy-event-listener-container
Clarify that lazy event listeners are built from the server container
-rw-r--r--lib/private/EventDispatcher/ServiceEventListener.php24
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;
}
}