remove debug code and add lowercase controller comparison
authorStricted <info@stricted.net>
Sun, 17 Jul 2016 05:21:58 +0000 (07:21 +0200)
committerStricted <info@stricted.net>
Sun, 17 Jul 2016 05:21:58 +0000 (07:21 +0200)
lib/system/RequestHandler.class.php
lib/system/route/Literal.class.php [new file with mode: 0644]
lib/system/route/Regex.class.php [new file with mode: 0644]
lib/system/route/Request.class.php [new file with mode: 0644]
vendor/Zend/Mvc/Router/Http/Regex.php

index 5b9f96e2d2ebd474c873722a0727cde64788001d..d08c0b3a89b1b066572a8112f6433b2539be7a62 100644 (file)
@@ -1,10 +1,10 @@
 <?php
 namespace dns\system;
 use dns\system\cache\builder\ControllerCacheBuilder;
-use Zend\Mvc\Router\Http\Literal;
-use Zend\Mvc\Router\Http\Regex;
+use dns\system\route\Request;
+use dns\system\route\Literal;
+use dns\system\route\Regex;
 use Zend\Mvc\Router\SimpleRouteStack;
-use Zend\ServiceManager\ServiceManager;
 
 /**
  * @author      Jan Altensen (Stricted)
@@ -30,12 +30,11 @@ class RequestHandler {
                
                $router->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<id>\d+)(/)?', 'defaults' => [ 'controller' => 'dns\page\DomainEditPage' ], 'spec' => '/DomainEdit/%id%' ]));
+               //$router->addRoute('DomainEdit', Regex::factory([ 'regex' => 'DomainEdit/(?P<id>\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 (file)
index 0000000..e5f9886
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+namespace dns\system\route;
+use Zend\Mvc\Router\Http\Literal as LiteralBase;
+use Zend\Stdlib\RequestInterface as Request;
+use Zend\Mvc\Router\Http\RouteMatch;
+
+class Literal extends LiteralBase {
+    public function match(Request $request, $pathOffset = null)
+    {
+        if (!method_exists($request, 'getUri')) {
+            return;
+        }
+
+        $uri  = $request->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 (file)
index 0000000..049cb87
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+namespace dns\system\route;
+use Zend\Mvc\Router\Http\Regex as RegexBase;
+use Zend\Stdlib\RequestInterface as Request;
+use Zend\Mvc\Router\Http\RouteMatch;
+
+class Regex extends RegexBase {
+    public function match(Request $request, $pathOffset = null)
+    {
+        if (!method_exists($request, 'getUri')) {
+            return;
+        }
+
+        $uri  = $request->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 (file)
index 0000000..7ab4912
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+namespace dns\system\route;
+use Zend\Stdlib\Request as BaseRequest;
+
+class Request extends BaseRequest {
+       public function getUri() {
+               return $this;
+       }
+       
+       public function getPath() {
+               return $_SERVER['QUERY_STRING'];
+       }
+}
index 3cb0cd11dc8059c8bd492f04e968c38a1465185f..ce1c8cf7bb15aab9a2bc706f6941a3faa6c2c6b3 100644 (file)
@@ -117,7 +117,6 @@ class Regex implements RouteInterface
         }
 
         if (!$result) {
-                       die("here");
             return;
         }
 
@@ -130,7 +129,7 @@ class Regex implements RouteInterface
                 $matches[$key] = rawurldecode($value);
             }
         }
-               var_dump($matches);
+               
         return new RouteMatch(array_merge($this->defaults, $matches), $matchedLength);
     }