mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-03-31 15:07:47 +01:00
fix event dispatcher and call the storage service
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Toastr\Prime\Producer;
|
||||
|
||||
final class ToastrProducer extends \Flasher\Prime\AbstractFlasher
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getRenderer()
|
||||
{
|
||||
return 'toastr';
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Toastr\Prime;
|
||||
|
||||
use Flasher\Prime\Notification\Notification;
|
||||
|
||||
final class Toastr extends Notification
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $title;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
*/
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Toastr\Prime;
|
||||
|
||||
use Flasher\Prime\Notification\NotificationBuilder;
|
||||
|
||||
/**
|
||||
* @method Toastr getNotification()
|
||||
*/
|
||||
final class ToastrBuilder extends NotificationBuilder
|
||||
{
|
||||
/**
|
||||
* @param string $title
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function title($title)
|
||||
{
|
||||
$notification = $this->envelope->getNotification();
|
||||
$notification->setTitle($title);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Toastr\Prime;
|
||||
|
||||
use Flasher\Prime\Factory\AbstractFactory;
|
||||
|
||||
final class ToastrFactory extends AbstractFactory
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function createNotification()
|
||||
{
|
||||
return new Toastr();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function createNotificationBuilder()
|
||||
{
|
||||
return new ToastrBuilder($this->getEventDispatcher(), $this->createNotification(), 'toastr');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function supports($name = null, array $context = array())
|
||||
{
|
||||
return in_array($name, array(__CLASS__, 'toastr'));
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Toastr\Prime\Renderer;
|
||||
namespace Flasher\Toastr\Prime;
|
||||
|
||||
use Flasher\Prime\Config\ConfigInterface;
|
||||
use Flasher\Prime\Envelope;
|
||||
use Flasher\Prime\Renderer\HasGlobalOptionsInterface;
|
||||
use Flasher\Prime\Renderer\HasOptionsInterface;
|
||||
use Flasher\Prime\Renderer\HasScriptsInterface;
|
||||
use Flasher\Prime\Renderer\HasStylesInterface;
|
||||
use Flasher\Prime\Renderer\RendererInterface;
|
||||
|
||||
class ToastrRenderer implements RendererInterface, HasScriptsInterface, HasStylesInterface, HasGlobalOptionsInterface
|
||||
final class ToastrRenderer implements RendererInterface, HasScriptsInterface, HasStylesInterface, HasOptionsInterface
|
||||
{
|
||||
/**
|
||||
* @var \Flasher\Prime\Config\ConfigInterface
|
||||
* @var ConfigInterface
|
||||
*/
|
||||
private $config;
|
||||
|
||||
@@ -44,14 +44,14 @@ class ToastrRenderer implements RendererInterface, HasScriptsInterface, HasStyle
|
||||
*/
|
||||
public function render(Envelope $envelope)
|
||||
{
|
||||
$context = $envelope->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'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user