本文整理匯總了PHP中Zend\ModuleManager\ModuleManager::getEventManager方法的典型用法代碼示例。如果您正苦於以下問題:PHP ModuleManager::getEventManager方法的具體用法?PHP ModuleManager::getEventManager怎麽用?PHP ModuleManager::getEventManager使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\ModuleManager\ModuleManager
的用法示例。
在下文中一共展示了ModuleManager::getEventManager方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: createService
/**
* Creates and returns the module manager
*
* Instantiates the default module listeners, providing them configuration
* from the "module_listener_options" key of the ApplicationConfig
* service. Also sets the default config glob path.
*
* Module manager is instantiated and provided with an EventManager, to which
* the default listener aggregate is attached. The ModuleEvent is also created
* and attached to the module manager.
*
* @param ServiceLocatorInterface $serviceLocator Service Manager
*
* @return ModuleManager
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$moduleCollection = new ModuleCollection();
$modules = $moduleCollection->getModules();
$array = array();
$autoloader = AutoloaderFactory::getRegisteredAutoloader(AutoloaderFactory::STANDARD_AUTOLOADER);
foreach ($modules as $module) {
$array[] = $module->getName();
$path = GC_APPLICATION_PATH . '/library/Modules/' . $module->getName();
if (file_exists($path) === false) {
$path = GC_APPLICATION_PATH . '/extensions/Modules/' . $module->getName();
}
$autoloader->registerNamespace($module->getName(), $path);
}
$autoloader->register();
$application = $serviceLocator->get('Application');
$configuration = $serviceLocator->get('ApplicationConfig');
$configuration['module_listener_options']['module_paths'] = array('./library/Modules', './extensions/Modules');
$listenerOptions = new Listener\ListenerOptions($configuration['module_listener_options']);
$defaultListeners = new Listener\DefaultListenerAggregate($listenerOptions);
$serviceListener = new Listener\ServiceListener($serviceLocator);
$this->prepareServices($serviceListener, $serviceLocator);
$moduleManager = new ModuleManager($array, $application->getEventManager());
$moduleManager->getEventManager()->attachAggregate($defaultListeners);
$moduleManager->getEventManager()->attachAggregate($serviceListener);
$moduleManager->loadModules();
$config = $moduleManager->getEvent()->getConfigListener()->getMergedConfig(false);
$this->prepareConfig($serviceLocator, $config);
foreach ($moduleManager->getLoadedModules() as $module) {
if (method_exists($module, 'onBootstrap')) {
$module->onBootstrap($application->getMvcEvent());
}
}
return $moduleManager;
}
示例2: init
public function init(ModuleManager $moduleManager)
{
$moduleManager->getEventManager()->attach(ModuleEvent::EVENT_LOAD_MODULES_POST, array($this, 'setOptions'), 1010);
$moduleManager->getEventManager()->attach(ModuleEvent::EVENT_LOAD_MODULES_POST, array($this, 'addLocaleToRoutes'), 1000);
// a little hacky but it avoid rewriting of many codes
$moduleManager->getEventManager()->attach(ModuleEvent::EVENT_LOAD_MODULES_POST, array($this, 'overrideViewHelperUrl'));
}
示例3: testDefaultListenerAggregateCanDetachItself
public function testDefaultListenerAggregateCanDetachItself()
{
$listenerAggregate = new DefaultListenerAggregate();
$moduleManager = new ModuleManager(array('ListenerTestModule'));
$this->assertEquals(1, count($moduleManager->getEventManager()->getEvents()));
$listenerAggregate->attach($moduleManager->getEventManager());
$this->assertEquals(3, count($moduleManager->getEventManager()->getEvents()));
$listenerAggregate->detach($moduleManager->getEventManager());
$this->assertEquals(1, count($moduleManager->getEventManager()->getEvents()));
}
示例4: init
/**
* @param ModuleManager
* @return [type]
*/
public function init(ModuleManager $moduleManager)
{
$events = $moduleManager->getEventManager();
$sharedEvents = $events->getSharedManager();
$sharedEvents->attach(__NAMESPACE__, 'dispatch', function ($e) {
$controller = $e->getTarget();
$controller->layout('layout/layoutFront');
}, 100);
$sharedEvents = $moduleManager->getEventManager()->getSharedManager();
$sharedEvents->attach('ZfcUser', 'dispatch', function ($e) {
// This event will only be fired when an ActionController under the ZfcUser namespace is dispatched.
$controller = $e->getTarget();
$controller->layout('layout/layoutFront');
}, 100);
}
示例5: init
/**
* Llamo a este método cuando se llama al módulo
* @param \Zend\ModuleManager\ModuleManager $moduleManager
*/
public function init(ModuleManager $moduleManager)
{
$sharedEvents = $moduleManager->getEventManager()->getSharedManager();
$sharedEvents->attach(__NAMESPACE__, 'dispatch', function ($e) {
$controller = $e->getTarget();
}, 100);
}
示例6: init
/**
* Wird bei der Initialisierung des Moduls aufgerufen
* @param \Zend\ModuleManager\ModuleManager $moduleManager
*/
public function init(\Zend\ModuleManager\ModuleManager $moduleManager)
{
$sharedManager = $moduleManager->getEventManager()->getSharedManager();
$sharedManager->attach('DragonJsonServer\\Service\\Clientmessages', 'Clientmessages', function (\DragonJsonServer\Event\Clientmessages $eventClientmessages) {
$serviceManager = $this->getServiceManager();
$serviceAllianceavatar = $serviceManager->get('\\DragonJsonServerAlliance\\Service\\Allianceavatar');
$allianceavatar = $serviceAllianceavatar->getAllianceavatar();
if (!isset($allianceavatar)) {
$avatar = $serviceManager->get('\\DragonJsonServerAvatar\\Service\\Avatar')->getAvatar();
if (!isset($avatar)) {
return;
}
$allianceavatar = $serviceAllianceavatar->getAllianceavatarByAvatar($avatar, false);
if (!isset($allianceavatar)) {
return;
}
}
$allianceclientmessages = $serviceManager->get('\\DragonJsonServerAllianceclientmessage\\Service\\Allianceclientmessage')->getAllianceclientmessagesByAllianceIdAndEventClientmessages($allianceavatar->getAllianceId(), $eventClientmessages);
$serviceClientmessages = $serviceManager->get('\\DragonJsonServer\\Service\\Clientmessages');
foreach ($allianceclientmessages as $allianceclientmessage) {
$serviceClientmessages->addClientmessage($allianceclientmessage->getKey(), $allianceclientmessage->getData());
}
});
$sharedManager->attach('DragonJsonServerAlliance\\Service\\Alliance', 'RemoveAlliance', function (\DragonJsonServerAlliance\Event\RemoveAlliance $eventRemoveAlliance) {
$alliance = $eventRemoveAlliance->getAlliance();
$this->getServiceManager()->get('\\DragonJsonServerAllianceclientmessage\\Service\\Allianceclientmessage')->removeAllianceclientmessagesByAllianceId($alliance->getAllianceId());
});
}
示例7: init
public function init(ModuleManager $moduleManager)
{
$sharedEvents = $moduleManager->getEventManager()->getSharedManager();
$sharedEvents->attach('Zend\\Mvc\\Controller\\AbstractActionController', MvcEvent::EVENT_DISPATCH, [$this, 'validaAuth'], 100);
//$sharedEvents->attach( 'Zend\Mvc\Controller\AbstractActionController', MvcEvent::EVENT_DISPATCH, [ $this, 'translateUsers' ], 100 );
//$sharedEvents->attach( 'Zend\Mvc\Controller\AbstractActionController', MvcEvent::EVENT_DISPATCH, [ $this, 'validateLicence' ], 100 );
}
示例8: init
/**
* @param \Zend\ModuleManager\ModuleManager $mm
*/
public function init(\Zend\ModuleManager\ModuleManager $mm)
{
$mm->getEventManager()->getSharedManager()->attach(__NAMESPACE__, 'dispatch', function ($e) {
/** @var MvcEvent $e */
$e->getTarget()->layout('layout/admin');
}, 100);
}
示例9: init
/**
* Module ini function that import the current domain files or it's alias
*
* @param ModuleManager $moduleManager
*/
public function init(ModuleManager $moduleManager)
{
$events = $moduleManager->getEventManager();
$events->attach(ModuleEvent::EVENT_MERGE_CONFIG, function (EventInterface $e) {
$configListener = $e->getConfigListener();
$config = $configListener->getMergedConfig(false);
$domain = DomainService::getDomain();
$domainDir = null;
if (!isset($config[$domain])) {
if (isset($config['losdomain']['domain_dir'])) {
$domainDir = $config['losdomain']['domain_dir'];
$domainConfig = DomainOptions::importDomain($domainDir, $domain);
$config = ArrayUtils::merge($config, $domainConfig);
$configListener->setMergedConfig($config);
}
}
if ($domainDir !== null && isset($config[$domain]) && array_key_exists('alias', $config[$domain])) {
$alias = $config[$domain]['alias'];
$aliasConfig = DomainOptions::importDomain($domainDir, $alias);
$config[$domain] = $aliasConfig[$alias];
$config = ArrayUtils::merge($config, $aliasConfig);
unset($config[$alias]);
$configListener->setMergedConfig($config);
}
});
}
示例10: init
/**
* Wird bei der Initialisierung des Moduls aufgerufen
* @param \Zend\ModuleManager\ModuleManager $moduleManager
*/
public function init(\Zend\ModuleManager\ModuleManager $moduleManager)
{
$sharedManager = $moduleManager->getEventManager()->getSharedManager();
$sharedManager->attach('DragonJsonServerApiannotation\\Module', 'Request', function (\DragonJsonServerApiannotation\Event\Request $eventRequest) {
if (!$eventRequest->getAnnotation() instanceof \DragonJsonServerAvatar\Annotation\Avatar) {
return;
}
$serviceManager = $this->getServiceManager();
$session = $serviceManager->get('\\DragonJsonServerAccount\\Service\\Session')->getSession();
if (null === $session) {
throw new \DragonJsonServer\Exception('missing session');
}
$serviceAvatar = $serviceManager->get('\\DragonJsonServerAvatar\\Service\\Avatar');
$avatar_id = $eventRequest->getRequest()->getParam('avatar_id');
$avatar = $serviceAvatar->getAvatarByAvatarIdAndSession($avatar_id, $session);
$this->getEventManager()->trigger((new \DragonJsonServerAvatar\Event\LoadAvatar())->setTarget($this)->setAvatar($avatar));
$serviceAvatar->setAvatar($avatar);
});
$sharedManager->attach('DragonJsonServerApiannotation\\Module', 'Servicemap', function (\DragonJsonServerApiannotation\Event\Servicemap $eventServicemap) {
if (!$eventServicemap->getAnnotation() instanceof \DragonJsonServerAvatar\Annotation\Avatar) {
return;
}
$eventServicemap->getService()->addParams([['type' => 'integer', 'name' => 'avatar_id', 'optional' => false]]);
});
$sharedManager->attach('DragonJsonServerAccount\\Service\\Account', 'RemoveAccount', function (\DragonJsonServerAccount\Event\RemoveAccount $eventRemoveAccount) {
$account = $eventRemoveAccount->getAccount();
$serviceAvatar = $this->getServiceManager()->get('\\DragonJsonServerAvatar\\Service\\Avatar');
$avatars = $serviceAvatar->getAvatarsByAccountId($account->getAccountId());
foreach ($avatars as $avatar) {
$serviceAvatar->removeAvatar($avatar);
}
});
}
示例11: init
/**
* Wird bei der Initialisierung des Moduls aufgerufen
* @param \Zend\ModuleManager\ModuleManager $moduleManager
*/
public function init(\Zend\ModuleManager\ModuleManager $moduleManager)
{
$sharedManager = $moduleManager->getEventManager()->getSharedManager();
$sharedManager->attach('DragonJsonServer\\Service\\Server', 'Response', function (\DragonJsonServer\Event\Response $eventResponse) {
$this->getServiceManager()->get('\\DragonJsonServerRequestlog\\Service\\Requestlog')->createRequestlog($eventResponse->getRequest(), $eventResponse->getResponse());
});
}
示例12: init
/**
* Wird bei der Initialisierung des Moduls aufgerufen
* @param \Zend\ModuleManager\ModuleManager $moduleManager
*/
public function init(\Zend\ModuleManager\ModuleManager $moduleManager)
{
$sharedManager = $moduleManager->getEventManager()->getSharedManager();
$sharedManager->attach('DragonJsonServer\\Service\\Server', 'Request', function (\DragonJsonServer\Event\Request $eventRequest) {
$request = $eventRequest->getRequest();
$method = $request->getMethod();
$securitytokens = $this->getServiceManager()->get('Config')['dragonjsonserversecuritytoken']['securitytokens'];
foreach ($securitytokens as $namespace => $securitytoken) {
if (substr($method, 0, strlen($namespace . '.')) != $namespace . '.') {
continue;
}
if ($request->getParam('securitytoken') != $securitytoken) {
throw new \DragonJsonServer\Exception('invalid securitytoken', ['namespace' => $namespace]);
}
}
});
$sharedManager->attach('DragonJsonServer\\Service\\Server', 'Servicemap', function (\DragonJsonServer\Event\Servicemap $eventServicemap) {
$securitytokens = $this->getServiceManager()->get('Config')['dragonjsonserversecuritytoken']['securitytokens'];
foreach ($eventServicemap->getServicemap()->getServices() as $method => $service) {
foreach ($securitytokens as $namespace => $securitytoken) {
$namespace .= '.';
if (substr($method, 0, strlen($namespace)) != $namespace) {
continue;
}
$service->addParams([['type' => 'string', 'name' => 'securitytoken', 'optional' => false]]);
}
}
});
}
示例13: init
public function init(ModuleManager $moduleManager)
{
$sharedEvents = $moduleManager->getEventManager()->getSharedManager();
// $sharedEvents->attach("Zend\Mvc\Controller\AbstractActionController",
// MvcEvent::EVENT_DISPATCH,
// array($this,'validaAuth'),100);
}
示例14: init
/**
* Wird bei der Initialisierung des Moduls aufgerufen
* @param \Zend\ModuleManager\ModuleManager $moduleManager
*/
public function init(\Zend\ModuleManager\ModuleManager $moduleManager)
{
$sharedManager = $moduleManager->getEventManager()->getSharedManager();
$sharedManager->attach('DragonJsonServer\\Service\\Clientmessages', 'Clientmessages', function (\DragonJsonServer\Event\Clientmessages $eventClientmessages) {
$serviceManager = $this->getServiceManager();
if (!$serviceManager->get('Config')['dragonjsonserveravatarmessage']['clientmessages']) {
return;
}
$avatar = $serviceManager->get('\\DragonJsonServerAvatar\\Service\\Avatar')->getAvatar();
if (null === $avatar) {
return;
}
$serviceAvatarmessage = $serviceManager->get('\\DragonJsonServerAvatarmessage\\Service\\Avatarmessage');
$avatarmessages = $serviceAvatarmessage->getAvatarmessagesByEventClientmessages($avatar, $eventClientmessages);
if (0 == count($avatarmessages)) {
return;
}
$avatarmessages = $serviceManager->get('\\DragonJsonServerDoctrine\\Service\\Doctrine')->toArray($avatarmessages);
$serviceManager->get('\\DragonJsonServer\\Service\\Clientmessages')->addClientmessage('avatarmassages', $avatarmessages);
});
$sharedManager->attach('DragonJsonServerAvatar\\Service\\Avatar', 'RemoveAvatar', function (\DragonJsonServerAvatar\Event\RemoveAvatar $eventRemoveAvatar) {
$serviceAvatarmessage = $this->getServiceManager()->get('\\DragonJsonServerAvatarmessage\\Service\\Avatarmessage');
$serviceAvatarmessage->removeAvatarmessagesByAvatarId($eventRemoveAvatar->getAvatar()->getAvatarId());
});
}
示例15: init
public function init(ModuleManager $moduleManager)
{
$eventManager = $moduleManager->getEventManager();
$sharedEventManager = $eventManager->getSharedManager();
$eventManager->attach(ModuleEvent::EVENT_MERGE_CONFIG, array($this, 'onConfigMerge'), 1);
$sharedEventManager->attach('doctrine', 'loadCli.post', array($this, 'initializeConsole'));
}