From 7d0df713669992ddc0ea5fc059e82b83c4297277 Mon Sep 17 00:00:00 2001 From: Stricted Date: Sun, 17 Jul 2016 07:21:58 +0200 Subject: [PATCH] remove debug code and add lowercase controller comparison --- lib/system/RequestHandler.class.php | 9 +++---- lib/system/route/Literal.class.php | 34 +++++++++++++++++++++++ lib/system/route/Regex.class.php | 39 +++++++++++++++++++++++++++ lib/system/route/Request.class.php | 13 +++++++++ vendor/Zend/Mvc/Router/Http/Regex.php | 3 +-- 5 files changed, 91 insertions(+), 7 deletions(-) create mode 100644 lib/system/route/Literal.class.php create mode 100644 lib/system/route/Regex.class.php create mode 100644 lib/system/route/Request.class.php diff --git a/lib/system/RequestHandler.class.php b/lib/system/RequestHandler.class.php index 5b9f96e..d08c0b3 100644 --- a/lib/system/RequestHandler.class.php +++ b/lib/system/RequestHandler.class.php @@ -1,10 +1,10 @@ addRoute('', Literal::factory([ 'route' => '', 'defaults' => [ 'controller' => 'dns\page\IndexPage' ] ])); $router->addRoute('Index', Literal::factory([ 'route' => 'Index', 'defaults' => [ 'controller' => 'dns\page\IndexPage' ] ])); - $router->addRoute('index', Literal::factory([ 'route' => 'index', 'defaults' => [ 'controller' => 'dns\page\IndexPage' ] ])); $router->addRoute('Login', Literal::factory([ 'route' => 'Login', 'defaults' => [ 'controller' => 'dns\page\LoginPage' ] ])); $router->addRoute('Logout', Literal::factory([ 'route' => 'Logout', 'defaults' => [ 'controller' => 'dns\page\LogoutPage' ] ])); $router->addRoute('DomainList', Literal::factory([ 'route' => 'DomainList', 'defaults' => [ 'controller' => 'dns\page\DomainListPage' ] ])); $router->addRoute('DomainAdd', Literal::factory([ 'route' => 'DomainAdd', 'defaults' => [ 'controller' => 'dns\page\DomainAddPage' ] ])); - //$router->addRoute('DomainAdd', Regex::factory([ 'regex' => 'DomainEdit/(?P\d+)(/)?', 'defaults' => [ 'controller' => 'dns\page\DomainEditPage' ], 'spec' => '/DomainEdit/%id%' ])); + //$router->addRoute('DomainEdit', Regex::factory([ 'regex' => 'DomainEdit/(?P\d+)(/)?', 'defaults' => [ 'controller' => 'dns\page\DomainEditPage' ], 'spec' => '/DomainEdit/%id%' ])); $match = $router->match(new Request()); if ($match !== null) { diff --git a/lib/system/route/Literal.class.php b/lib/system/route/Literal.class.php new file mode 100644 index 0000000..e5f9886 --- /dev/null +++ b/lib/system/route/Literal.class.php @@ -0,0 +1,34 @@ +getUri(); + $path = $uri->getPath(); + + if ($pathOffset !== null) { + if ($pathOffset >= 0 && strlen($path) >= $pathOffset && !empty($this->route)) { + if (strpos($path, $this->route, $pathOffset) === $pathOffset) { + return new RouteMatch($this->defaults, strlen($this->route)); + } + } + + return; + } + + if (mb_strtolower($path) === mb_strtolower($this->route)) { + return new RouteMatch($this->defaults, strlen($this->route)); + } + + return; + } +} + diff --git a/lib/system/route/Regex.class.php b/lib/system/route/Regex.class.php new file mode 100644 index 0000000..049cb87 --- /dev/null +++ b/lib/system/route/Regex.class.php @@ -0,0 +1,39 @@ +getUri(); + $path = $uri->getPath(); + + if ($pathOffset !== null) { + $result = preg_match('(\G' . $this->regex . ')i', $path, $matches, null, $pathOffset); + } else { + $result = preg_match('(^' . $this->regex . '$)i', $path, $matches); + } + + if (!$result) { + return; + } + + $matchedLength = strlen($matches[0]); + + foreach ($matches as $key => $value) { + if (is_numeric($key) || is_int($key) || $value === '') { + unset($matches[$key]); + } else { + $matches[$key] = rawurldecode($value); + } + } + + return new RouteMatch(array_merge($this->defaults, $matches), $matchedLength); + } +} diff --git a/lib/system/route/Request.class.php b/lib/system/route/Request.class.php new file mode 100644 index 0000000..7ab4912 --- /dev/null +++ b/lib/system/route/Request.class.php @@ -0,0 +1,13 @@ +defaults, $matches), $matchedLength); } -- 2.20.1