/** * Retrieve router object * * @return Zend_Controller_Router_Rewrite */ public function getRouter() { $routesIni = $this->_getRoutesConfig(); $this->setOptions($routesIni->toArray()); $options = $this->getOptions(); if ($this->_localeIsEnabled()) { $bootstrap = $this->getBootstrap(); if (!$this->_locale) { $bootstrap->bootstrap('Locale'); $this->_locale = $bootstrap->getContainer()->locale; } $defaultLocale = array_keys($this->_locale->getDefault()); $defaultLocale = $defaultLocale[0]; $locales = $this->_getPossibleLocales(); $routes = $options['routes']; $localizedRoutes = Garp_I18n::getLocalizedRoutes($routes, $locales); $options['routes'] = array_merge($routes, $localizedRoutes); $this->setOptions($options); } $router = parent::getRouter(); $router->addDefaultRoutes(); return $router; }
/** * Retrieves the router * * @return Zend_Controller_Router_Abstract */ public function getRouter() { if (null === $this->_router) { // Store the router in the front controller $this->_bootstrap->bootstrap('FrontController'); $front = $this->_bootstrap->getResource('FrontController'); // Don't instantiate a URL rewriter in CLI mode if (PHP_SAPI == 'cli') { $front->setRouter(new Glitch_Controller_Router_Cli()); } elseif (!($front instanceof Glitch_Controller_Front && !$front->isRouterSet())) { $front->setRouter(new Glitch_Controller_Router_Rewrite()); } $router = $front->getRouter(); // Setting options only works for URL rewriting if ($router instanceof Zend_Controller_Router_Rewrite) { // Use parent for further initialization $router = parent::getRouter(); } // Store now as property, not earlier; otherwise parent call fails! $this->_router = $router; $this->_initRestMappings(); } return $this->_router; }
public function testOptionsPassedToResourceAreUsedToCreateRoutes() { $options = array('routes' => array('archive' => array('route' => 'archive/:year/*', 'defaults' => array('controller' => 'archive', 'action' => 'show', 'year' => 2000), 'reqs' => array('year' => '\\d+')))); $resource = new Zend_Application_Resource_Router($options); $resource->setBootstrap($this->bootstrap); $resource->init(); $router = $resource->getRouter(); $this->assertTrue($router->hasRoute('archive')); $route = $router->getRoute('archive'); $this->assertTrue($route instanceof Zend_Controller_Router_Route); $this->assertEquals($options['routes']['archive']['defaults'], $route->getDefaults()); }