From 7c45946c90281394909bcf80fc31b2d708fa1430 Mon Sep 17 00:00:00 2001 From: Khoubza Younes Date: Sun, 6 Dec 2020 04:03:14 +0100 Subject: [PATCH] fix event dispatcher and call the storage service --- Producer/ToastrProducer.php | 14 -------- Toastr.php | 29 +++++++++++++++++ ToastrBuilder.php | 24 ++++++++++++++ ToastrFactory.php | 32 +++++++++++++++++++ .../ToastrRenderer.php => ToastrRenderer.php | 26 +++++++++------ 5 files changed, 102 insertions(+), 23 deletions(-) delete mode 100644 Producer/ToastrProducer.php create mode 100644 Toastr.php create mode 100644 ToastrBuilder.php create mode 100644 ToastrFactory.php rename Renderer/ToastrRenderer.php => ToastrRenderer.php (65%) diff --git a/Producer/ToastrProducer.php b/Producer/ToastrProducer.php deleted file mode 100644 index 5eebc45a..00000000 --- a/Producer/ToastrProducer.php +++ /dev/null @@ -1,14 +0,0 @@ -title; + } + + /** + * @param string $title + */ + public function setTitle($title) + { + $this->title = $title; + } +} diff --git a/ToastrBuilder.php b/ToastrBuilder.php new file mode 100644 index 00000000..17d8dfda --- /dev/null +++ b/ToastrBuilder.php @@ -0,0 +1,24 @@ +envelope->getNotification(); + $notification->setTitle($title); + + return $this; + } +} diff --git a/ToastrFactory.php b/ToastrFactory.php new file mode 100644 index 00000000..737d57c9 --- /dev/null +++ b/ToastrFactory.php @@ -0,0 +1,32 @@ +getEventDispatcher(), $this->createNotification(), 'toastr'); + } + + /** + * @inheritDoc + */ + public function supports($name = null, array $context = array()) + { + return in_array($name, array(__CLASS__, 'toastr')); + } +} diff --git a/Renderer/ToastrRenderer.php b/ToastrRenderer.php similarity index 65% rename from Renderer/ToastrRenderer.php rename to ToastrRenderer.php index 6c32905a..3474347e 100644 --- a/Renderer/ToastrRenderer.php +++ b/ToastrRenderer.php @@ -1,18 +1,18 @@ getContext(); - $options = isset($context['options']) ? $context['options'] : array(); + $notification = $envelope->getNotification(); + $options = $envelope->getOptions(); return sprintf( "toastr.%s('%s', '%s', %s);", - $envelope->getType(), - $envelope->getMessage(), - $envelope->getTitle(), + $notification->getType(), + $notification->getMessage(), + $notification->getTitle(), json_encode($options) ); } @@ -76,4 +76,12 @@ class ToastrRenderer implements RendererInterface, HasScriptsInterface, HasStyle { return sprintf('toastr.options = %s;', json_encode($this->options)); } + + /** + * @inheritDoc + */ + public function supports($name = null, array $context = array()) + { + return in_array($name, array(__CLASS__, 'toastr', 'Flasher\Toastr\Prime\ToastrFactory', 'Flasher\Toastr\Prime\Toastr')); + } }