From d0c0a0340a00cd1ceef50aede5026f9c694550f6 Mon Sep 17 00:00:00 2001 From: Khoubza Younes Date: Mon, 7 Dec 2020 04:35:29 +0100 Subject: [PATCH] rename builder dispatch method to flash and add addFlash method --- Factory/AbstractFactory.php | 3 ++- Flasher.php | 10 ++++++++++ FlasherInterface.php | 24 ++++++++++++++++++++++++ Notification/NotificationBuilder.php | 20 +++++++++++++++++++- 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/Factory/AbstractFactory.php b/Factory/AbstractFactory.php index 34973cf6..0fd42012 100644 --- a/Factory/AbstractFactory.php +++ b/Factory/AbstractFactory.php @@ -26,7 +26,8 @@ use Flasher\Prime\Stamp\StampInterface; * @method NotificationBuilderInterface error($message = null, array $options = array()) * @method NotificationBuilderInterface info($message = null, array $options = array()) * @method NotificationBuilderInterface warning($message = null, array $options = array()) - * @method Envelope dispatch(StampInterface[] $stamps) + * @method Envelope flash(StampInterface[] $stamps) + * @method Envelope addFlash(string|Envelope $type, string $message = null, array $options = array()) * @method NotificationInterface getNotification() * @method NotificationInterface getEnvelope() */ diff --git a/Flasher.php b/Flasher.php index 4d4f3bfb..25914600 100644 --- a/Flasher.php +++ b/Flasher.php @@ -5,6 +5,7 @@ namespace Flasher\Prime; use Flasher\Prime\Manager\AbstractManager; use Flasher\Prime\Notification\NotificationBuilderInterface; use Flasher\Prime\Notification\NotificationInterface; +use Flasher\Prime\Stamp\StampInterface; /** * @method NotificationBuilderInterface type($type, $message = null, array $options = array()) @@ -12,11 +13,20 @@ use Flasher\Prime\Notification\NotificationInterface; * @method NotificationBuilderInterface options($options) * @method NotificationBuilderInterface setOption($name, $value) * @method NotificationBuilderInterface unsetOption($name) + * @method NotificationBuilderInterface handler(string $handler) + * @method NotificationBuilderInterface with(StampInterface[] $stamps) + * @method NotificationBuilderInterface withStamp(StampInterface $stamp) + * @method NotificationBuilderInterface priority($priority) + * @method NotificationBuilderInterface hops($amount) + * @method NotificationBuilderInterface keep() * @method NotificationBuilderInterface success($message = null, array $options = array()) * @method NotificationBuilderInterface error($message = null, array $options = array()) * @method NotificationBuilderInterface info($message = null, array $options = array()) * @method NotificationBuilderInterface warning($message = null, array $options = array()) + * @method Envelope flash(StampInterface[] $stamps) + * @method Envelope addFlash(string|Envelope $type, string $message = null, array $options = array()) * @method NotificationInterface getNotification() + * @method NotificationInterface getEnvelope() */ final class Flasher extends AbstractManager implements FlasherInterface { diff --git a/FlasherInterface.php b/FlasherInterface.php index 37c192ed..abf0b217 100644 --- a/FlasherInterface.php +++ b/FlasherInterface.php @@ -3,7 +3,31 @@ namespace Flasher\Prime; use Flasher\Prime\Factory\FlasherFactoryInterface; +use Flasher\Prime\Notification\NotificationBuilderInterface; +use Flasher\Prime\Notification\NotificationInterface; +use Flasher\Prime\Stamp\StampInterface; +/** + * @method NotificationBuilderInterface type($type, $message = null, array $options = array()) + * @method NotificationBuilderInterface message($message) + * @method NotificationBuilderInterface options($options) + * @method NotificationBuilderInterface setOption($name, $value) + * @method NotificationBuilderInterface unsetOption($name) + * @method NotificationBuilderInterface handler(string $handler) + * @method NotificationBuilderInterface with(StampInterface[] $stamps) + * @method NotificationBuilderInterface withStamp(StampInterface $stamp) + * @method NotificationBuilderInterface priority($priority) + * @method NotificationBuilderInterface hops($amount) + * @method NotificationBuilderInterface keep() + * @method NotificationBuilderInterface success($message = null, array $options = array()) + * @method NotificationBuilderInterface error($message = null, array $options = array()) + * @method NotificationBuilderInterface info($message = null, array $options = array()) + * @method NotificationBuilderInterface warning($message = null, array $options = array()) + * @method Envelope flash(StampInterface[] $stamps) + * @method Envelope addFlash(string|Envelope $type, string $message = null, array $options = array()) + * @method NotificationInterface getNotification() + * @method NotificationInterface getEnvelope() + */ interface FlasherInterface { /** diff --git a/Notification/NotificationBuilder.php b/Notification/NotificationBuilder.php index fd1bc589..c5601d31 100644 --- a/Notification/NotificationBuilder.php +++ b/Notification/NotificationBuilder.php @@ -232,7 +232,7 @@ class NotificationBuilder implements NotificationBuilderInterface * * @return Envelope|mixed */ - public function dispatch($stamps = array()) + public function flash($stamps = array()) { if (!empty($stamps)) { $this->with($stamps); @@ -244,4 +244,22 @@ class NotificationBuilder implements NotificationBuilderInterface return $this->eventDispatcher->dispatch($event); } + + /** + * @param string $type + * @param string $message + * @param array $options + * + * @return Envelope|mixed + */ + public function addFlash($type, $message, array $options = array()) + { + if (is_string($type)) { + $this->type($type, $message, $options); + } elseif ($type instanceof NotificationInterface) { + $this->envelope = Envelope::wrap($type); + } + + return $this->flash(); + } }