rename builder dispatch method to flash and add addFlash method

This commit is contained in:
Khoubza Younes
2020-12-07 04:35:29 +01:00
parent 636da37e23
commit d0c0a0340a
4 changed files with 55 additions and 2 deletions
+2 -1
View File
@@ -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()
*/
+10
View File
@@ -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
{
+24
View File
@@ -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
{
/**
+19 -1
View File
@@ -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();
}
}