fix event dispatcher and call the storage service

This commit is contained in:
Khoubza Younes
2020-12-06 04:03:14 +01:00
parent 99f68a2dee
commit 5fa41f3e67
22 changed files with 465 additions and 209 deletions
@@ -0,0 +1,28 @@
<?php
namespace Flasher\Symfony\DependencyInjection\Compiler;
use Flasher\Prime\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
final class EventSubscriberCompilerPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if (!$container->has('flasher.event_dispatcher')) {
return;
}
/** @var EventDispatcherInterface $flasherBus */
$eventDispatcher = $container->findDefinition('flasher.event_dispatcher');
foreach ($container->findTaggedServiceIds('flasher.event_subscriber') as $id => $tags) {
$eventDispatcher->addMethodCall('addSubscriber', array(new Reference($id)));
}
}
}
@@ -0,0 +1,28 @@
<?php
namespace Flasher\Symfony\DependencyInjection\Compiler;
use Flasher\Prime\Flasher;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
final class FactoryCompilerPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if (!$container->has('flasher.factory_manager')) {
return;
}
/** @var Flasher $manager */
$manager = $container->findDefinition('flasher.factory_manager');
foreach ($container->findTaggedServiceIds('flasher.factory') as $id => $tags) {
$manager->addMethodCall('addDriver', array(new Reference($id)));
}
}
}
@@ -2,6 +2,7 @@
namespace Flasher\Symfony\DependencyInjection\Compiler;
use Flasher\Prime\Filter\FilterManager;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
@@ -13,20 +14,15 @@ final class FilterCompilerPass implements CompilerPassInterface
*/
public function process(ContainerBuilder $container)
{
if (!$container->has('notify.filter')) {
if (!$container->has('flasher.filter_manager')) {
return;
}
/** @var \Flasher\Prime\Filter\FilterManager $manager */
$manager = $container->findDefinition('notify.filter');
/** @var FilterManager $manager */
$manager = $container->findDefinition('flasher.filter_manager');
foreach ($container->findTaggedServiceIds('notify.filter') as $id => $tags) {
foreach ($tags as $attributes) {
$manager->addMethodCall('addDriver', array(
$attributes['alias'],
new Reference($id),
));
}
foreach ($container->findTaggedServiceIds('flasher.filter') as $id => $tags) {
$manager->addMethodCall('addDriver', array(new Reference($id)));
}
}
}
@@ -0,0 +1,28 @@
<?php
namespace Flasher\Symfony\DependencyInjection\Compiler;
use Flasher\Prime\Middleware\FlasherBus;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
final class MiddlewareCompilerPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if (!$container->has('flasher.flasher_bus')) {
return;
}
/** @var FlasherBus $flasherBus */
$flasherBus = $container->findDefinition('flasher.flasher_bus');
foreach ($container->findTaggedServiceIds('flasher.middleware') as $id => $tags) {
$flasherBus->addMethodCall('addMiddleware', array(new Reference($id)));
}
}
}
@@ -2,6 +2,7 @@
namespace Flasher\Symfony\DependencyInjection\Compiler;
use Flasher\Prime\Presenter\PresenterManager;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
@@ -13,20 +14,15 @@ final class PresenterCompilerPass implements CompilerPassInterface
*/
public function process(ContainerBuilder $container)
{
if (!$container->has('notify.presenter')) {
if (!$container->has('flasher.presenter_manager')) {
return;
}
/** @var \Flasher\Prime\Presenter\PresenterManager $manager */
$manager = $container->findDefinition('notify.presenter');
/** @var PresenterManager $manager */
$manager = $container->findDefinition('flasher.presenter_manager');
foreach ($container->findTaggedServiceIds('notify.presenter') as $id => $tags) {
foreach ($tags as $attributes) {
$manager->addMethodCall('addDriver', array(
$attributes['alias'],
new Reference($id),
));
}
foreach ($container->findTaggedServiceIds('flasher.presenter') as $id => $tags) {
$manager->addMethodCall('addDriver', array(new Reference($id)));
}
}
}
@@ -1,32 +0,0 @@
<?php
namespace Flasher\Symfony\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
final class ProducerCompilerPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if (!$container->has('notify.producer')) {
return;
}
/** @var \Flasher\Prime\Flasher $manager */
$manager = $container->findDefinition('notify.producer');
foreach ($container->findTaggedServiceIds('notify.producer') as $id => $tags) {
foreach ($tags as $attributes) {
$manager->addMethodCall('addDriver', array(
$attributes['alias'],
new Reference($id),
));
}
}
}
}
@@ -2,6 +2,7 @@
namespace Flasher\Symfony\DependencyInjection\Compiler;
use Flasher\Prime\Renderer\RendererManager;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
@@ -13,20 +14,15 @@ final class RendererCompilerPass implements CompilerPassInterface
*/
public function process(ContainerBuilder $container)
{
if (!$container->has('notify.renderer')) {
if (!$container->has('flasher.renderer_manager')) {
return;
}
/** @var \Flasher\Prime\Renderer\RendererManager $manager */
$manager = $container->findDefinition('notify.renderer');
/** @var RendererManager $manager */
$manager = $container->findDefinition('flasher.renderer_manager');
foreach ($container->findTaggedServiceIds('notify.renderer') as $id => $tags) {
foreach ($tags as $attributes) {
$manager->addMethodCall('addDriver', array(
$attributes['alias'],
new Reference($id),
));
}
foreach ($container->findTaggedServiceIds('flasher.renderer') as $id => $tags) {
$manager->addMethodCall('addDriver', array(new Reference($id)));
}
}
}
+3 -7
View File
@@ -12,13 +12,13 @@ final class Configuration implements ConfigurationInterface
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('notify');
$treeBuilder = new TreeBuilder('flasher');
if (\method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->getRootNode();
} else {
// BC layer for symfony/config 4.1 and older
$rootNode = $treeBuilder->root('notify');
$rootNode = $treeBuilder->root('flasher');
}
$rootNode
@@ -30,7 +30,7 @@ final class Configuration implements ConfigurationInterface
->arrayNode('scripts')
->prototype('scalar')->end()
->defaultValue(array(
'/vendor/php-flasher/flasher/assets/js/notify.js'
'/bundles/flasher/js/flasher.js'
))
->end()
->arrayNode('styles')
@@ -42,10 +42,6 @@ final class Configuration implements ConfigurationInterface
->useAttributeAsKey('name')
->prototype('variable')->end()
->end()
->arrayNode('stamps_middlewares')
->ignoreExtraKeys(false)
->prototype('variable')->end()
->end()
->end()
;
@@ -6,9 +6,8 @@ use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Flasher\Symfony\Config\Config;
final class NotifyExtension extends Extension
final class FlasherExtension extends Extension
{
/**
* {@inheritdoc}
@@ -18,12 +17,12 @@ final class NotifyExtension extends Extension
public function load(array $configs, ContainerBuilder $container)
{
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yaml');
$loader->load('config.yaml');
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$notifyConfig = $container->getDefinition('notify.config');
$notifyConfig = $container->getDefinition('flasher.config');
$notifyConfig->replaceArgument(0, $config);
}
}
+7 -3
View File
@@ -2,21 +2,25 @@
namespace Flasher\Symfony;
use Flasher\Symfony\DependencyInjection\Compiler\EventSubscriberCompilerPass;
use Flasher\Symfony\DependencyInjection\Compiler\FilterCompilerPass;
use Flasher\Symfony\DependencyInjection\Compiler\ProducerCompilerPass;
use Flasher\Symfony\DependencyInjection\Compiler\FactoryCompilerPass;
use Flasher\Symfony\DependencyInjection\Compiler\MiddlewareCompilerPass;
use Flasher\Symfony\DependencyInjection\Compiler\RendererCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class NotifyBundle extends Bundle
class FlasherBundle extends Bundle
{
/**
* {@inheritdoc}
*/
public function build(ContainerBuilder $container)
{
$container->addCompilerPass(new ProducerCompilerPass());
$container->addCompilerPass(new FactoryCompilerPass());
$container->addCompilerPass(new RendererCompilerPass());
$container->addCompilerPass(new FilterCompilerPass());
$container->addCompilerPass(new MiddlewareCompilerPass());
$container->addCompilerPass(new EventSubscriberCompilerPass());
}
}
+27
View File
@@ -0,0 +1,27 @@
services:
Flasher\Prime\Config\Config: '@flasher.config'
Flasher\Prime\Manager\AbstractManager: '@flasher.abstract_manager'
Flasher\Prime\Flasher: '@flasher'
Flasher\Prime\Presenter\PresenterManager: '@flasher.presenter_manager'
Flasher\Prime\Renderer\RendererManager: '@flasher.renderer_manager'
Flasher\Prime\Middleware\FlasherBus: '@flasher.flasher_bus'
Flasher\Prime\EventDispatcher\EventDispatcher: '@flasher.event_dispatcher'
Flasher\Symfony\Storage\Storage: '@flasher.storage'
Flasher\Prime\Storage\StorageManager: '@flasher.storage_manager'
Flasher\Prime\Filter\FilterManager: '@flasher.filter_manager'
Flasher\Prime\Filter\FilterBuilder: '@flasher.filter_builder'
Flasher\Prime\Filter\DefaultFilter: '@flasher.filter.default'
Flasher\Prime\Factory\AbstractFactory: '@flasher.abstract_factory'
Flasher\Prime\Presenter\AbstractPresenter: '@flasher.abstract_presenter'
Flasher\Prime\Presenter\Adapter\JsonPresenter: '@flasher.presenter.json'
Flasher\Prime\Presenter\Adapter\HtmlPresenter: '@flasher.presenter.html'
flasher.factory_manager: '@flasher'
Flasher\Prime\FlasherInterface: '@flasher'
Flasher\Prime\Storage\StorageManagerInterface: '@flasher.storage_manager'
Flasher\Prime\Renderer\RendererManagerInterface: '@flasher.renderer_manager'
Flasher\Prime\Presenter\PresenterManagerInterface: '@flasher.presenter_manager'
Flasher\Prime\Middleware\FlasherBusInterface: '@flasher.flasher_bus'
Flasher\Prime\Filter\FilterManagerInterface: '@flasher.filter_manager'
Flasher\Prime\EventDispatcher\EventDispatcherInterface: '@flasher.event_dispatcher'
Flasher\Prime\Storage\StorageInterface: '@flasher.storage'
+35
View File
@@ -0,0 +1,35 @@
imports:
# - { resource: 'services.yaml' }
- { resource: 'middlewares.yaml' }
- { resource: 'storage.yaml' }
- { resource: 'presenters.yaml' }
- { resource: 'filters.yaml' }
- { resource: 'twig.yaml' }
- { resource: 'event_subscribers.yaml' }
- { resource: 'aliases.yaml' }
services:
flasher.config:
class: Flasher\Prime\Config\Config
arguments:
- null
flasher.abstract_manager:
class: Flasher\Prime\Manager\AbstractManager
abstract: true
arguments:
- '@flasher.config'
flasher:
class: Flasher\Prime\Flasher
parent: 'flasher.abstract_manager'
flasher.abstract_factory:
class: Flasher\Prime\Factory\AbstractFactory
abstract: true
arguments:
- '@flasher.event_dispatcher'
flasher.renderer_manager:
class: Flasher\Prime\Renderer\RendererManager
parent: 'flasher.abstract_manager'
+29
View File
@@ -0,0 +1,29 @@
services:
flasher.event_dispatcher:
class: Flasher\Prime\EventDispatcher\EventDispatcher
Flasher\Prime\EventDispatcher\EventListener\PostFilterListener:
public: false
tags:
- 'flasher.event_subscriber'
Flasher\Prime\EventDispatcher\EventListener\PostFlushListener:
public: false
arguments:
- '@flasher.storage'
tags:
- 'flasher.event_subscriber'
Flasher\Prime\EventDispatcher\EventListener\MiddlewareListener:
public: false
arguments:
- '@flasher.flasher_bus'
tags:
- 'flasher.event_subscriber'
Flasher\Prime\EventDispatcher\EventListener\StorageListener:
public: false
arguments:
- '@flasher.storage'
tags:
- 'flasher.event_subscriber'
+14
View File
@@ -0,0 +1,14 @@
services:
flasher.filter_manager:
class: Flasher\Prime\Filter\FilterManager
parent: 'flasher.abstract_manager'
flasher.filter_builder:
class: Flasher\Prime\Filter\FilterBuilder
flasher.filter.default:
class: Flasher\Prime\Filter\DefaultFilter
arguments:
- '@flasher.filter_builder'
tags:
- 'flasher.filter'
+23
View File
@@ -0,0 +1,23 @@
services:
flasher.flasher_bus:
class: Flasher\Prime\Middleware\FlasherBus
Flasher\Prime\Middleware\AddCreatedAtStampMiddleware:
public: false
tags:
- 'flasher.middleware'
Flasher\Prime\Middleware\AddHopsStampMiddleware:
public: false
tags:
- 'flasher.middleware'
Flasher\Prime\Middleware\AddPriorityStampMiddleware:
public: false
tags:
- 'flasher.middleware'
Flasher\Prime\Middleware\AddRenderedAtStampMiddleware:
public: false
tags:
- 'flasher.middleware'
+26
View File
@@ -0,0 +1,26 @@
services:
flasher.presenter_manager:
class: Flasher\Prime\Presenter\PresenterManager
parent: 'flasher.abstract_manager'
flasher.abstract_presenter:
class: Flasher\Prime\Presenter\AbstractPresenter
abstract: true
arguments:
- '@flasher.event_dispatcher'
- '@flasher.config'
- '@flasher.storage_manager'
- '@flasher.filter_manager'
- '@flasher.renderer_manager'
flasher.presenter.html:
class: Flasher\Prime\Presenter\Adapter\HtmlPresenter
parent: 'flasher.abstract_presenter'
tags:
- 'flasher.presenter'
flasher.presenter.json:
class: Flasher\Prime\Presenter\Adapter\JsonPresenter
parent: 'flasher.abstract_presenter'
tags:
- 'flasher.presenter'
+13 -79
View File
@@ -1,91 +1,25 @@
services:
notify.config:
flasher.config:
class: Flasher\Prime\Config\Config
arguments:
- null
notify.producer:
class: Flasher\Prime\Producer\ProducerManager
flasher.abstract_manager:
class: Flasher\Prime\Manager\AbstractManager
abstract: true
arguments:
- '@notify.config'
- '@flasher.config'
notify.presenter:
class: Flasher\Prime\Presenter\PresenterManager
flasher:
class: Flasher\Prime\Flasher
parent: 'flasher.abstract_manager'
notify.renderer:
flasher.renderer_manager:
class: Flasher\Prime\Renderer\RendererManager
arguments:
- '@notify.config'
parent: 'flasher.abstract_manager'
notify.middleware:
class: Flasher\Prime\Middleware\MiddlewareManager
arguments:
- '@notify.config'
notify.storage:
class: Flasher\Symfony\Storage\Storage
arguments:
- '@session'
notify.filter:
class: Flasher\Prime\Filter\FilterManager
arguments:
- '@notify.config'
notify.producer.abstract:
class: Flasher\Prime\Producer\AbstractProducer
flasher.abstract_factory:
class: Flasher\Prime\Factory\AbstractFactory
abstract: true
arguments:
- '@notify.storage'
- '@notify.middleware'
notify.presenter.abstract:
class: Flasher\Prime\Presenter\AbstractPresenter
abstract: true
arguments:
- '@notify.config'
- '@notify.storage'
- '@notify.filter'
- '@notify.renderer'
notify.presenter.html:
class: Flasher\Prime\Presenter\Adapter\HtmlPresenter
parent: 'notify.presenter.abstract'
tags:
- { name: 'notify.presenter', alias: 'html' }
notify.presenter.json:
class: Flasher\Prime\Presenter\Adapter\JsonPresenter
parent: 'notify.presenter.abstract'
tags:
- { name: 'notify.presenter', alias: 'json' }
notify.twig_extension:
class: Flasher\Symfony\TwigFlasher\PrimeTwigExtension
arguments:
- '@notify.presenter.html'
public: false
tags:
- { name: twig.extension }
notify.filter_builder:
class: Flasher\Prime\Filter\FilterBuilder
notify.filter.default:
class: Flasher\Prime\Filter\DefaultFilter
arguments:
- '@notify.filter_builder'
tags:
- { name: 'notify.filter', alias: 'default' }
Flasher\Prime\Config\Config: '@notify.config'
Flasher\Prime\Producer\ProducerManager: '@notify.producer'
Flasher\Prime\Presenter\PresenterManager: '@notify.presenter'
Flasher\Prime\Renderer\RendererManager: '@notify.renderer'
Flasher\Prime\Middleware\MiddlewareManager: '@notify.middleware'
Flasher\Symfony\Storage\Storage: '@notify.storage'
Flasher\Prime\Filter\FilterManager: '@notify.filter'
Flasher\Prime\Filter\DefaultFilter: '@notify.filter.default'
Flasher\Prime\Filter\FilterBuilder: '@notify.filter_builder'
Flasher\Prime\Presenter\Json\JsonPresenter: '@notify.presenter.json'
Flasher\Prime\Presenter\Html\HtmlPresenter: '@notify.presenter.html'
- '@flasher.flasher_bus'
+11
View File
@@ -0,0 +1,11 @@
services:
flasher.storage:
class: Flasher\Symfony\Storage\Storage
arguments:
- '@session'
flasher.storage_manager:
class: Flasher\Prime\Storage\StorageManager
arguments:
- '@flasher.storage'
- '@flasher.event_dispatcher'
+7
View File
@@ -0,0 +1,7 @@
services:
Flasher\Symfony\Twig\FlasherTwigExtension:
class:
arguments:
- '@flasher.presenter.html'
tags:
- 'twig.extension'
+114
View File
@@ -0,0 +1,114 @@
/*!
* PHPFlasher js 1.0.0
* https://github.com/php-flasher/flasher
* @license MIT licensed
*
* Copyright (C) 2020 Younes KHOUBZA
*/
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory(root));
} else if (typeof exports === 'object') {
module.exports = factory(root);
} else {
root.PHPFlasher = factory(root);
}
})(typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : this, function (window) {
'use strict';
var exports = {};
exports.render = function (_settings) {
var settings = Object.assign({}, {
scripts: [],
styles: [],
options: [],
notifications: [],
}, _settings);
exports.addStyles(settings.styles, function () {
exports.addScripts(settings.scripts, function () {
var script = '';
settings.options.forEach(function (option) {
script += option + "\n";
});
script += "\n\n";
settings.notifications.forEach(function (notification) {
script += notification.code + "\n";
});
exports.parseScript(script);
});
});
};
exports.addStyles = function (urls, callback) {
if (0 === urls.length) {
if ("function" === typeof callback) {
callback();
}
return this;
}
if (null !== document.querySelector(`link[href='${urls[0]}']`)) {
return exports.addStyles(urls.slice(1), callback);
}
var tag = document.createElement('link');
tag.href = urls[0];
tag.type = 'text/css';
tag.rel = 'stylesheet';
tag.onload = function () {
exports.addStyles(urls.slice(1), callback);
};
document.head.appendChild(tag);
return this;
};
exports.addScripts = function (urls, callback) {
if (0 === urls.length) {
if ("function" === typeof callback) {
callback();
}
return this;
}
if (null !== document.querySelector(`script[src='${urls[0]}']`)) {
return exports.addScripts(urls.slice(1), callback);
}
var tag = document.createElement('script');
tag.src = urls[0];
tag.type = 'text/javascript';
tag.onload = function () {
exports.addScripts(urls.slice(1), callback);
};
document.body.appendChild(tag);
return this;
};
exports.parseScript = function (script) {
var tag = document.createElement('script');
tag.type = "text/javascript";
tag.text = script;
document.body.appendChild(tag);
return this;
};
return exports;
});
+48 -50
View File
@@ -3,79 +3,48 @@
namespace Flasher\Symfony\Storage;
use Flasher\Prime\Envelope;
use Flasher\Prime\Stamp\CreatedAtStamp;
use Flasher\Prime\Stamp\LifeStamp;
use Flasher\Prime\Stamp\UuidStamp;
use Flasher\Prime\Storage\StorageInterface;
use Symfony\Component\HttpFoundation\Session\Session;
final class Storage implements StorageInterface
{
const ENVELOPES_NAMESPACE = 'notify::envelopes';
const ENVELOPES_NAMESPACE = 'flasher::envelopes';
/**
* @var Session
*/
private $session;
/**
* @param Session $session
*/
public function __construct(Session $session)
{
$this->session = $session;
}
public function get()
/**
* @inheritDoc
*/
public function all()
{
return $this->session->get(self::ENVELOPES_NAMESPACE, array());
}
public function add(Envelope $envelope)
{
if (null === $envelope->get('Flasher\Prime\Stamp\UuidStamp')) {
$envelope->withStamp(new UuidStamp());
}
if (null === $envelope->get('Flasher\Prime\Stamp\UuidStamp')) {
$envelope->withStamp(new UuidStamp());
}
if (null === $envelope->get('Flasher\Prime\Stamp\LifeStamp')) {
$envelope->withStamp(new LifeStamp(1));
}
if (null === $envelope->get('Flasher\Prime\Stamp\CreatedAtStamp')) {
$envelope->withStamp(new CreatedAtStamp());
}
$envelopes = $this->get();
$envelopes[] = $envelope;
$this->session->set(self::ENVELOPES_NAMESPACE, $envelopes);
}
/**
* @param Envelope[] $envelopes
* @inheritDoc
*/
public function flush($envelopes)
public function add($envelopes)
{
$envelopesMap = array();
$envelopes = is_array($envelopes) ? $envelopes : func_get_args();
$envelopes = array_merge($envelopes, $this->all());
$store = $this->all();
foreach ($envelopes as $envelope) {
$life = $envelope->get('Flasher\Prime\Stamp\LifeStamp')->getLife();
$uuid = $envelope->get('Flasher\Prime\Stamp\UuidStamp')->getUuid();
$envelopesMap[$uuid] = $life;
}
$store = array();
foreach ($this->session->get(self::ENVELOPES_NAMESPACE, array()) as $envelope) {
$uuid = $envelope->get('Flasher\Prime\Stamp\UuidStamp')->getUuid();
if(isset($envelopesMap[$uuid])) {
$life = $envelopesMap[$uuid] - 1;
if ($life <= 0) {
continue;
}
$envelope->with(new LifeStamp($life));
if (null === $envelope->get('Flasher\Prime\Stamp\UuidStamp')) {
$envelope->withStamp(new UuidStamp());
}
$store[] = $envelope;
@@ -83,4 +52,33 @@ final class Storage implements StorageInterface
$this->session->set(self::ENVELOPES_NAMESPACE, $store);
}
/**
* @inheritDoc
*/
public function remove($envelopes)
{
$envelopes = is_array($envelopes) ? $envelopes : func_get_args();
$map = UuidStamp::indexWithUuid($envelopes);
$store = array_filter(
$this->all(),
function (Envelope $envelope) use ($map) {
$uuid = $envelope->get('Flasher\Prime\Stamp\UuidStamp')->getUuid();
return !isset($map[$uuid]);
}
);
$this->session->set(self::ENVELOPES_NAMESPACE, $store);
}
/**
* @inheritDoc
*/
public function clear()
{
$this->session->set(self::ENVELOPES_NAMESPACE, array());
}
}
@@ -3,11 +3,10 @@
namespace Flasher\Symfony\Twig;
use Flasher\Prime\Presenter\Adapter\HtmlPresenter;
use Flasher\Prime\Presenter\PresenterManager;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
final class NotifyTwigExtension extends AbstractExtension
final class FlasherTwigExtension extends AbstractExtension
{
private $htmlPresenter;
@@ -21,7 +20,7 @@ final class NotifyTwigExtension extends AbstractExtension
$options = array('is_safe' => array('html'));
return array(
new TwigFunction('notify_render', array($this, 'notifyRender'), $options),
new TwigFunction('flasher_render', array($this, 'flasherRender'), $options),
);
}
@@ -30,7 +29,7 @@ final class NotifyTwigExtension extends AbstractExtension
*
* @return string
*/
public function notifyRender($criteria = null)
public function flasherRender($criteria = null)
{
return $this->htmlPresenter->render($criteria);
}