Example #1
0
 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()));
 }
Example #3
0
 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'));
 }
Example #5
0
 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);
 }
Example #6
0
 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);
 }
Example #7
0
 public function init(Manager $moduleManager)
 {
     $this->initAutoloader($moduleManager->getOptions()->getApplicationEnv());
 }
Example #8
0
 /**
  * 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();
 }
Example #9
0
 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']);
 }
Example #10
0
 /**
  * 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);
 }
Example #11
0
 public function init(Manager $moduleManager)
 {
     $moduleManager->events()->attach('loadModules.post', array($this, 'modulesLoaded'));
 }
Example #12
0
 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();
 }
Example #13
0
 /**
  * @param Manager $moduleManager
  */
 public function init(Manager $moduleManager)
 {
     $moduleManager->events()->attach('loadModules.post', array($this, 'registerAnnotations'));
 }
Example #14
0
    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);
    }
Example #15
0
 public function init(Manager $moduleManager)
 {
     $events = $moduleManager->events();
     $sharedEvents = $events->getSharedManager();
     $sharedEvents->attach('bootstrap', 'bootstrap', array($this, 'initializeView'), 100);
 }
Example #16
0
 public function testNotFoundModuleThrowsRuntimeException()
 {
     $this->setExpectedException('RuntimeException');
     $moduleManager = new Manager(array('NotFoundModule'));
     $moduleManager->loadModules();
 }
Example #17
0
 public function init(Manager $moduleManager)
 {
     $moduleManager->events()->attach('loadModules.post', array($this, 'modulesLoaded'));
     $events = StaticEventManager::getInstance();
     $events->attach('bootstrap', 'bootstrap', array($this, 'attachDoctrineEvents'), 100);
 }
Example #18
0
 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);
 }