Example #1
0
 /**
  * Process the command
  *
  * @return integer
  */
 public function processCommandTask()
 {
     $modulePaths = $this->getModulePathsForProject();
     // define module list
     if ($this->params->paramModuleList && count($this->params->paramModuleList) > 0) {
         // use modules parameter
         $moduleList = $this->params->paramModuleList;
     } else {
         $moduleList = $this->loadModulesForProject($modulePaths);
     }
     // init loadable modules
     $loadableModules = [];
     // loop through module list
     foreach ($moduleList as $moduleName) {
         foreach ($modulePaths as $modulePath) {
             // check module file
             $moduleFile = $modulePath . '/' . $moduleName . '/Module.php';
             if (file_exists($moduleFile)) {
                 $loadableModules[] = $moduleName;
             }
         }
     }
     // sort by key
     sort($loadableModules);
     // configure event managers
     $sharedEvents = new SharedEventManager();
     $eventManager = new EventManager($sharedEvents);
     // configure module manager
     $moduleManager = new ModuleManager($loadableModules, $eventManager);
     // configure defaukt listeners
     $defaultListeners = new DefaultListenerAggregate(new ListenerOptions(['module_paths' => $modulePaths]));
     $defaultListeners->attach($moduleManager->getEventManager());
     // load modules
     $moduleManager->loadModules();
     // set loaded modules
     $this->params->loadedModules = $moduleManager->getLoadedModules();
     // check loaded modules
     if (!empty($this->params->loadedModules)) {
         return 0;
     }
     // output fail message
     $this->console->writeTaskLine('task_fetch_load_modules_not_found', [$this->console->colorize($this->params->workingPath, Color::GREEN)]);
     return 1;
 }
Example #2
0
 /**
  * Process the command
  *
  * @return integer
  */
 public function processCommandTask()
 {
     // define module list
     if ($this->params->paramModuleList && count($this->params->paramModuleList) > 0) {
         // use modules parameter
         $moduleList = $this->params->paramModuleList;
     } else {
         // fetch modules form path
         $moduleList = scandir($this->params->projectModuleDir);
         // clear unwanted entries
         unset($moduleList[array_search('.', $moduleList)]);
         unset($moduleList[array_search('..', $moduleList)]);
     }
     // check if Module.php file exists
     foreach ($moduleList as $moduleKey => $moduleName) {
         // check module file
         $moduleFile = $this->params->projectModuleDir . '/' . $moduleName . '/Module.php';
         if (!file_exists($moduleFile)) {
             unset($moduleList[$moduleKey]);
         }
     }
     // sort by key
     sort($moduleList);
     // configure event listeners for module manager
     $sharedEvents = new SharedEventManager();
     $defaultListeners = new DefaultListenerAggregate(new ListenerOptions(array('module_paths' => array($this->params->projectModuleDir))));
     // configure module manager
     $moduleManager = new ModuleManager($moduleList);
     $moduleManager->getEventManager()->setSharedManager($sharedEvents);
     $moduleManager->getEventManager()->attachAggregate($defaultListeners);
     $moduleManager->loadModules();
     // set loaded modules
     $this->params->loadedModules = $moduleManager->getLoadedModules();
     // check loaded modules
     if (!empty($this->params->loadedModules)) {
         return 0;
     }
     // output fail message
     $this->console->writeTaskLine('task_fetch_load_modules_not_found', array($this->console->colorize($this->params->projectPath, Color::GREEN)));
     return 1;
 }
Example #3
0
 public function testModuleIsMarkedAsLoadedWhenLoadModuleEventIsTriggered()
 {
     $test = new stdClass();
     $moduleManager = new ModuleManager(array('BarModule'));
     $events = $moduleManager->getEventManager();
     $events->attachAggregate($this->defaultListeners);
     $events->attach(ModuleEvent::EVENT_LOAD_MODULE, function ($e) use($test) {
         $test->modules = $e->getTarget()->getLoadedModules(false);
     });
     $moduleManager->loadModules();
     $this->assertTrue(isset($test->modules));
     $this->assertArrayHasKey('BarModule', $test->modules);
     $this->assertInstanceOf('BarModule\\Module', $test->modules['BarModule']);
 }
 public function testNotFoundModuleThrowsRuntimeException()
 {
     $this->setExpectedException('RuntimeException');
     $moduleManager = new ModuleManager(array('NotFoundModule'));
     $moduleManager->loadModules();
 }
