From ec6e69e240ae6d5ab9ba4992ddd20ed5c2b196b7 Mon Sep 17 00:00:00 2001 From: Jonathan Treffler Date: Tue, 23 Jul 2024 02:10:32 +0200 Subject: [PATCH] use container to allow dependency injection in transport classes --- lib/Service/SubscriptionService.php | 3 +-- lib/Transport/TransportManager.php | 11 +++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/Service/SubscriptionService.php b/lib/Service/SubscriptionService.php index 3dd770c..1d2b95a 100644 --- a/lib/Service/SubscriptionService.php +++ b/lib/Service/SubscriptionService.php @@ -43,14 +43,13 @@ class SubscriptionService { } } - public function create(string $userId, string $collectionName, string $transport, int $expirationTimestamp, $data, ?int $creationTimestamp = null) { + public function create(string $userId, string $collectionName, string $transport, int $expirationTimestamp, ?int $creationTimestamp = null) { $subscription = new Subscription(); $subscription->setUserId($userId); $subscription->setCollectionName($collectionName); $subscription->setTransport($transport); $subscription->setCreationTimestamp($creationTimestamp ?? time()); $subscription->setExpirationTimestamp($expirationTimestamp); - $subscription->setData(json_encode($data)); $subscription = $this->mapper->insert($subscription); return $subscription; diff --git a/lib/Transport/TransportManager.php b/lib/Transport/TransportManager.php index 712322e..bb8e2bf 100644 --- a/lib/Transport/TransportManager.php +++ b/lib/Transport/TransportManager.php @@ -27,18 +27,21 @@ declare(strict_types=1); namespace OCA\DavPush\Transport; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Server; use OCA\DavPush\Events\RegisterTransportsEvent; use OCA\DavPush\PushTransports\WebPushTransport; -use OCA\DavPush\PushTransports\WebhookTransport; +//use OCA\DavPush\PushTransports\WebhookTransport; class TransportManager { private array $transports = []; - public function __construct(IEventDispatcher $dispatcher) { + public function __construct( + IEventDispatcher $dispatcher, + ) { // register integrated transports - $this->registerTransport(new WebPushTransport()); - $this->registerTransport(new WebhookTransport()); + $this->registerTransport(Server::get(WebPushTransport::class)); + //$this->registerTransport(ContainerInterface::get(WebhookTransport::class)); // register transports provided by other apps $event = new RegisterTransportsEvent($this);