Skip to content

Commit 7ad0826

Browse files
author
tchapi
committed
chore
1 parent 66f929d commit 7ad0826

4 files changed

Lines changed: 18 additions & 8 deletions

File tree

config/services.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ services:
7777
App\Services\BirthdayService:
7878
arguments:
7979
$birthdayReminderOffset: "%birthday_reminder_offset%"
80-
$calendarBackend: null # will be overridden when instantiated manually
8180

8281
App\Security\ApiKeyAuthenticator:
8382
arguments:

src/Command/SyncBirthdayCalendars.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Entity\User;
66
use App\Services\BirthdayService;
77
use Doctrine\Persistence\ManagerRegistry;
8+
use Sabre\CalDAV\Backend\PDO as CalendarBackend;
89
use Symfony\Component\Console\Command\Command;
910
use Symfony\Component\Console\Helper\ProgressBar;
1011
use Symfony\Component\Console\Input\InputArgument;
@@ -18,6 +19,10 @@ public function __construct(
1819
private BirthdayService $birthdayService,
1920
) {
2021
parent::__construct();
22+
23+
$em = $doctrine->getManager();
24+
$pdo = $em->getConnection()->getNativeConnection();
25+
$this->birthdayService->setBackend(new CalendarBackend($pdo));
2126
}
2227

2328
protected function configure(): void

src/Plugins/BirthdayCalendarPlugin.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Plugins;
44

55
use App\Services\BirthdayService;
6+
use Sabre\CalDAV\Backend\PDO as CalendarBackend;
67
use Sabre\CardDAV;
78
use Sabre\DAV;
89

@@ -18,9 +19,10 @@ class BirthdayCalendarPlugin extends DAV\ServerPlugin
1819
*/
1920
protected $server;
2021

21-
public function __construct(BirthdayService $birthdayService)
22+
public function __construct(BirthdayService $birthdayService, CalendarBackend $calendarBackend)
2223
{
2324
$this->birthdayService = $birthdayService;
25+
$this->birthdayService->setBackend($calendarBackend);
2426
}
2527

2628
public function initialize(DAV\Server $server)

src/Services/BirthdayService.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,20 @@
3131

3232
class BirthdayService
3333
{
34+
/**
35+
* @var CalendarBackend
36+
*/
37+
private $calendarBackend;
38+
3439
public function __construct(
3540
private ManagerRegistry $doctrine,
3641
private string $birthdayReminderOffset,
37-
private ?CalendarBackend $calendarBackend = null,
3842
) {
39-
if (!$calendarBackend) {
40-
$em = $this->doctrine->getManager();
41-
$pdo = $em->getConnection()->getNativeConnection();
42-
$this->calendarBackend = new CalendarBackend($pdo);
43-
}
43+
}
44+
45+
public function setBackend(CalendarBackend $calendarBackend)
46+
{
47+
$this->calendarBackend = $calendarBackend;
4448
}
4549

4650
public function onCardChanged(int $addressBookId, string $cardUri, string $cardData): void

0 commit comments

Comments
 (0)