public function init(Manager $moduleManager) { $this->initAutoloader($moduleManager->getOptions()->getApplicationEnv()); $events = StaticEventManager::getInstance(); $events->attach('bootstrap', 'bootstrap', array($this, 'initializeRouter'), 100); $events->attach('bootstrap', 'bootstrap', array($this, 'initializeView'), 100); }
public function testDefaultListenerAggregateCanDetachItself() { $listenerAggregate = new DefaultListenerAggregate(); $moduleManager = new Manager(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 testInitMethodCalledByInitTriggerListener() { $moduleManager = new Manager(array('ListenerTestModule')); $moduleManager->setDisableLoadDefaultListeners(true); $initListener = new InitTrigger(); $moduleManager->events()->attach('loadModule', $initListener); $moduleManager->loadModules(); $modules = $moduleManager->getLoadedModules(); $this->assertTrue($modules['ListenerTestModule']->initCalled); }
public function testAutoloadersRegisteredByAutoloaderListener() { $moduleManager = new Manager(array('ListenerTestModule')); $moduleManager->setDisableLoadDefaultListeners(true); $autoloaderListener = new AutoloaderListener(); $moduleManager->events()->attach('loadModule', $autoloaderListener); $moduleManager->loadModules(); $modules = $moduleManager->getLoadedModules(); $this->assertTrue($modules['ListenerTestModule']->getAutoloaderConfigCalled); $this->assertTrue(class_exists('Foo\\Bar')); }
public function testCanCacheMergedConfig() { $options = new ListenerOptions(array('cache_dir' => $this->tmpdir, 'config_cache_enabled' => true)); $configListener = new ConfigListener($options); $moduleManager = $this->moduleManager; $moduleManager->setModules(array('SomeModule', 'ListenerTestModule')); $moduleManager->events()->attach('loadModule', $configListener); $moduleManager->loadModules(); // This should cache the config $modules = $moduleManager->getLoadedModules(); $this->assertTrue($modules['ListenerTestModule']->getConfigCalled); // Now we check to make sure it uses the config and doesn't hit // the module objects getConfig() method(s) $moduleManager = new Manager(array('SomeModule', 'ListenerTestModule')); $moduleManager->events()->attach('loadModule.resolve', new ModuleResolverListener(), 1000); $configListener = new ConfigListener($options); $moduleManager->events()->attach('loadModule', $configListener); $moduleManager->loadModules(); $modules = $moduleManager->getLoadedModules(); $this->assertFalse($modules['ListenerTestModule']->getConfigCalled); }
public function testCanCacheMergedConfigFromGlob() { $options = new ListenerOptions(array('cache_dir' => $this->tmpdir, 'config_cache_enabled' => true)); $configListener = new ConfigListener($options); $configListener->addConfigGlobPath(__DIR__ . '/_files/good/*.{ini,php,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 Manager(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 init(Manager $moduleManager) { $this->initAutoloader($moduleManager->getOptions()->getApplicationEnv()); }
/** * Constructor * * Populates $config from the $modules "getMergedConfig" method. * * @param ModuleManager $modules * @return void */ public function __construct(ModuleManager $modules) { $this->modules = $modules; $this->config = $modules->getMergedConfig(); }
public function testCanMergeConfigFromGlob() { $moduleManager = new Manager(array('SomeModule')); $moduleManager->loadModules(); $moduleManager->getConfigListener()->mergeGlobDirectory(dirname(__DIR__) . '/_files/*.{ini,json,php,xml,yaml}'); $config = $moduleManager->getMergedConfig(false); $this->assertTrue($config['php']); }
/** * Initialize the module. * * @param Manager $moduleManager * @return void */ public function init(Manager $moduleManager) { $moduleManager->events()->attach('loadModule', array($this, 'addAssetPath')); $events = StaticEventManager::getInstance(); $events->attach('Zend\\Mvc\\Application', 'route', array($this, 'checkRequestUriForAsset'), PHP_INT_MAX); }
public function init(Manager $moduleManager) { $moduleManager->events()->attach('loadModules.post', array($this, 'modulesLoaded')); }
public function testPhpConfigFileReturningConfigWithoutExpectedApplicationEnvironmentRaisesException() { $moduleManager = new Manager(array('SomeModule')); $configListener = $moduleManager->getConfigListener(); $configListener->addConfigGlobPaths(new ArrayObject(array(__DIR__ . '/_files/bad/*.inc'))); $this->setExpectedException('Zend\\Module\\Listener\\Exception\\RuntimeException', 'environment'); $moduleManager->loadModules(); }
/** * @param Manager $moduleManager */ public function init(Manager $moduleManager) { $moduleManager->events()->attach('loadModules.post', array($this, 'registerAnnotations')); }
public function testCanCacheMerchedConfig() { $options = new ManagerOptions(array( 'cache_config' => true, 'cache_dir' => $this->tmpdir, )); // build the cache $moduleManager = new Manager(array('BarModule', 'BazModule'), $options); $config = $moduleManager->getMergedConfig(); $this->assertSame('foo', $config->bar); $this->assertSame('bar', $config->baz); // use the cache $moduleManager = new Manager(array('BarModule', 'BazModule'), $options); $config = $moduleManager->getMergedConfig(); $this->assertSame('foo', $config->bar); $this->assertSame('bar', $config->baz); }
public function init(Manager $moduleManager) { $events = $moduleManager->events(); $sharedEvents = $events->getSharedManager(); $sharedEvents->attach('bootstrap', 'bootstrap', array($this, 'initializeView'), 100); }
public function testNotFoundModuleThrowsRuntimeException() { $this->setExpectedException('RuntimeException'); $moduleManager = new Manager(array('NotFoundModule')); $moduleManager->loadModules(); }
public function init(Manager $moduleManager) { $moduleManager->events()->attach('loadModules.post', array($this, 'modulesLoaded')); $events = StaticEventManager::getInstance(); $events->attach('bootstrap', 'bootstrap', array($this, 'attachDoctrineEvents'), 100); }
public function testCanMergeConfigFromArrayOfGlobs() { $moduleManager = new Manager(array('SomeModule')); $moduleManager->getConfigListener()->addConfigGlobPaths(new \ArrayObject(array(dirname(__DIR__) . '/_files/*.ini', dirname(__DIR__) . '/_files/*.json', dirname(__DIR__) . '/_files/*.php', dirname(__DIR__) . '/_files/*.xml', dirname(__DIR__) . '/_files/*.yaml'))); $moduleManager->loadModules(); // Test as object $configObject = $moduleManager->getMergedConfig()->all; $this->assertSame('yes', $configObject->ini); $this->assertSame('yes', $configObject->php); $this->assertSame('yes', $configObject->json); $this->assertSame('yes', $configObject->xml); $this->assertTrue($configObject->yaml); }