notificaiton: load interface automatically

This commit is contained in:
2021-12-25 22:53:35 +01:00
parent 5cebcfddb7
commit f6f0786d38
4 changed files with 22 additions and 15 deletions

View File

@@ -11,29 +11,30 @@ declare(strict_types=1);
namespace Chill\MainBundle\Notification;
use Chill\ActivityBundle\Notification\ActivityNotificationRenderer;
use Chill\MainBundle\Entity\Notification;
use Chill\MainBundle\Notification\Exception\NotificationHandlerNotFound;
use Chill\PersonBundle\Notification\AccompanyingPeriodNotificationRenderer;
use Doctrine\ORM\EntityManagerInterface;
final class NotificationHandlerManager
{
private array $renderers;
private EntityManagerInterface $em;
private iterable $handlers;
public function __construct(
AccompanyingPeriodNotificationRenderer $accompanyingPeriodNotificationRenderer,
ActivityNotificationRenderer $activityNotificationRenderer
iterable $handlers,
EntityManagerInterface $em
) {
// TODO configure automatically
// TODO CREER UNE INTERFACE POUR ETRE SUR QUE LES RENDERERS SONT OK
$this->renderers[] = $accompanyingPeriodNotificationRenderer;
$this->renderers[] = $activityNotificationRenderer;
$this->handlers = $handlers;
$this->em = $em;
}
/**
* @throw NotificationHandlerNotFound if handler is not found
*/
public function getHandler(Notification $notification): NotificationHandlerInterface
{
foreach ($this->renderers as $renderer) {
foreach ($this->handlers as $renderer) {
if ($renderer->supports($notification)) {
return $renderer;
}
@@ -42,12 +43,12 @@ final class NotificationHandlerManager
throw new NotificationHandlerNotFound();
}
public function getTemplate(Notification $notification)
public function getTemplate(Notification $notification): string
{
return $this->getHandler($notification)->getTemplate();
}
public function getTemplateData(Notification $notification)
public function getTemplateData(Notification $notification): array
{
return $this->getHandler($notification)->getTemplateData($notification);
}