Commit 3fc0be45 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Aid de vue Messenger: injection du plugin flashMessenger par la factory.

parent f9e45024
......@@ -6,9 +6,8 @@ use UnicaenApp\Traits\MessageAwareInterface;
use UnicaenApp\Traits\MessageAwareTrait;
use Zend\EventManager\EventManagerAwareInterface;
use Zend\EventManager\EventManagerAwareTrait;
use Zend\Mvc\Plugin\FlashMessenger\FlashMessenger as FlashMessengerPlugin;
use Zend\View\Helper\AbstractHelper;
use Zend\View\Helper\FlashMessenger;
use Zend\View\Renderer\PhpRenderer;
/**
* Aide de vue permettant de stocker une liste de messages d'information de différentes sévérités
......@@ -62,7 +61,7 @@ class Messenger extends AbstractHelper implements MessageAwareInterface, EventMa
protected $containerClassesToAdd = [];
/**
* @var \Zend\Mvc\Controller\Plugin\FlashMessenger
* @var FlashMessengerPlugin
*/
protected $pluginFlashMessenger;
......@@ -524,19 +523,18 @@ EOT;
}
/**
* @return \Zend\Mvc\Controller\Plugin\FlashMessenger
* @param FlashMessengerPlugin $pluginFlashMessenger
*/
protected function getPluginFlashMessenger()
public function setPluginFlashMessenger(FlashMessengerPlugin $pluginFlashMessenger)
{
if (null === $this->pluginFlashMessenger) {
/** @var PhpRenderer $view */
$view = $this->getView();
/* @var $vh FlashMessenger */
$vh = $view->getHelperPluginManager()->get('flashMessenger');
$this->pluginFlashMessenger = $vh->getPluginFlashMessenger();
}
$this->pluginFlashMessenger = $pluginFlashMessenger;
}
/**
* @return FlashMessengerPlugin
*/
protected function getPluginFlashMessenger()
{
return $this->pluginFlashMessenger;
}
}
\ No newline at end of file
......@@ -3,30 +3,30 @@
namespace UnicaenApp\View\Helper;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\EventManager\EventManagerInterface;
use Zend\Mvc\Plugin\FlashMessenger\FlashMessenger as FlashMessengerPlugin;
/**
* Description of MessengerFactory
*
* @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
* @author Unicaen
*/
class MessengerFactory implements FactoryInterface
class MessengerFactory
{
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this->__invoke($serviceLocator, '?');
}
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
public function __invoke(ContainerInterface $container)
{
$messenger = new Messenger();
/* @var $application Application */
$application = $container->get('application');
if ($application){
$messenger->setEventManager($application->getEventManager());
}
/** @var FlashMessengerPlugin $flashMessengerPlugin */
$flashMessengerPlugin = $container->get('PluginManager')->get('flashMessenger');
$messenger->setPluginFlashMessenger($flashMessengerPlugin);
// /* @var $application Application */
// $application = $container->get('application');
// if ($application){
// $messenger->setEventManager($application->getEventManager());
// }
/** @var EventManagerInterface $eventManager */
$eventManager = $container->get('EventManager');
$messenger->setEventManager($eventManager);
return $messenger;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment