mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 02:23:51 +00:00
notification: create
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Notification\Exception;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class NotificationHandlerNotFound extends RuntimeException
|
||||
{
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Notification;
|
||||
|
||||
interface NotificationHandlerInterface
|
||||
{
|
||||
}
|
@@ -13,8 +13,8 @@ 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 Exception;
|
||||
|
||||
final class NotificationHandlerManager
|
||||
{
|
||||
@@ -31,17 +31,7 @@ final class NotificationHandlerManager
|
||||
$this->renderers[] = $activityNotificationRenderer;
|
||||
}
|
||||
|
||||
public function getTemplate(Notification $notification)
|
||||
{
|
||||
return $this->getRenderer($notification)->getTemplate();
|
||||
}
|
||||
|
||||
public function getTemplateData(Notification $notification)
|
||||
{
|
||||
return $this->getRenderer($notification)->getTemplateData($notification);
|
||||
}
|
||||
|
||||
private function getRenderer(Notification $notification)
|
||||
public function getHandler(Notification $notification): NotificationHandlerInterface
|
||||
{
|
||||
foreach ($this->renderers as $renderer) {
|
||||
if ($renderer->supports($notification)) {
|
||||
@@ -49,6 +39,16 @@ final class NotificationHandlerManager
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception('No renderer for ' . $notification);
|
||||
throw new NotificationHandlerNotFound();
|
||||
}
|
||||
|
||||
public function getTemplate(Notification $notification)
|
||||
{
|
||||
return $this->getHandler($notification)->getTemplate();
|
||||
}
|
||||
|
||||
public function getTemplateData(Notification $notification)
|
||||
{
|
||||
return $this->getHandler($notification)->getTemplateData($notification);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user