Пример #1
0
 /**
  * @param Destination $destination
  * @param Uri $context
  * @return Uri
  */
 public function assemble(Destination $destination, $context = null)
 {
     $base = Uri::cast($context);
     $params = $destination->getParams();
     $path = $this->resolvePattern($params->core());
     $uri = new Uri();
     $uri->setPath($base->getPath() . $path);
     return $uri;
 }
Пример #2
0
 /**
  * @param string $route
  * @param array $params
  * @return Uri
  */
 public function assemble($route, $params = null, $base = null)
 {
     if ($base === null) {
         $request = $this->getRequest();
         if ($request) {
             $base = $request->getRoot();
         }
     }
     return $this->routes->assemble(Destination::match($params, $route), $base);
 }
Пример #3
0
 public function testSimple1()
 {
     $request = $this->request('admin/area/51');
     $root = $request->getRoot();
     $chain = Rt\ChainRoute::factory(['admin' => ['pattern' => '/admin', 'params' => ['controller' => 'C1', 'action' => 'a1'], 'children' => ['area' => ['pattern' => '/area[/{id}]', 'params' => ['extra' => 'EXTRA']]]]]);
     $exp = ['id' => '51', 'controller' => 'C1', 'action' => 'a1', 'extra' => 'EXTRA'];
     $dest = $chain->route($request);
     $this->assertTrue($dest->isMatch());
     $this->assertTrue($dest->isFinal());
     $this->assertEquals($exp, $dest->getParams()->core());
     $uri = $chain->assemble(Rt\Destination::match(['id' => 51], "admin/area"), $root);
     $this->assertEquals("{$root}/admin/area/51", $uri->toString());
 }
Пример #4
0
 public function testSimple1()
 {
     $request = new Request();
     $root = "/demo";
     $request->setRoot($root);
     $request->getUri()->setPath("{$root}/admin/view/42");
     $context = new R\Destination();
     // $context->setRemainder("/admin/article/view/123/the-slug");
     $route = new R\RegexRoute("|^/admin/(?<action>[\\w]+)|", "{~}/admin/{action}");
     $dest = $route->route($request, $context);
     // var_dump($dest);
     $uri = $route->assemble(R\Destination::match(['action' => "index"]), $root);
     // var_dump($uri);
 }
Пример #5
0
 public function testSimple1()
 {
     $request = new Request();
     $root = "/demo";
     $request->setRoot($root);
     $request->getUri()->setPath("{$root}/admin/view/segment");
     $context = new Rt\Destination();
     $route = new Rt\SegmentRoute("/admin[/{action}]");
     $route->setPartial();
     $dest = $route->route($request, $context);
     // var_dump($dest);
     $uri = $route->assemble(Rt\Destination::match(['action' => "index"]), $root);
     // var_dump($uri);
 }
Пример #6
0
 /**
  *
  * @param Request $request
  * @param Destination $context
  * @return string
  */
 protected function matchSubject($request, $context)
 {
     if ($context && $context->getRemainder()) {
         $subject = $context->getRemainder();
     } else {
         $subject = $this->requestSubject($request);
     }
     return $subject;
 }
Пример #7
0
 /**
  * @param Destination $destination
  * @param array $params
  * @return Param\Node
  */
 protected function processParams(Destination $destination, array $params)
 {
     $target = $destination->getParams();
     $target->inject($this->getDefaults());
     $target->inject($params);
     return $target;
 }
Пример #8
0
 public function testAssemble1()
 {
     $route = new R\SimpleRoute("/admin");
     $uri = $route->assemble(R\Destination::match([]), '/test');
     $this->assertEquals("/test/admin", $uri->toString());
 }
Пример #9
0
 /**
  * @param Destination $destination
  * @return Uri
  */
 public function assemble(Destination $destination, $uri = null)
 {
     $base = $this->getBase();
     $path = $destination->getName();
     list($head, $tail) = $this->shiftPath($path);
     if ($base) {
         $uri = $base->assemble($destination, $uri);
     }
     if ($head) {
         if (!isset($this->children[$head])) {
             throw new Exception\RuntimeException("Route [{$head}] not found", 1);
         }
         $route = $this->children[$head]['route'];
         $dest = clone $destination;
         $dest->setName($tail);
         $uri = $route->assemble($dest, $uri);
     }
     //
     return $uri;
 }