本文整理匯總了PHP中Zend\EventManager\StaticEventManager類的典型用法代碼示例。如果您正苦於以下問題:PHP StaticEventManager類的具體用法?PHP StaticEventManager怎麽用?PHP StaticEventManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了StaticEventManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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);
}
}
}
}
示例2: __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());
});
}
示例3: 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);
}
}
示例4: 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);
}
示例5: 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'));
}
示例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: setUp
public function setUp()
{
StaticEventManager::resetInstance();
if (isset($this->message)) {
unset($this->message);
}
$this->events = new EventManager();
}
示例8: _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);
});
}
示例9: setUp
public function setUp()
{
StaticEventManager::resetInstance();
$this->controller = new TestAsset\SampleController();
$this->request = new Request();
$this->response = null;
$this->routeMatch = new RouteMatch(array('controller' => 'controller-sample'));
$this->event = new MvcEvent();
$this->event->setRouteMatch($this->routeMatch);
$this->controller->setEvent($this->event);
}
示例10: setUp
public function setUp()
{
StaticEventManager::resetInstance();
$this->controller = new IndexController();
$this->request = new Request();
$this->response = null;
$this->routeMatch = new RouteMatch(array('controller' => 'php-unit-controller-index'));
$this->event = new MvcEvent();
$this->event->setRouteMatch($this->routeMatch);
$this->controller->setEvent($this->event);
}
示例11: 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);
}
示例12: 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));
});
}
示例13: 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);
}
示例14: _after
public function _after(\Codeception\TestCase $test)
{
$_SESSION = array();
$_GET = array();
$_POST = array();
$_COOKIE = array();
// reset singleton
StaticEventManager::resetInstance();
Placeholder\Registry::unsetRegistry();
$this->queries = 0;
$this->time = 0;
}
示例15: 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;
});
}