<?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)
$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) {
--- /dev/null
+<?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;
+ }
+}
+
--- /dev/null
+<?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);
+ }
+}
--- /dev/null
+<?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'];
+ }
+}
}
if (!$result) {
- die("here");
return;
}
$matches[$key] = rawurldecode($value);
}
}
- var_dump($matches);
+
return new RouteMatch(array_merge($this->defaults, $matches), $matchedLength);
}