public function init(ModuleManager $moduleManager) { $events = $moduleManager->events()->getSharedManager(); $instance = $this; //TODO this will no be needed in PHP 5.4 $events->attach('bootstrap', 'bootstrap', function ($e) use($instance, $moduleManager) { $app = $e->getParam('application'); $instance->setJoinedConfig($e->getParam('config')); $instance->bootstrap($moduleManager, $app); }); }
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); }
public function testDefaultListenerAggregateCanDetachItself() { $listenerAggregate = new DefaultListenerAggregate; $moduleManager = new ModuleManager(array('ListenerTestModule')); $listenerAggregate->attach($moduleManager->events()); $this->assertEquals(4, count($moduleManager->events()->getEvents())); $listenerAggregate->detach($moduleManager->events()); $this->assertEquals(0, count($moduleManager->events()->getEvents())); }
public function testModuleLoadingBehavior() { $moduleManager = new ModuleManager(array('BarModule')); $moduleManager->events()->attachAggregate($this->defaultListeners); $modules = $moduleManager->getLoadedModules(); $this->assertSame(0, count($modules)); $modules = $moduleManager->getLoadedModules(true); $this->assertSame(1, count($modules)); $moduleManager->loadModules(); // should not cause any problems $moduleManager->loadModule('BarModule'); // should not cause any problems $modules = $moduleManager->getLoadedModules(true); // BarModule already loaded so nothing happens $this->assertSame(1, count($modules)); }