public function testPathToString() { $request = new ActionRequest(Message\Request::create('/index.php/foo')->withServerParams(['SCRIPT_NAME' => '/index.php'])); $this->assertEquals('/index.php', $request->pathToString([])); $this->assertEquals('/', $request->pathToString([], true)); $this->assertEquals('/index.php/foo/bar', $request->pathToString(['foo', 'bar'])); $request = $request->withAttribute('rewrite', true); $this->assertEquals('/foo/bar', $request->pathToString(['foo', 'bar', '', ''])); $this->assertEquals('/foo//bar', $request->pathToString(['foo', '', 'bar'])); }
/** * {@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); }
/** * Create a path redirect. * * @param string|string[] $path Path array. * @param array $query Query. * @param string $fragment Fragment. * @param bool $permanent Whether redirect is permanent. * @param bool $rewrite Whether to force removal of script name from path. * @return ResponseInterface A redirect response. */ public function redirectPath($path, array $query = [], $fragment = '', $permanent = false, $rewrite = false) { $location = new Message\Uri($this->request->pathToString($path, $rewrite)); $location = $location->withQuery(http_build_query($query))->withFragment($fragment); return Message\Response::redirect($location, $permanent); }