mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 02:23:51 +00:00
notificaiton: load interface automatically
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user