Display notification using services (draft)

This commit is contained in:
Marc Ducobu
2021-06-18 18:05:02 +02:00
parent bdf691a063
commit 282db51f06
15 changed files with 208 additions and 1 deletions

View File

@@ -0,0 +1,44 @@
<?php
namespace Chill\MainBundle\Notification;
use Chill\MainBundle\Entity\Notification;
use Chill\PersonBundle\Notification\AccompanyingPeriodNotificationRenderer;
use Chill\ActivityBundle\Notification\ActivityNotificationRenderer;
final class NotificationRenderer
{
private array $renderers;
public function __construct(
AccompanyingPeriodNotificationRenderer $accompanyingPeriodNotificationRenderer,
ActivityNotificationRenderer $activityNotificationRenderer)
{
// TODO configure automatically
// TODO CREER UNE INTERFACE POUR ETRE SUR QUE LES RENDERERS SONT OK
$this->renderers[] = $accompanyingPeriodNotificationRenderer;
$this->renderers[] = $activityNotificationRenderer;
}
private function getRenderer(Notification $notification)
{
foreach ($this->renderers as $renderer) {
if($renderer->supports($notification)) {
return $renderer;
}
}
throw new \Exception('No renderer for '. $notification);
}
public function getTemplate(Notification $notification)
{
return $this->getRenderer($notification)->getTemplate();
}
public function getTemplateData(Notification $notification)
{
return $this->getRenderer($notification)->getTemplateData($notification);
}
}