コード例 #1
0
 /**
  * @param \Zend\ModuleManager\ModuleEvent $e
  *
  * @throws Exception\MissingDependencyModuleException
  */
 public function __invoke(ModuleEvent $e)
 {
     $module = $e->getModule();
     if ($module instanceof DependencyIndicatorInterface || method_exists($module, 'getModuleDependencies')) {
         $dependencies = $module->getModuleDependencies();
         foreach ($dependencies as $dependencyModule) {
             if (!isset($this->loaded[$dependencyModule])) {
                 throw new Exception\MissingDependencyModuleException(sprintf('Module "%s" depends on module "%s", which was not initialized before it', $e->getModuleName(), $dependencyModule));
             }
         }
     }
     $this->loaded[$e->getModuleName()] = true;
 }
コード例 #2
0
 /**
  * @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();
 }
コード例 #3
0
 /**
  * @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)) {
         // If expected module class was not found, check for the possible class name variations:
         // - If module directory uses ZF1 naming style (spinal-case instead of CamelCase), check
         //   for Module class in Camel-Cased module name namespace
         // - If that fails, check for class name prefixed with Camel-Cased module name
         //   (no autoloading involved here)
         $moduleName = $this->formatModuleName($moduleName);
         $class = $moduleName . '\\Module';
         if (!class_exists($class)) {
             $class = $moduleName . '_Module';
             if (!class_exists($class, false)) {
                 return false;
             }
         }
     }
     $module = new $class();
     return $module;
 }
コード例 #4
0
 public function onLoadModule(ModuleEvent $e)
 {
     $module = $e->getModule();
     if (!$module instanceof DirectoryProviderInterface && !method_exists($module, 'getDir')) {
         return;
     }
     $moduleDirectory = $module->getDir();
     if (!is_dir($moduleDirectory)) {
         return;
     }
     // Store the module path
     $moduleName = $e->getModuleName();
     $this->paths[$moduleName] = array('path' => $moduleDirectory, 'template_path_stack' => null, 'default_template_path_stack' => null);
     // Check for especific module-dependant themes
     if ($module instanceof ConfigProviderInterface || is_callable(array($this, 'getConfig'))) {
         $config = $module->getConfig();
         if ($config instanceof Traversable) {
             $config = ArrayUtils::iteratorToArray($config);
         }
         if (!is_array($config)) {
             throw new Exception\InvalidArgumentException(sprintf('Config being merged must be an array, ' . 'implement the Traversable interface, or be an ' . 'instance of Zend\\Config\\Config. %s given.', gettype($config)));
         }
         if (isset($config['theme_manager'])) {
             if (is_array($config['theme_manager'])) {
                 if (isset($config['theme_manager']['template_path_stack'])) {
                     $this->paths[$moduleName]['template_path_stack'] = $config['theme_manager']['template_path_stack'];
                 }
             }
         }
         if (isset($config['view_manager'])) {
             if (is_array($config['view_manager'])) {
                 if (isset($config['view_manager']['template_path_stack'])) {
                     $this->paths[$moduleName]['default_template_path_stack'] = $config['view_manager']['template_path_stack'];
                 }
             }
         }
     }
 }
コード例 #5
0
ファイル: ConfigListener.php プロジェクト: totolouis/ZF2-Auth
 /**
  * Merge the config for each module
  *
  * @param  ModuleEvent $e
  * @return ConfigListener
  */
 public function onLoadModule(ModuleEvent $e)
 {
     $module = $e->getModule();
     if (!$module instanceof ConfigProviderInterface && !is_callable(array($module, 'getConfig'))) {
         return $this;
     }
     $config = $module->getConfig();
     $this->addConfig($e->getModuleName(), $config);
     return $this;
 }
コード例 #6
0
 /**
  * Retrieve service manager configuration from module, and
  * configure the service manager.
  *
  * If the module does not implement a specific interface and does not
  * implement a specific method, does nothing. Also, if the return value
  * of that method is not a ServiceConfig object, or not an array or
  * Traversable that can seed one, does nothing.
  *
  * The interface and method name can be set by adding a new service manager
  * via the addServiceManager() method.
  *
  * @param  ModuleEvent $e
  * @return void
  */
 public function onLoadModule(ModuleEvent $e)
 {
     $module = $e->getModule();
     foreach ($this->serviceManagers as $key => $sm) {
         if (!$module instanceof $sm['module_class_interface'] && !method_exists($module, $sm['module_class_method'])) {
             continue;
         }
         $config = $module->{$sm['module_class_method']}();
         if ($config instanceof ServiceConfigInterface) {
             $config = $this->serviceConfigToArray($config);
         }
         if ($config instanceof Traversable) {
             $config = ArrayUtils::iteratorToArray($config);
         }
         if (!is_array($config)) {
             // If we do not have an array by this point, nothing left to do.
             continue;
         }
         // We are keeping track of which modules provided which configuration to which service managers.
         // The actual merging takes place later. Doing it this way will enable us to provide more powerful
         // debugging tools for showing which modules overrode what.
         $fullname = $e->getModuleName() . '::' . $sm['module_class_method'] . '()';
         $this->serviceManagers[$key]['configuration'][$fullname] = $config;
     }
 }
コード例 #7
0
 /**
  * Event callback for 'initServicesTrigger'.
  *
  * @param ModuleEvent $e
  *
  * @return $this
  */
 public function getServicesTrigger(ModuleEvent $e)
 {
     $module = $e->getModule();
     if (is_callable(array($module, 'getServiceConfig'))) {
         $services = $module->getServiceConfig();
         if (is_array($services) && isset($services['factories'])) {
             $this->services[$e->getModuleName()] = $services['factories'];
         }
     }
     return $this;
 }