Пример #1
0
 function __construct($Request = null, AkRouter $Router = null)
 {
     if (!$Router) {
         $Router = AkRouter::getInstance();
     }
     if (!$Request) {
         $Request = AkRequest::getInstance();
     }
     $this->Request = $Request;
     $this->Router = $Router;
     $this->persistValuesFromRequest($Request);
 }
Пример #2
0
 /**
  * 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);
 }
Пример #3
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);
 }
Пример #4
0
 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;
 }
Пример #5
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);
     }
 }