diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2021-10-14 11:12:55 +0200 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2021-10-14 16:06:51 +0200 |
commit | c75a12c1540b63909e2546733a83a36646c82bd3 (patch) | |
tree | a91e100b9e872b343a06bab167438eac70fc822c /lib/private/Calendar | |
parent | ed533bd128807ae4e41efb590d59afe05c26668c (diff) | |
download | nextcloud-server-c75a12c1540b63909e2546733a83a36646c82bd3.tar.gz nextcloud-server-c75a12c1540b63909e2546733a83a36646c82bd3.zip |
Build instances of the calendar providers before using them
What we get from the registration context are only the class names. We
still have to load the classes before we can use them.
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/private/Calendar')
-rw-r--r-- | lib/private/Calendar/Manager.php | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/lib/private/Calendar/Manager.php b/lib/private/Calendar/Manager.php index 30ee60e4943..3fa4b55d1ea 100644 --- a/lib/private/Calendar/Manager.php +++ b/lib/private/Calendar/Manager.php @@ -31,6 +31,11 @@ use OCP\Calendar\ICalendar; use OCP\Calendar\ICalendarProvider; use OCP\Calendar\ICalendarQuery; use OCP\Calendar\IManager; +use Psr\Container\ContainerInterface; +use Psr\Log\LoggerInterface; +use Throwable; +use function array_map; +use function array_merge; class Manager implements IManager { @@ -47,8 +52,18 @@ class Manager implements IManager { /** @var Coordinator */ private $coordinator; - public function __construct(Coordinator $coordinator) { + /** @var ContainerInterface */ + private $container; + + /** @var LoggerInterface */ + private $logger; + + public function __construct(Coordinator $coordinator, + ContainerInterface $container, + LoggerInterface $logger) { $this->coordinator = $coordinator; + $this->container = $container; + $this->logger = $logger; } /** @@ -159,9 +174,21 @@ class Manager implements IManager { } /** @var CalendarQuery $query */ - $calendars = array_merge(...array_map(static function (ICalendarProvider $p) use ($query) { - return $p->getCalendars($query->getPrincipalUri(), $query->getCalendarUris()); - }, $context->getCalendarProviders())); + $calendars = array_merge( + ...array_map(function ($registration) use ($query) { + try { + /** @var ICalendarProvider $provider */ + $provider = $this->container->get($registration->getService()); + } catch (Throwable $e) { + $this->logger->error('Could not load calendar provider ' . $registration->getService() . ': ' . $e->getMessage(), [ + 'exception' => $e, + ]); + return []; + } + + return $provider->getCalendars($query->getPrincipalUri(), $query->getCalendarUris()); + }, $context->getCalendarProviders()) + ); $results = []; /** @var ICalendar $calendar */ |