示例#1
0
文件: Router.php 项目: epixa/Epixa
 /**
  * {@inheritdoc}
  *
  * In addition, load routes from file if a file was specified
  * 
  * @return Router
  */
 public function init()
 {
     $routes = array();
     foreach ($this->getOptions() as $key => $value) {
         if (strtolower($key) == 'file') {
             $routes = (include $value);
             break;
         }
     }
     $this->setOptions(array('routes' => $routes));
     return parent::init();
 }
示例#2
0
 /**
  * @return Zend_Controller_Router_Rewrite
  */
 public function init()
 {
     $router = parent::init();
     $front = $this->getBootstrap()->getResource('Frontcontroller');
     if ($front->getParam('api')) {
         // The API route is the only valid route for an API request.
         $router->addRoute('api', new Omeka_Controller_Router_Api());
     } else {
         $router->addConfig(new Zend_Config_Ini(CONFIG_DIR . '/routes.ini', 'routes'));
         fire_plugin_hook('define_routes', array('router' => $router));
         $this->_addHomepageRoute($router);
     }
     return $router;
 }
示例#3
0
 /**
  * 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;
 }
示例#4
0
 /**
  * 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;
 }
示例#5
0
 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());
 }
示例#6
0
 public function init()
 {
     parent::init();
 }