示例#1
0
 function rewrite($options = array())
 {
     list($params, $options) = $this->extractOptionsFromParameters($options);
     $this->rewriteParameters($params);
     $named_route = $this->extractNamedRoute($params);
     return (string) $this->Router->urlize($params, $named_route)->setOptions(array_merge($this->values_from_request, $options));
 }
示例#2
0
 public function testRouterConnectAddsLangSegmentAutomatically()
 {
     $Router = new AkRouter();
     $Router->person('/person/:name');
     $routes = $Router->getRoutes();
     $segments = $routes['person']->getSegments();
     $this->assertArrayHasKey('lang', $segments);
 }
示例#3
0
文件: router.php 项目: bermi/akelos
 /**
  * @param string $url
  * @return PHPUnit_Routing_TestCase
  */
 public function get($url)
 {
     $Request = $this->createRequest($url);
     try {
         $this->params = $this->Router->match($Request);
         if ($this->reciprocity) {
             $this->assertEqual($url, $this->Router->urlize($this->params)->path());
         }
     } catch (NoMatchingRouteException $e) {
         $this->errors = true;
     }
     return $this;
 }
示例#4
0
 /**
  * @return AkRouter
  */
 function createRouter()
 {
     $Router = new AkRouter();
     $Router->generate_helper_functions = true;
     foreach ($this->Routes as $name => $args) {
         call_user_func_array(array($Router, $name), $args);
     }
     AkRouter::$singleton = $Router;
     return $this->Router = $Router;
 }
示例#5
0
    function testInvestigateRequest()
    {
        $Request = new AkRequest();
        $Request->_request['ak'] = 'blog/show/1';
        $Request->_request['q']  = 'wer';
        
        $Router = new AkRouter();
        $Router->connect(':controller/:action/:id');
        $Request->checkForRoutedRequests($Router);

        $this->assertEquals(array(
            'controller'=>'blog',
            'action'=>'show',
            'id'=>1,
            'q'=>'wer',
            'ak'=>'blog/show/1'),$Request->getParameters());     # we don't need the 'ak'-key, do we?
        #var_dump($Request->getRequestUri());    # http://localhost/
        #var_dump($Request->getHost());          # localhost
        #var_dump($Request->getHostWithPort());  # localhost
        #var_dump($Request->getMethod());        # env->request_method
        #var_dump($Request->getLocaleFromUrl()); #
        #var_dump($Request->getPath());          # env->request_uri    
        #var_dump($Request->getPathParameters());# possibly orhpaned       
    }
示例#6
0
文件: base.php 项目: bermi/sintags
 /**
  * Gets a route to an URL from the rules defined at config/routes.php
  */
 static function toUrl($options, $set_routes = false)
 {
     static $Router;
     if (empty($Router)) {
         if ($set_routes) {
             $Router = $options;
             return;
         } else {
             $Router = AkRouter::getInstance();
         }
     } else {
         if ($options instanceof AkRouter && $set_routes) {
             $Router = $options;
             return;
         }
     }
     return $Router->toUrl($options);
 }
示例#7
0
 function createRouter()
 {
     $Router = new AkRouter();
     $Router->addRoute('default', new AkRoute('/:controller/:action/:id'));
     return $Router;
 }
示例#8
0
文件: Ak.php 项目: joeymetal/v1
 function toUrl($options, $set_routes = false)
 {
     static $Map;
     if(empty($Map)){
         if($set_routes){
             $Map = $options;
             return;
         }else{
             require_once(AK_LIB_DIR.DS.'AkRouter.php');
             $Map = new AkRouter();
             if(is_file(AK_ROUTES_MAPPING_FILE)){
                 include(AK_ROUTES_MAPPING_FILE);
             }
         }
     }
     return $Map->toUrl($options);
 }
示例#9
0
 private function mapResourceRoutes(AkRouter $Map, $Resource, $action, $route_path, $route_name = null, $method = null, $resource_options = array())
 {
     if ($Resource->hasAction($action)) {
         $action_options = $this->actionOptionsFor($action, $Resource, $method, $resource_options);
         $formatted_route_path = $route_path . '.:format';
         $requirements = Ak::deleteAndGetValue($action_options, array('requirements'));
         $conditions = Ak::deleteAndGetValue($action_options, array('conditions'));
         if ($route_name && !in_array($route_name, $Map->getNamedRouteNames())) {
             $Map->connectNamed($route_name, $formatted_route_path, $action_options, (array) $requirements, (array) $conditions);
         } else {
             $Map->connectNamed(null, $formatted_route_path, $action_options, (array) $requirements, (array) $conditions);
         }
     }
 }
