本文整理匯總了PHP中Zend\EventManager\StaticEventManager::getInstance方法的典型用法代碼示例。如果您正苦於以下問題:PHP StaticEventManager::getInstance方法的具體用法?PHP StaticEventManager::getInstance怎麽用?PHP StaticEventManager::getInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\EventManager\StaticEventManager
的用法示例。
在下文中一共展示了StaticEventManager::getInstance方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: __construct
public function __construct()
{
$event = $this->getEvent();
$this->viewModel = $event->getViewModel();
$sharedEvents = StaticEventManager::getInstance();
$sharedEvents->attach('Zend\\Mvc\\Controller\\AbstractActionController', MvcEvent::EVENT_DISPATCH, function (Event $event) {
// get view model for layout
$view = $event->getViewModel();
// assign locales information
$sm = $this->getServiceLocator();
$config = $sm->get('Configuration');
$view->setVariable('locale', $sm->get('translator')->getLocale());
$view->setVariable('locales', $config['locales']['list']);
// assign flashmessanger messages
$messages = $this->flashmessenger()->getSuccessMessages();
$view->setVariable('messages', $messages);
$info = $this->flashmessenger()->getInfoMessages();
$view->setVariable('info', $info);
$warnings = $this->flashmessenger()->getMessages();
$view->setVariable('warnings', $warnings);
$errors = $this->flashmessenger()->getErrorMessages();
$view->setVariable('errors', $errors);
// assign variables to action view
$this->viewModel->setVariables($view->getVariables());
});
}
示例2: attachConfigEvents
/**
* Attach scripts and links to the view helpers based on the configuration file.
* @todo Handle priority
* @todo Add extended specification for scripts and links
*/
protected function attachConfigEvents()
{
$config = $this->serviceLocator->get('Configuration');
if (isset($config['dots']['view']['events']) && is_array($config['dots']['view']['events'])) {
foreach ($config['dots']['view']['events'] as $name => $options) {
if (!empty($options)) {
StaticEventManager::getInstance()->attach('dots', $name, function (Event $event) use($options) {
$view = $event->getTarget();
if (isset($options['scripts']) && is_array($options['scripts'])) {
$scripts = array_filter($options['scripts'], function ($script) {
return $script != null;
});
foreach ($scripts as $script) {
$view->plugin('headScript')->appendFile($script);
}
}
if (isset($options['links']) && is_array($options['links'])) {
$links = array_filter($options['links'], function ($link) {
return $link != null;
});
foreach ($links as $script) {
$view->plugin('headLink')->appendStylesheet($script);
}
}
}, 200);
}
}
}
}
示例3: init
public function init()
{
// Attach Event to EventManager
$events = StaticEventManager::getInstance();
// Add event of authentication before dispatch
$events->attach('Zend\\View\\View', ViewEvent::EVENT_RENDERER_POST, array($this, 'addPiwikCode'), 110);
}
示例4: setEventCollection
public static function setEventCollection(EventManagerInterface $events = null)
{
parent::setEventCollection($events);
$sharedManager = StaticEventManager::getInstance();
static::$events->setSharedManager($sharedManager);
static::$events->setIdentifiers(array(__CLASS__, get_called_class(), 'dots'));
}
示例5: init
/**
* Initialize the module
*
* @param ModuleManager $m Module manager
*
* @return void
*/
public function init(ModuleManager $m)
{
if (!Console::isConsole()) {
$em = StaticEventManager::getInstance();
$em->attach('Zend\\Mvc\\Application', 'bootstrap', [$this, 'registerBaseUrl'], 100000);
}
}
示例6: init
public function init(Manager $moduleManager)
{
$events = StaticEventManager::getInstance();
# post configuration merge
$events->attach('Zend\\Module\\Manager', 'loadModules.post', array($this, 'postModulesLoadsListener'), 8);
# pre bootstrap
$events->attach('bootstrap', 'bootstrap', array($this, 'preBootstrapListener'), 20);
}
示例7: _afterLogin
private function _afterLogin($e)
{
$em = \Zend\EventManager\StaticEventManager::getInstance();
$em->attach('ZfcUser\\Authentication\\Adapter\\AdapterChain', 'authenticate.success', function ($e) {
$userId = $e->getIdentity();
$this->_logService->log(LogService::NOTICE, "Connexion de l'utilisateur: {$userId}", LogService::USER);
$this->_userTable->updateLastConnection($userId);
});
}
示例8: onBootstrap
public function onBootstrap($e)
{
$app = $e->getTarget();
$this->sm = $app->getServiceManager();
StaticEventManager::getInstance()->attach('ZF\\Rest\\RestController', 'getList.post', function ($e) {
$halCollection = $e->getParam('collection');
$parameters = $e->getTarget()->queryParams();
unset($parameters['page']);
$halCollection->setCollectionRouteOptions(array('query' => $parameters));
});
}
示例9: initializeView
public function initializeView(Event $e)
{
$app = $e->getParam('application');
$locator = $app->getLocator();
$config = $e->getParam('modules')->getMergedConfig();
$view = $this->getView($app, $config);
$viewListener = $this->getViewListener($view, $config);
$app->events()->attachAggregate($viewListener);
$events = StaticEventManager::getInstance();
$viewListener->registerStaticListeners($events, $locator);
}
示例10: onBootstrap
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$em = $e->getApplication()->getServiceManager()->get('Doctrine\\ORM\\EntityManager');
$platform = $em->getConnection()->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');
$this->initializeSessions($e);
$sharedEventManager = StaticEventManager::getInstance();
$sharedEventManager->attach(__NAMESPACE__, MvcEvent::EVENT_DISPATCH, array($this, 'onLoad'), 200);
}
示例11: defineEventHandlers
public function defineEventHandlers()
{
$events = StaticEventManager::getInstance();
$view = $this->di->get('view');
$events->attach('Zf2\\Mvc\\FrontController', 'dispatch.post', function ($e) use($view) {
$response = $e->getParam('response');
if ($response->getHeaders()->getStatusCode() != 302) {
$content = $view->render($e->getParam('request'), $e->getParam('__RESULT__'));
$response->setContent($content);
}
return $response;
});
}
示例12: onBootstrap
public function onBootstrap(MvcEvent $event)
{
$serviceManager = $event->getApplication()->getServiceManager();
$events = StaticEventManager::getInstance();
$events->attach('dots', 'blocks.admin.menu', function () use($serviceManager) {
$view = $serviceManager->get('DotsTwigViewRenderer');
//render admin navigation
$viewModel = new ViewModel();
$viewModel->setTemplate('dots-slideshow/admin/menu');
$viewModel->setTerminal(true);
return $view->render($viewModel);
});
}
示例13: attachDefaultListeners
/**
* Attach default events listeners for the dispatcher
*/
protected function attachDefaultListeners()
{
$events = StaticEventManager::getInstance();
foreach ($this->handlers as $class => $handlers) {
foreach ($handlers as $options) {
$event = explode(':', $options['event']);
if (array_key_exists('priority', $options)) {
$events->attach($event[0], $event[1], array($class, $options['handler']), $options['priority']);
} else {
$events->attach($event[0], $event[1], array($class, $options['handler']));
}
}
}
}
示例14: onBootstrap
public function onBootstrap($e)
{
$em = StaticEventManager::getInstance();
$em->attach('*', '*', function ($e) {
$event = $e->getName();
$target = get_class($e->getTarget());
$params = $e->getParams();
$output = sprintf('Event "%s" was triggered on target "%s", with parameters %s', $event, $target, json_encode($params));
error_log($output);
// Return true so this listener doesn't break the validator
// chain triggering session.validate listeners
return true;
});
}
示例15: testAuthenticate
public function testAuthenticate()
{
$authService = $this->prophesize(AuthenticationService::class);
$adapter = $this->prophesize(AdapterInterface::class);
$result = $this->prophesize(Result::class);
$authenticator = new Authenticator($authService->reveal(), $adapter->reveal());
$eventManager = StaticEventManager::getInstance();
// event will be raised
$eventManager->attach(Authenticator::class, AuthenticationEvent::EVENT_AUTH, function ($e) use($result) {
$this->assertInstanceOf(AuthenticationEvent::class, $e);
$e->setResult($result->reveal());
});
$returnedResult = $authenticator->authenticate();
$this->assertSame($result->reveal(), $returnedResult);
}