Fix routing

This commit is contained in:
Dennis Eichhorn 2019-03-17 19:32:27 +01:00
parent b62d213000
commit b286fa4de1
5 changed files with 12 additions and 11 deletions

View File

@ -263,12 +263,12 @@ final class Request extends RequestAbstract
*/
public function createRequestHashs(int $start = 0) : void
{
$this->hash = [];
$this->hash = [\sha1('')];
$pathArray = $this->uri->getPathElements();
foreach ($pathArray as $key => $path) {
$paths = [];
for ($i = $start; $i < $key + 1; ++$i) {
for ($i = $start; $i <= $key; ++$i) {
$paths[] = $pathArray[$i];
}

View File

@ -203,7 +203,7 @@ final class Argument implements UriInterface
$this->path = $path;
}
$this->pathElements = \explode('/', $this->path);
$this->pathElements = \explode('/', \ltrim($this->path, '/'));
}
/**

View File

@ -37,7 +37,7 @@ final class Http implements UriInterface
* @var string
* @since 1.0.0
*/
private $rootPath = '/';
private $rootPath = '';
/**
* Path offset.
@ -168,7 +168,7 @@ final class Http implements UriInterface
$this->port = $url['port'] ?? 80;
$this->user = $url['user'] ?? '';
$this->pass = $url['pass'] ?? '';
$this->path = \ltrim($url['path'] ?? '', '/');
$this->path = $url['path'] ?? '';
if (StringUtils::endsWith($this->path, '.php')) {
$path = \substr($this->path, 0, -4);
@ -180,7 +180,7 @@ final class Http implements UriInterface
$this->path = $path;
}
$this->pathElements = \explode('/', $this->path);
$this->pathElements = \explode('/', \ltrim($this->path, '/'));
$this->queryString = $url['query'] ?? '';
if (!empty($this->queryString)) {
@ -242,7 +242,7 @@ final class Http implements UriInterface
*/
public function setRootPath(string $root) : void
{
$this->rootPath = $root;
$this->rootPath = \rtrim($root, '/');
}
/**

View File

@ -74,6 +74,7 @@ class RequestTest extends \PHPUnit\Framework\TestCase
$request->createRequestHashs(0);
self::assertEquals([
'da39a3ee5e6b4b0d3255bfef95601890afd80709',
'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3',
'328413d996ab9b79af9d4098af3a65b885c4ca64'
], $request->getHash());

View File

@ -50,21 +50,21 @@ class HttpTest extends \PHPUnit\Framework\TestCase
{
$obj = new Http($uri = 'https://www.google.com/test/path.php?para1=abc&para2=2#frag');
self::assertEquals('/', $obj->getRootPath());
self::assertEquals('', $obj->getRootPath());
self::assertEquals(0, $obj->getPathOffset());
self::assertEquals('https', $obj->getScheme());
self::assertEquals('www.google.com', $obj->getHost());
self::assertEquals(80, $obj->getPort());
self::assertEquals('', $obj->getPass());
self::assertEquals('', $obj->getUser());
self::assertEquals('test/path', $obj->getPath());
self::assertEquals('test/path?para1=abc&para2=2', $obj->getRoute());
self::assertEquals('/test/path', $obj->getPath());
self::assertEquals('/test/path?para1=abc&para2=2', $obj->getRoute());
self::assertEquals('test', $obj->getPathElement(0));
self::assertEquals('para1=abc&para2=2', $obj->getQuery());
self::assertEquals(['para1' => 'abc', 'para2' => '2'], $obj->getQueryArray());
self::assertEquals('2', $obj->getQuery('para2'));
self::assertEquals('frag', $obj->getFragment());
self::assertEquals('https://www.google.com/', $obj->getBase());
self::assertEquals('https://www.google.com', $obj->getBase());
self::assertEquals($uri, $obj->__toString());
self::assertEquals('www.google.com:80', $obj->getAuthority());
self::assertEquals('', $obj->getUserInfo());