コード例 #1
0
ファイル: Multilang.php プロジェクト: s-kalaus/zkernel
 public function routeStartup(Zend_Controller_Request_Abstract $request)
 {
     if (!$this->_issession) {
         $front = Zend_Controller_Front::getInstance();
         $router = $front->getRouter();
         if ($this->_domain) {
             $doms = $this->_model->fetchPairs('id', 'domain');
             if ($doms) {
                 foreach ($doms as $k => $el) {
                     $doms[$k] = @$el[0] ? explode(' ', $el) : array();
                 }
             }
             $lang = $request->getParam('lang');
             if ($lang) {
                 $this->_session->lang = $this->_model->fetchOne('id', array('`stitle` = ?' => $lang));
             } else {
                 if ($doms) {
                     foreach ($doms as $k => $el) {
                         if (in_array($_SERVER['HTTP_HOST'], $el)) {
                             $this->_session->lang = $k;
                             break;
                         }
                     }
                 }
             }
             $this->_lang = $this->_model->fetchRow(null, '(`id` = ' . (int) $this->_session->lang . ') DESC, (`default` = 1) DESC');
             if ($this->_lang) {
                 $this->_lang = new Zkernel_View_Data($this->_lang);
             }
             $this->_lang->_default = $this->getDefault();
             $this->_lang->_ids = $this->_model->fetchIds();
             $this->_lang->_doms = $doms;
         } else {
             $routes = $router->getRoutes();
             $router->removeDefaultRoutes();
             if ($routes) {
                 foreach ($routes as $k => $el) {
                     $router->removeRoute($k);
                 }
             }
             $langRoute = new Zend_Controller_Router_Route(':lang', array('lang' => $this->getDefault()->stitle));
             $router->addRoute('default', $langRoute->chain(new Zend_Controller_Router_Route_Module(array(), $front->getDispatcher(), $front->getRequest())));
             $router->addRoute('lang', $langRoute);
             if ($routes) {
                 foreach ($routes as $k => $el) {
                     $router->addRoute($k, $k == 'fu' || $k == 'minify' ? $el : $langRoute->chain($el));
                 }
             }
         }
     }
     $this->save();
 }
コード例 #2
0
ファイル: Router.php プロジェクト: uglide/zfcore-transition
 /**
  * Defined by Zend_Application_Resource_Resource
  *
  * @return Zend_Controller_Router_Rewrite
  */
 public function init()
 {
     if (null === $this->_router) {
         $router = $this->getRouter();
         // returns $this->_router
         $router->addConfig($this->_getConfig());
         // add locale chain if using translate
         if ($this->getBootstrap()->hasPluginResource('Translate')) {
             $locale = new Zend_Controller_Router_Route(':locale', array(), array('locale' => '^[a-z]{2}$'));
             $router->addDefaultRoutes();
             foreach ($router->getRoutes() as $name => $route) {
                 //rename existing routes
                 $router->removeRoute($name)->addRoute($name . 'Default', $route)->addRoute($name, $locale->chain($route));
             }
         }
     }
     return $this->_router;
 }
コード例 #3
0
 /**
  * @group ZF-10964
  */
 public function test_RESTfulApp_route_chaining_urlencodedWithPlusSymbol()
 {
     $request = $this->_buildRequest('GET', '/api/user/email%2Btest%40example.com');
     $this->_front->setRequest($request);
     $router = $this->_front->getRouter();
     $router->removeDefaultRoutes();
     $nonRESTRoute = new Zend_Controller_Router_Route('api');
     $RESTRoute = new Zend_Rest_Route($this->_front);
     $router->addRoute("api", $nonRESTRoute->chain($RESTRoute));
     $routedRequest = $router->route($request);
     $this->assertEquals("default", $routedRequest->getParam("module"));
     $this->assertEquals("user", $routedRequest->getParam("controller"));
     $this->assertEquals("get", $routedRequest->getParam("action"));
     $this->assertEquals("*****@*****.**", $routedRequest->getParam("id"));
 }
コード例 #4
0
 /**
  * @group ZF-7848
  */
 public function testChainingWithEmptyStaticRoutesMatchesCorrectly()
 {
     $adminRoute = new Zend_Controller_Router_Route('admin', array('module' => 'admin', 'controller' => 'index', 'action' => 'index'));
     $indexRoute = new Zend_Controller_Router_Route_Static('', array('module' => 'admin', 'controller' => 'index', 'action' => 'index'));
     $loginRoute = new Zend_Controller_Router_Route('login', array('module' => 'admin', 'controller' => 'login', 'action' => 'index'));
     $emptyRoute = $adminRoute->chain($indexRoute);
     $nonEmptyRoute = $adminRoute->chain($loginRoute);
     $request = new Zend_Controller_Request_Http();
     $request->setPathInfo('/admin');
     $values = $emptyRoute->match($request);
     $this->assertEquals(array('module' => 'admin', 'controller' => 'index', 'action' => 'index'), $values);
     $request->setPathInfo('/admin/');
     $values = $emptyRoute->match($request);
     $this->assertEquals(array('module' => 'admin', 'controller' => 'index', 'action' => 'index'), $values);
     $request->setPathInfo('/admin/login');
     $values = $nonEmptyRoute->match($request);
     $this->assertEquals(array('module' => 'admin', 'controller' => 'login', 'action' => 'index'), $values);
 }
コード例 #5
0
 public function _initRoutes()
 {
     $this->bootstrap('FrontController');
     $this->_frontController = $this->getResource('FrontController');
     $router = $this->_frontController->getRouter();
     $langRoute = new Zend_Controller_Router_Route(':lang/', array('lang' => 'en'));
     $defaultRoute = new Zend_Controller_Router_Route(':controller/:action', array('module' => 'default', 'controller' => 'index', 'action' => 'index'));
     $defaultRoute = $langRoute->chain($defaultRoute);
     $router->addRoute('langRoute', $langRoute);
     $router->addRoute('defaultRoute', $defaultRoute);
 }
コード例 #6
0
ファイル: ChainTest.php プロジェクト: hjr3/zf2
 public function testI18nChaining()
 {
     $lang = new Zend_Controller_Router_Route(':lang', array('lang' => 'en'));
     $profile = new Zend_Controller_Router_Route('user/:id', array('controller' => 'foo', 'action' => 'bar'));
     $chain = $lang->chain($profile);
     $res = $chain->match(new Zend_Controller_Router_ChainTest_Request('http://localhost/en/user/1'));
     $this->assertEquals('en', $res['lang']);
     $this->assertEquals('1', $res['id']);
 }
コード例 #7
0
 public function test_RESTfulApp_route_chaining()
 {
     $request = $this->_buildRequest('GET', '/api/user/lcrouch');
     $this->_front->setRequest($request);
     $router = $this->_front->getRouter();
     $router->removeDefaultRoutes();
     $nonRESTRoute = new \Zend_Controller_Router_Route('api');
     $RESTRoute = new REST\Route($this->_front);
     $router->addRoute("api", $nonRESTRoute->chain($RESTRoute));
     $routedRequest = $router->route($request);
     $this->assertEquals("default", $routedRequest->getParam("module"));
     $this->assertEquals("user", $routedRequest->getParam("controller"));
     $this->assertEquals("get", $routedRequest->getParam("action"));
     $this->assertEquals("lcrouch", $routedRequest->getParam("id"));
 }
コード例 #8
0
ファイル: ChainTest.php プロジェクト: lortnus/zf1
 public function testI18nChaining()
 {
     $this->markTestSkipped('Route features not ready');
     $lang = new Zend_Controller_Router_Route(':lang', array('lang' => 'en'));
     $profile = new Zend_Controller_Router_Route('user/:id', array('controller' => 'foo', 'action' => 'bar'));
     $chain = $lang->chain($profile);
     $res = $chain->match('en/user/1');
     $this->assertEquals('en', $res['lang']);
     $this->assertEquals('1', $res['id']);
 }