コード例 #1
0
ファイル: Router.php プロジェクト: jivoo/http
 /**
  * {@inheritdoc}
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
 {
     $this->request = new ActionRequest($request);
     $this->request = $this->request->withAttribute('rewrite', $this->rewrite);
     $path = $this->request->path;
     if (!$this->rewrite) {
         if (!isset($path[0]) or $path[0] != $this->request->scriptName) {
             return $this->redirectPath($path, $this->request->query, '', true);
         }
         array_shift($path);
         $this->request = $this->request->withAttribute('path', $path);
     }
     if (count($path) > 0 and $path[count($path) - 1] === '') {
         return $this->redirectPath($path, $this->request->query, '', true);
     }
     $this->route = $this->findMatch($path, $this->request->getMethod());
     if (!isset($this->route)) {
         throw new Route\RouteException('No route found for path "' . implode('/', $path) . '"');
     }
     $middleware = $this->middleware;
     $this->triggerEvent('dispatch', new RouterEvent($this, $this->route, $this->request, $response));
     $first = $this->getNext($middleware, [$this->route, 'dispatch']);
     $response = $first($this->request, $response);
     $this->triggerEvent('dispatched', new RouterEvent($this, $this->route, $this->request, $response));
     return $response;
 }
コード例 #2
0
ファイル: ActionRequestTest.php プロジェクト: jivoo/http
 public function testFindPath()
 {
     $request = Message\Request::create('/foo/index.php/foo/bar');
     $this->assertEquals(['foo', 'index.php', 'foo', 'bar'], ActionRequest::findPath($request));
     $request = $request->withServerParams(['SCRIPT_NAME' => '/foo/index.php']);
     $this->assertEquals(['index.php', 'foo', 'bar'], ActionRequest::findPath($request));
     $request = $request->withUri(new Message\Uri('/foo'));
     $this->assertEquals([], ActionRequest::findPath($request));
     $request = $request->withUri(new Message\Uri('/foo/'));
     $this->assertEquals([], ActionRequest::findPath($request));
 }
コード例 #3
0
ファイル: PathRoute.php プロジェクト: jivoo/http
 /**
  * {@inheritdoc}
  */
 public function dispatch(\Jivoo\Http\ActionRequest $request, \Psr\Http\Message\ResponseInterface $response)
 {
     $location = new Message\Uri($request->pathToString($this->path));
     $location = $location->withQuery(http_build_query($this->query))->withFragment($this->fragment);
     return Message\Response::redirect($location, false);
 }