mirror of
https://github.com/nextcloud/server.git
synced 2026-04-27 17:18:48 -04:00
Merge pull request #27794 from nextcloud/fix/clarify-lazy-event-listener-container
Clarify that lazy event listeners are built from the server container
This commit is contained in:
commit
26efbe982e
1 changed files with 18 additions and 6 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue