Example #1
0
 /**
  * Creates a new route. Sets the URI and regular expressions for keys.
  * Routes should always be created with [Route::set] or they will not
  * be properly stored.
  *
  *     $route = new Route($uri, $regex);
  *
  * The $uri parameter should be a string for basic regex matching.
  *
  *
  * @param   string  $uri    route URI pattern
  * @param   array   $regex  key patterns
  * @return  void
  * @uses    Route::_compile
  */
 public function __construct($uri = NULL, $regex = NULL)
 {
     if ($uri === NULL) {
         // Assume the route is from cache
         return;
     }
     if (!empty($uri)) {
         $this->_uri = $uri;
     }
     if (!empty($regex)) {
         $this->_regex = $regex;
     }
     // Store the compiled regex locally
     $this->_route_regex = Route::compile($uri, $regex);
 }
 /**
  * Tests Route::compile()
  *
  * Makes sure that compile will use custom regex if specified
  *
  * @test
  * @covers Route::compile
  */
 public function test_compile_uses_custom_regex_if_specificed()
 {
     $compiled = Route::compile('<controller>(/<action>(/<id>))', array('controller' => '[a-z]+', 'id' => '\\d+'));
     $this->assertSame('#^(?P<controller>[a-z]+)(?:/(?P<action>[^/.,;?\\n]++)(?:/(?P<id>\\d+))?)?$#uD', $compiled);
 }
Example #3
0
 /**
  * Sets what parameters and text values of a route are translated
  *
  * @param   array  $translate     parameters and values to translate
  * @return  $this or array
  * @uses    Lang::$i18n_routes
  * @uses    Lang::find_current()
  * @uses    Route::compile
  */
 public function translate(array $translate = NULL)
 {
     if (!Lang::$i18n_routes or $translate === NULL) {
         // Nothing to translate
         return $this->_translate;
     }
     // Set translate
     $this->_translate = $translate ? $translate : array();
     // Translate the URI to the current language
     $this->translate_route(Lang::find_current());
     if ($this->_uri_source !== $this->_uri or $this->_regex_source !== $this->_regex) {
         // URI and / or regex was translated, update route_regex
         $this->_route_regex = Route::compile($this->_uri, $this->_regex);
     }
     return $this;
 }
Example #4
0
 public function __construct($uri = NULL, $regex = NULL)
 {
     if ($uri === NULL) {
         return;
     }
     if (!empty($uri)) {
         $this->_uri = $uri;
     }
     if (!empty($regex)) {
         $this->_regex = $regex;
     }
     $this->_route_regex = Route::compile($uri, $regex);
 }
Example #5
0
 /**
  * Creates a new route. Sets the URI and regular expressions for keys.
  * Routes should always be created with [Route::set] or they will not
  * be properly stored.
  *
  *     $route = new Route($uri, $regex);
  *
  * The $uri parameter can either be a string for basic regex matching or it
  * can be a valid callback or anonymous function (php 5.3+). If you use a
  * callback or anonymous function, your method should return an array
  * containing the proper keys for the route. If you want the route to be
  * "reversable", you need pass the route string as the third parameter.
  *
  *     $route = new Route(function($uri)
  *     {
  *     	if (list($controller, $action, $param) = explode('/', $uri) AND $controller == 'foo' AND $action == 'bar')
  *     	{
  *     		return array(
  *     			'controller' => 'foobar',
  *     			'action' => $action,
  *     			'id' => $param,
  *     		);
  *     	},
  *     	'foo/bar/<id>'
  *     });
  *
  * @param   mixed   $uri    route URI pattern or lambda/callback function
  * @param   array   $regex  key patterns
  * @return  void
  * @uses    Route::_compile
  */
 public function __construct($uri = NULL, $regex = NULL, $name = NULL)
 {
     if ($uri === NULL) {
         // Assume the route is from cache
         return;
     }
     if (!is_string($uri) and is_callable($uri)) {
         $this->_callback = $uri;
         $this->_uri = $regex;
         $regex = NULL;
     } elseif (!empty($uri)) {
         $this->_uri = $uri;
     }
     if (!empty($regex)) {
         $this->_regex = $regex;
     }
     if (!empty($name)) {
         $this->route_name = $name;
     }
     // Store the compiled regex locally
     $this->_route_regex = Route::compile($uri, $regex);
 }