php Zend-EventManager-StaticEventManager类(方法)实例源码

下面列出了php Zend-EventManager-StaticEventManager 类(方法)源码代码实例,从而了解它的用法。

作者:Ellipizl    项目:dotscm   
/**
  * 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);
             }
         }
     }
 }

作者:evoli    项目:loculu   
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());
     });
 }

作者:samul    项目:vufind-er   
/**
  * 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);
     }
 }

作者:VaporFa    项目:piwi   
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);
 }

作者:Ellipizl    项目:dotscm   
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'));
 }

作者:widmogro    项目:zf2-facebook-modul   
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);
 }

作者:robertodormepoc    项目:zf   
public function setUp()
 {
     StaticEventManager::resetInstance();
     if (isset($this->message)) {
         unset($this->message);
     }
     $this->events = new EventManager();
 }

作者:antaru    项目:mystra-pv   
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);
     });
 }

作者:razvansividr    项目:pnlzf2-   
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);
 }

作者:jordiwe    项目:zf2.unlikelysource.or   
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);
 }

作者:bb-drumme    项目:Zcm   
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);
 }

作者:kapitch    项目:kap-apigilit   
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));
     });
 }

作者:kristjanAn    项目:SimpleI   
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);
 }

作者:Naszvadi    项目:ImageCM   
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;
 }

作者:Gee    项目:zf2-sandbo   
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;
     });
 }

作者:Ellipizl    项目:dotscm   
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);
     });
 }

作者:jvandem    项目:zf2-event-logge   
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;
     });
 }

作者:Ellipizl    项目:dotscm   
/**
  * 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']));
             }
         }
     }
 }

作者:t4we    项目:authenticatio   
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);
 }

作者:Eli-T    项目:Codeceptio   
public function _after(\Codeception\TestCase $test)
 {
     $_SESSION = array();
     $_GET = array();
     $_POST = array();
     $_COOKIE = array();
     // reset singleton
     StaticEventManager::resetInstance();
     // Reset singleton placeholder if version < 2.2.0, no longer required in 2.2.0+
     if (Version::compareVersion('2.2.0') >= 0) {
         Placeholder\Registry::unsetRegistry();
     }
     $this->queries = 0;
     $this->time = 0;
 }


问题


面经


文章

微信
公众号

扫码关注公众号