X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=modules%2FApplication%2FModule.php;h=37cb11fd1f76548100e24046171b85471c428e9c;hb=bb0d0604ab23ce6ef620755f8923ede273b04267;hp=cfcc333c1234b5174ac658afdfaab490c165791f;hpb=f8a26075e9ee566a933125f76e73208fffd775a2;p=zf2.biz%2Fgalerie.git diff --git a/modules/Application/Module.php b/modules/Application/Module.php index cfcc333..37cb11f 100644 --- a/modules/Application/Module.php +++ b/modules/Application/Module.php @@ -2,46 +2,50 @@ namespace Application; -use InvalidArgumentException, - Zend\Module\Manager, - Zend\Config\Config, - Zend\Di\Locator, - Zend\EventManager\EventCollection, - Zend\EventManager\StaticEventCollection; +use Zend\Module\Manager, + Zend\EventManager\StaticEventManager, + Zend\Loader\AutoloaderFactory; class Module { - protected $appListeners = array(); - protected $staticListeners = array(); + protected $view; protected $viewListener; public function init(Manager $moduleManager) { - $this->initAutoloader($moduleManager->getOptions()->getApplicationEnv()); + $this->initAutoloader(); + $events = StaticEventManager::getInstance(); + $events->attach('bootstrap', 'bootstrap', array($this, 'initializeView'), 100); } - protected function initAutoloader($env = null) + protected function initAutoloader() { - require __DIR__ . '/autoload_register.php'; + AutoloaderFactory::factory(array( + 'Zend\Loader\ClassMapAutoloader' => array( + __DIR__ . '/autoload_classmap.php', + ), + 'Zend\Loader\StandardAutoloader' => array( + 'namespaces' => array( + __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, + ), + ), + )); } - public static function getConfig() + public function getConfig($env = null) { - return new Config(include __DIR__ . '/configs/module.config.php'); + return include __DIR__ . '/configs/module.config.php'; } - public function registerApplicationListeners(EventCollection $events, Locator $locator, Config $config) + public function initializeView($e) { - $view = $locator->get('view'); - $viewListener = $this->getViewListener($view, $config); - $events->attachAggregate($viewListener); - } - - public function registerStaticListeners(StaticEventCollection $events, Locator $locator, Config $config) - { - $view = $locator->get('view'); + $app = $e->getParam('application'); + $locator = $app->getLocator(); + $config = $e->getParam('modules')->getMergedConfig(); + $view = $this->getView($app); $viewListener = $this->getViewListener($view, $config); - + $app->events()->attachAggregate($viewListener); + $events = StaticEventManager::getInstance(); $viewListener->registerStaticListeners($events, $locator); } @@ -57,4 +61,22 @@ class Module $this->viewListener = $viewListener; return $viewListener; } + + protected function getView($app) + { + if ($this->view) { + return $this->view; + } + + $di = $app->getLocator(); + $view = $di->get('view'); + $url = $view->plugin('url'); + $url->setRouter($app->getRouter()); + + $view->plugin('headTitle')->setSeparator(' - ') + ->setAutoEscape(false) + ->append('Application'); + $this->view = $view; + return $view; + } }