本文整理汇总了PHP中Zend\ModuleManager\ModuleEvent类的典型用法代码示例。如果您正苦于以下问题:PHP ModuleEvent类的具体用法?PHP ModuleEvent怎么用?PHP ModuleEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ModuleEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onConfigMerge
/**
*
* @param \Zend\EventManager\Event $event
*/
public function onConfigMerge(ModuleEvent $event)
{
$config = $event->getConfigListener()->getMergedConfig(false);
foreach ($config['sds']['doctrineExtensions']['manifest'] as $name => $manifestConfig) {
if (!isset($manifestConfig['initalized']) || !$manifestConfig['initalized']) {
$manifest = new Manifest($manifestConfig);
$manifestConfig = $manifest->toArray();
$config['sds']['doctrineExtensions']['manifest'][$name] = $manifestConfig;
//alias documentManager
//add delegators
$documentManagerConfig = $config;
foreach (explode('.', $manifestConfig['document_manager']) as $key) {
$documentManagerConfig = $documentManagerConfig[$key];
}
$delegatorConfig = ['delegators' => [$manifestConfig['document_manager'] => ['doctrineExtensions.' . $name . '.documentManagerDelegatorFactory'], $documentManagerConfig['eventmanager'] => ['doctrineExtensions.' . $name . '.eventManagerDelegatorFactory'], $documentManagerConfig['configuration'] => ['doctrineExtensions.' . $name . '.configurationDelegatorFactory']]];
$config['service_manager'] = ArrayUtils::merge($config['service_manager'], $delegatorConfig);
}
}
if (!isset($config['sds']['doctrineExtensions']['manifest']['default']) || !isset($config['sds']['doctrineExtensions']['manifest']['default']['extension_configs']['extension.dojo'])) {
//remove dojo_src.default route if doctrineExtensions.dojo.default is not configured
unset($config['router']['routes']['dojo.default']);
}
if (!isset($config['sds']['doctrineExtensions']['manifest']['default']) || !isset($config['sds']['doctrineExtensions']['manifest']['default']['extension_configs']['extension.rest'])) {
//remove rest.default route if doctrineExtensions.rest.default is not configured
unset($config['router']['routes']['rest.default']);
}
$event->getConfigListener()->setMergedConfig($config);
}
示例2: onMergeConfig
/**
* @param ModuleEvent $event
* @throws Exception
*/
public function onMergeConfig(ModuleEvent $event)
{
// do not parse annotations if config cache is enabled.
$config = $event->getConfigListener()->getMergedConfig(false);
$annotationReader = AnnotationReaderFactory::factory($config['zf_annotation']);
$parser = ClassParserFactory::factory($config, $event->getTarget()->getEventManager(), $annotationReader);
$scanner = new DirectoryScanner();
$classesToParse = [];
$modules = $event->getTarget()->getLoadedModules();
$modulesAllowedToScan = $config['zf_annotation']['scan_modules'];
foreach ($modules as $module) {
$parts = explode('\\', get_class($module));
$modName = array_shift($parts);
if (!empty($modulesAllowedToScan) && !in_array($modName, $modulesAllowedToScan)) {
continue;
}
$ref = new ReflectionClass($module);
$dir = dirname($ref->getFileName());
foreach ($scanner->scan($dir) as $class) {
$classesToParse[] = $class;
}
}
$parsedConfig = $parser->parse($classesToParse);
$event->getConfigListener()->setMergedConfig(array_replace_recursive($parsedConfig, $config));
}
示例3: 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
* @return ModuleManager
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
if (!$serviceLocator->has('ServiceListener')) {
$serviceLocator->setFactory('ServiceListener', 'HumusMvc\\Service\\ServiceListenerFactory');
}
if (!$serviceLocator->has('Zf1MvcListener')) {
$serviceLocator->setFactory('Zf1MvcListener', 'HumusMvc\\Service\\Zf1MvcListenerFactory');
}
$configuration = $serviceLocator->get('ApplicationConfig');
$listenerOptions = new ListenerOptions($configuration['module_listener_options']);
$defaultListeners = new DefaultListenerAggregate($listenerOptions);
$serviceListener = $serviceLocator->get('ServiceListener');
$serviceListener->addServiceManager($serviceLocator, 'service_manager', 'Zend\\ModuleManager\\Feature\\ServiceProviderInterface', 'getServiceConfig');
$serviceListener->addServiceManager('ViewHelperManager', 'view_helpers', 'Zend\\ModuleManager\\Feature\\ViewHelperProviderInterface', 'getViewHelperConfig');
$serviceListener->addServiceManager('ActionHelperManager', 'action_helpers', 'HumusMvc\\ModuleManager\\Feature\\ActionHelperProviderInterface', 'getActionHelperConfig');
$events = $serviceLocator->get('EventManager');
$events->attach($defaultListeners);
$events->attach($serviceListener);
$sharedEvents = $events->getSharedManager();
$sharedEvents->attach('HumusMvc\\Application', 'bootstrap', new LocaleListener());
$moduleEvent = new ModuleEvent();
$moduleEvent->setParam('ServiceManager', $serviceLocator);
$moduleManager = new ModuleManager($configuration['modules'], $events);
$moduleManager->setEvent($moduleEvent);
return $moduleManager;
}
示例4: extendRoutes
/**
* @param ModuleEvent $e
* @throws InvalidArgumentException
*/
public function extendRoutes(ModuleEvent $e)
{
$configListener = $e->getConfigListener();
$config = $configListener->getMergedConfig(false);
// Allow extension of routes with overriding capability
if (isset($config['router']['inheritance']) && is_array($config['router']['inheritance'])) {
foreach ($config['router']['inheritance'] as $newRoute => $routeConfig) {
// Not going to override any existing routes
if (isset($config['router']['routes'][$newRoute])) {
throw new InvalidArgumentException('Cannot extend route to existing route id.');
}
// parent route must be provided
if (!isset($routeConfig['extends'])) {
throw new InvalidArgumentException('Parent route must be defined.');
}
// parent route must exist
if (!isset($config['router']['routes'][$routeConfig['extends']])) {
throw new InvalidArgumentException('Parent route does not exist.');
}
// If there is any configuration provided, it must be iterable
if (isset($routeConfig['configuration']) && !is_array($routeConfig['configuration'])) {
throw new InvalidArgumentException('Route overrides must be iterable.');
}
// Copying the parent config and merging in the overrides
$newRouteConfig = $config['router']['routes'][$routeConfig['extends']];
$newRouteConfig = ArrayUtils::merge($newRouteConfig, $routeConfig['configuration']);
$config['router']['routes'][$newRoute] = $newRouteConfig;
}
// Removing this node so this isn't re-executed
unset($config['router']['inheritance']);
}
// Pass the changed configuration back to the listener:
$configListener->setMergedConfig($config);
}
示例5: onMergeConfig
public function onMergeConfig(ModuleEvent $e)
{
$configListener = $e->getConfigListener();
$config = $configListener->getMergedConfig(false);
// Modify the configuration; here, we'll add Oracle Custom DQL Functions:
if (isset($config['doctrine_extensions']['oracle_doctrine_driver_config_key'])) {
$configKey = $config['doctrine_extensions']['oracle_doctrine_driver_config_key'];
//Get existing map (if any) to be merged with the module map
if (isset($config['doctrine']['configuration'][$configKey])) {
$existingMap = $config['doctrine']['configuration'][$configKey];
} else {
$existingMap = array();
}
$config['doctrine']['configuration'][$configKey] = array_merge_recursive($existingMap, DoctrineExtensionsUtilts::getOracleDQLFunctions());
}
// Modify the configuration; here, we'll add MySQL Custom DQL Functions:
if (isset($config['doctrine_extensions']['mysql_doctrine_driver_config_key'])) {
$configKey = $config['doctrine_extensions']['mysql_doctrine_driver_config_key'];
//Get existing map (if any) to be merged with the module map
if (isset($config['doctrine']['configuration'][$configKey])) {
$existingMap = $config['doctrine']['configuration'][$configKey];
} else {
$existingMap = array();
}
$config['doctrine']['configuration'][$configKey] = array_merge_recursive($existingMap, DoctrineExtensionsUtilts::getMysqlDQLFunctions());
}
// Pass the changed configuration back to the listener:
$configListener->setMergedConfig($config);
}
示例6: 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
* @return ModuleManager
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
if (!$serviceLocator->has('ServiceListener')) {
$serviceLocator->setFactory('ServiceListener', 'Zend\\Mvc\\Service\\ServiceListenerFactory');
}
$configuration = $serviceLocator->get('ApplicationConfig');
$listenerOptions = new ListenerOptions($configuration['module_listener_options']);
$defaultListeners = new DefaultListenerAggregate($listenerOptions);
$serviceListener = $serviceLocator->get('ServiceListener');
$serviceListener->addServiceManager($serviceLocator, 'service_manager', 'Zend\\ModuleManager\\Feature\\ServiceProviderInterface', 'getServiceConfig');
$serviceListener->addServiceManager('ControllerLoader', 'controllers', 'Zend\\ModuleManager\\Feature\\ControllerProviderInterface', 'getControllerConfig');
$serviceListener->addServiceManager('ControllerPluginManager', 'controller_plugins', 'Zend\\ModuleManager\\Feature\\ControllerPluginProviderInterface', 'getControllerPluginConfig');
$serviceListener->addServiceManager('ViewHelperManager', 'view_helpers', 'Zend\\ModuleManager\\Feature\\ViewHelperProviderInterface', 'getViewHelperConfig');
$serviceListener->addServiceManager('ValidatorManager', 'validators', 'Zend\\ModuleManager\\Feature\\ValidatorProviderInterface', 'getValidatorConfig');
$serviceListener->addServiceManager('FilterManager', 'filters', 'Zend\\ModuleManager\\Feature\\FilterProviderInterface', 'getFilterConfig');
$serviceListener->addServiceManager('FormElementManager', 'form_elements', 'Zend\\ModuleManager\\Feature\\FormElementProviderInterface', 'getFormElementConfig');
$serviceListener->addServiceManager('RoutePluginManager', 'route_manager', 'Zend\\ModuleManager\\Feature\\RouteProviderInterface', 'getRouteConfig');
$serviceListener->addServiceManager('SerializerAdapterManager', 'serializers', 'Zend\\ModuleManager\\Feature\\SerializerProviderInterface', 'getSerializerConfig');
$serviceListener->addServiceManager('HydratorManager', 'hydrators', 'Zend\\ModuleManager\\Feature\\HydratorProviderInterface', 'getHydratorConfig');
$serviceListener->addServiceManager('InputFilterManager', 'input_filters', 'Zend\\ModuleManager\\Feature\\InputFilterProviderInterface', 'getInputFilterConfig');
$serviceListener->addServiceManager('LogProcessorManager', 'log_processors', 'Zend\\ModuleManager\\Feature\\LogProcessorProviderInterface', 'getLogProcessorConfig');
$serviceListener->addServiceManager('LogWriterManager', 'log_writers', 'Zend\\ModuleManager\\Feature\\LogWritersProviderInterface', 'getLogWriterConfig');
$events = $serviceLocator->get('EventManager');
$events->attach($defaultListeners);
$events->attach($serviceListener);
$moduleEvent = new ModuleEvent();
$moduleEvent->setParam('ServiceManager', $serviceLocator);
$moduleManager = new ModuleManager($configuration['modules'], $events);
$moduleManager->setEvent($moduleEvent);
return $moduleManager;
}
示例7: 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
* @return ModuleManager
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
if (!$serviceLocator->has('ServiceListener')) {
$serviceLocator->setFactory('ServiceListener', 'Console\\Service\\ServiceListenerFactory');
}
$configuration = $serviceLocator->get('ApplicationConfig');
$listenerOptions = new ListenerOptions($configuration['module_listener_options']);
$defaultListeners = new DefaultListenerAggregate($listenerOptions);
$serviceListener = $serviceLocator->get('ServiceListener');
$serviceListener->addServiceManager($serviceLocator, 'service_manager', 'Zend\\ModuleManager\\Feature\\ServiceProviderInterface', 'getServiceConfig');
$serviceListener->addServiceManager('ValidatorManager', 'validators', 'Zend\\ModuleManager\\Feature\\ValidatorProviderInterface', 'getValidatorConfig');
$serviceListener->addServiceManager('FilterManager', 'filters', 'Zend\\ModuleManager\\Feature\\FilterProviderInterface', 'getFilterConfig');
$serviceListener->addServiceManager('SerializerAdapterManager', 'serializers', 'Zend\\ModuleManager\\Feature\\SerializerProviderInterface', 'getSerializerConfig');
$serviceListener->addServiceManager('SerializerAdapterManager', 'serializers', 'Zend\\ModuleManager\\Feature\\SerializerProviderInterface', 'getSerializerConfig');
$serviceListener->addServiceManager('HydratorManager', 'hydrators', 'Zend\\ModuleManager\\Feature\\HydratorProviderInterface', 'getHydratorConfig');
$serviceListener->addServiceManager('InputFilterManager', 'input_filters', 'Zend\\ModuleManager\\Feature\\InputFilterProviderInterface', 'getInputFilterConfig');
$events = $serviceLocator->get('EventManager');
$events->attach($defaultListeners);
$events->attach($serviceListener);
$moduleEvent = new ModuleEvent();
$moduleEvent->setParam('ServiceManager', $serviceLocator);
$moduleManager = new ModuleManager($configuration['modules'], $events);
$moduleManager->setEvent($moduleEvent);
return $moduleManager;
}
示例8: onLoadModule
/**
* loadModule
*
* Check each loaded module to see if it implements LocatorRegistered. If it
* does, we add it to an internal array for later.
*
* @param ModuleEvent $e
* @return void
*/
public function onLoadModule(ModuleEvent $e)
{
if (!$e->getModule() instanceof LocatorRegisteredInterface) {
return;
}
$this->modules[] = $e->getModule();
}
示例9: onMergeConfig
public function onMergeConfig(\Zend\ModuleManager\ModuleEvent $event)
{
$configListener = $event->getConfigListener();
$config = $configListener->getMergedConfig(false);
// echo '<pe>';
// print_r($config);
// echo '</pre>';
}
示例10: __invoke
/**
* @param ModuleEvent $e
* @eturn void
*/
public function __invoke(ModuleEvent $e)
{
$module = $e->getModule();
if (!$module instanceof InitProviderInterface && !method_exists($module, 'init')) {
return;
}
$module->init($e->getTarget());
}
示例11: onMergeConfig
public function onMergeConfig(ModuleEvent $moduleEvent)
{
$configListener = $moduleEvent->getConfigListener();
$config = $configListener->getMergedConfig(false);
// echo "<pre style='font-weight:bold'>";
// print_r($config['controllers']);
// echo "</pre>";
}
示例12: onLoadModulesPost
/**
* Called when the modules are loaded.
*
* @param ModuleEvent $event
*/
public function onLoadModulesPost(ModuleEvent $event)
{
/** @var ServiceManager $serviceManager */
$serviceManager = $event->getParam('ServiceManager');
/** @var EngineInterface $engine */
$engine = $serviceManager->get('phpab.engine');
$engine->start();
}
示例13: __invoke
/**
* @param ModuleEvent $e
* @return void
*/
public function __invoke(ModuleEvent $e)
{
$module = $e->getModule();
if (!$module instanceof AutoloaderProviderInterface && !method_exists($module, 'getAutoloaderConfig')) {
return;
}
$autoloaderConfig = $module->getAutoloaderConfig();
AutoloaderFactory::factory($autoloaderConfig);
}
示例14: __invoke
/**
* @param ModuleEvent $e
* @return object|false False if module class does not exist
*/
public function __invoke(ModuleEvent $e)
{
$moduleName = $e->getModuleName();
$class = $moduleName . '\\Module';
if (!class_exists($class)) {
return false;
}
return new $class();
}
示例15: testModuleResolverListenerCanResolveModuleClasses
public function testModuleResolverListenerCanResolveModuleClasses()
{
$moduleResolver = new ModuleResolverListener();
$e = new ModuleEvent();
$e->setModuleName('ListenerTestModule');
$this->assertInstanceOf('ListenerTestModule\\Module', $moduleResolver($e));
$e->setModuleName('DoesNotExist');
$this->assertFalse($moduleResolver($e));
}