示例#10
0
 /**
  * Asserts that the provided options can be used to generate the provided 
  * path.  This is the inverse of +assertRecognizes+.
  * The +extras+ parameter is used to tell the request the names and values of
  * additional request parameters that would be in a query string. 
  * The +message+ parameter allows you to specify a custom error message for 
  * assertion failures.
  *
  * The +defaults+ parameter is unused.
  *
  * ==== Examples
  *
  * Asserts that the default action is generated for a route with no action
  *
  *     $this->assertGenerates(
  *               '/items', 
  *               array('controller'=>'items', 'action'=>'index')
  *           );
  *
  * Tests that the list action is properly routed
  *
  *     $this->assertGenerates(
  *               '/items/list', 
  *               array('controller'=>'items', 'action'=>'list')
  *           );
  *
  *  Tests the generation of a route with a parameter
  * 
  *     $this->assertGenerates(
  *               '/items/list/1', 
  *               array('controller'=>'items', 'action'=>'list', 'id'=>'1')
  *           );
  *
  * Asserts that the generated route gives us our custom route
  * 
  *     $this->assertGenerates(
  *               'changesets/12', 
  *               array(
  *                   'controller'=>'scm', 'action'=>'show_diff', 
  *                   'revision' => 12)
  *           );
  */
 public function assertGenerates($expected_path, $options = array(), $defaults = array(), $extras = array(), $message = null)
 {
     $options = array_merge($options, $defaults);
     if (@$expected_path[0] != '/') {
         $expected_path = '/' . $expected_path;
     }
     $this->Router = empty($this->Router) ? AkRouter::getInstance() : $this->Router;
     $generated_path = (string) $this->Router->urlize($options);
     if (!empty($extras)) {
         $parsed = parse_url($generated_path);
         if (!empty($parsed['query'])) {
             $vars = array();
             parse_str($parsed['query'], $vars);
             krsort($vars);
             krsort($extras);
             $this->_UnitTester->assertEqual($vars, $extras, 'Extra parameters ' . json_encode($extras) . ' do not match ' . json_encode($vars) . ' found in path ' . $expected_path);
             $generated_path = str_replace('?' . $parsed['query'], '', $generated_path);
         } else {
             $this->_UnitTester->fail('Extra parameters ' . json_encode($extras) . ' not found in path ' . $expected_path);
         }
     }
     $this->_UnitTester->assertEqual($expected_path, $generated_path);
 }
示例#11
0
 public function test_should_assert_recognizes()
 {
     $Router = new AkRouter();
     $Router->connect('/about', array('controller' => 'pages', 'action' => 'about'));
     $Router->resources('photos');
     $this->nextAssertionUsingRouter($Router);
     $this->assertRecognizes(array('controller' => 'photos', 'action' => 'show', 'id' => 1), "/photos/1");
     $this->assertRecognizes(array('controller' => 'pages', 'action' => 'about'), "/about");
 }
示例#12
0
文件: request.php 项目: bermi/akelos
 public function mapRoutes($Router = null)
 {
     if (empty($Router)) {
         $Router = AkRouter::getInstance();
     }
     try {
         $this->checkForRoutedRequests($Router);
     } catch (Exception $e) {
         if (AK_TEST_MODE) {
             throw $e;
         } else {
             $ExceptionDispatcher = new AkExceptionDispatcher();
             $ExceptionDispatcher->renderException($e);
             return false;
         }
     }
     return true;
 }
示例#13
0
文件: base.php 项目: bermi/akelos
 /**
  * @return AkRouter
  */
 static function getInstance()
 {
     if (!($Router = Ak::getStaticVar('AkRouterSingleton'))) {
         $Router = new AkRouter();
         $Router->loadMap();
         Ak::setStaticVar('AkRouterSingleton', $Router);
     }
     return $Router;
 }
示例#14
0
 function _mapRoutes($Map = null)
 {
     require_once AK_LIB_DIR . DS . 'AkRouter.php';
     if (is_file(AK_ROUTES_MAPPING_FILE)) {
         if (empty($Map)) {
             $Map = AkRouter::getInstance();
         }
         #$Map->loadMap();
         $this->checkForRoutedRequests($Map);
     }
 }
示例#15
0
文件: AkRouter.php 项目: joeymetal/v1
 /**
  * @return AkRouter
  */
 static function getInstance()
 {
     if (!self::$singleton) {
         $Map = self::$singleton = new AkRouter();
         $Map->loadMap();
     }
     return self::$singleton;
 }
示例#16
0
 /**
  * @param string $url
  * @return AkRouterSpec
  */
 function get($url)
 {
     $this->params = $this->Router->toParams($url);
     return $this;
 }