Example #5
0
    public function testCanCacheMergedConfigFromStatic()
    {
        $options = new ListenerOptions(array(
            'cache_dir'            => $this->tmpdir,
            'config_cache_enabled' => true,
        ));
        $configListener = new ConfigListener($options);
        $configListener->addConfigStaticPaths(array(
                __DIR__ . '/_files/good/config.ini',
                __DIR__ . '/_files/good/config.php',
                __DIR__ . '/_files/good/config.xml')
                );

        $moduleManager = $this->moduleManager;
        $moduleManager->setModules(array('SomeModule'));

        $moduleManager->events()->attachAggregate($configListener);

        $moduleManager->loadModules();
        $configObjectFromGlob = $configListener->getMergedConfig();

        // This time, don't add the glob path
        $configListener = new ConfigListener($options);
        $moduleManager = new ModuleManager(array('SomeModule'));
        $moduleManager->events()->attach('loadModule.resolve', new ModuleResolverListener, 1000);

        $moduleManager->events()->attachAggregate($configListener);

        $moduleManager->loadModules();

        // Check if values from glob object and cache object are the same
        $configObjectFromCache = $configListener->getMergedConfig();
        $this->assertNotNull($configObjectFromGlob->ini);
        $this->assertSame($configObjectFromGlob->ini, $configObjectFromCache->ini);
        $this->assertNotNull($configObjectFromGlob->php);
        $this->assertSame($configObjectFromGlob->php, $configObjectFromCache->php);
        $this->assertNotNull($configObjectFromGlob->xml);
        $this->assertSame($configObjectFromGlob->xml, $configObjectFromCache->xml);
    }
 /**
  * Load the provided modules.
  *
  * @triggers loadModules.pre
  * @triggers loadModules.post
  * @return Manager
  */
 public function loadModules()
 {
     $this->getEventManager()->trigger(ModuleEvent::EVENT_LOAD_MODULES_AUTH, $this, $this->getEvent());
     return parent::loadModules();
 }
Example #7
0
 public function testCanNotLoadSomeObjectModuleWithoutIdentifier()
 {
     require_once __DIR__ . '/TestAsset/SomeModule/Module.php';
     $configListener = $this->defaultListeners->getConfigListener();
     $moduleManager = new ModuleManager(array(new \SomeModule\Module()), new EventManager());
     $moduleManager->getEventManager()->attachAggregate($this->defaultListeners);
     $this->setExpectedException('Zend\\ModuleManager\\Exception\\RuntimeException');
     $moduleManager->loadModules();
 }
Example #8
0
 public function testCanLoadModuleDuringTheLoadModuleEvent()
 {
     $configListener = $this->defaultListeners->getConfigListener();
     $moduleManager = new ModuleManager(array('LoadOtherModule', 'BarModule'));
     $moduleManager->getEventManager()->attachAggregate($this->defaultListeners);
     $moduleManager->loadModules();
     $config = $configListener->getMergedConfig();
     $this->assertTrue(isset($config['loaded']));
     $this->assertSame('oh, yeah baby!', $config['loaded']);
 }
require_once 'library/Zend/Loader/StandardAutoloader.php';
$loader = new Zend\Loader\StandardAutoloader(array('autoregister_zf' => true));
$loader->registerNamespace('SON', 'library/SON');
$loader->register();
/*

Evento:
- LoadModules (lista e pega todos os modulos da aplicação) foreach
   * Zend\Loader\ModuleAutoloader
*
- LoadModule
   - loadmodule.resolve (new Module();) instancia o objeto do modulo
   - loadmodule

       - getAutoloaderConfig() - possibilita ter seu proprio autoloader
       - getConfig() - merge em relacao ao seu framework
       - init(ModuleManager) - leve, somente o necessario
       - onBootstrap       - Zend\Mvc () - bootstrap event
       - LocatorRegistrationListener implementar interface Zend\ModuleManager\Feature\LocatorRegisterdInterface
       - ServiceListener (somente zend\mvc) services, controllers, plugins, view_helpers
   - loadModules.post - todos os modulos ja foram carregados, agora eu posso atachar meus listener
*/
use Zend\ModuleManager\Listener;
use Zend\ModuleManager\ModuleManager;
$listenerOptions = new Listener\ListenerOptions(array('module_paths' => array('./modules')));
$aggregateListener = new Listener\DefaultListenerAggregate($listenerOptions);
$moduleManager = new ModuleManager(array('Modulo'));
$moduleManager->getEventManager()->attachAggregate($aggregateListener);
$moduleManager->loadModules();
Example #10
0
 /**
  * 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;
 }