Example #1
0
 /**
  * Add an alias from one route to another
  * 
  * Because objects are passed by reference since
  * PHP 5, we can just add a new route key pointing
  * to the same route object. :-)
  * 
  * @param string $fromUri
  * @param string $toUri
  * @param string $fromHttpMethod
  * @param string $toHttpMethod
  * @return Threepwood\Flagship
  */
 public function alias($fromUri, $toUri, $fromHttpMethod = HTTP_ALL, $toHttpMethod = HTTP_ALL)
 {
     $fromUri = str_replace('//', '/', $this->getOption('baseUrl') . $fromUri);
     $toUri = str_replace('//', '/', $this->getOption('baseUrl') . $toUri);
     $toRqst = new Http\Request($toUri, $toHttpMethod);
     $fromKey = Http\Request::buildRequestKey($fromUri, $fromHttpMethod);
     $route = $this->findStaticRoute($toRqst);
     if ($route) {
         $this->_staticRoutes[$fromKey] = $route;
         return $this;
     }
     $route = $this->findDynamicRoute($toRqst);
     if ($route) {
         $this->_dynamicRoutes[$fromKey] = $route;
         return $this;
     }
     throw new Route\Exception('Can\'t alias to non-existing route "' . $toRqst->getKey() . '"');
 }