예제 #1
0
 public function testInvoke()
 {
     $map = new RouteMap();
     $map->add('/foo/{id}', function () {
     })->name('foo');
     $url = new UrlFunction($map);
     $this->assertSame('/foo/1234', $url('foo', ['id' => 1234]));
 }
예제 #2
0
파일: Router.php 프로젝트: kingjerod/tonis
 /**
  * @param string|string[] $methods
  * @param string          $path
  * @param callable        $handler
  * @return Route
  */
 public function route($methods, $path, $handler)
 {
     $route = $this->routeMap->add($path, $handler);
     $this->collector->addRoute($methods, $path, $route);
     $this->middleware[] = $route;
     return $route;
 }
예제 #3
0
파일: App.php 프로젝트: tonis-io/tonis
 /**
  * @param ServerRequestInterface $request
  * @param ResponseInterface      $response
  * @param callable               $next
  * @return ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
 {
     $request = $this->decorateRequest($request);
     $response = $this->decorateResponse($response);
     $relay = $this->relayBuilder->newInstance($this->middleware);
     $error = $this->errorHandler;
     $notFound = $this->notFoundHandler;
     try {
         $response = $relay($request, $response);
     } catch (\Exception $ex) {
         $response = $error($request, $response, $ex);
     }
     if (!$response instanceof ResponseInterface) {
         throw new Exception\InvalidResponse();
     }
     if (null === $this->routeMap->getRouteMatch()) {
         $response = $notFound($request, $response);
     }
     return $next ? $next($request, $response) : $response;
 }
예제 #4
0
 /**
  * Generates a url for the route specified if it exists.
  *
  * @param string $name
  * @param array $params
  * @return string
  */
 public function __invoke($name, array $params = [])
 {
     return $this->routeMap->assemble($name, $params);
 }