<?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;
+use Zend\Stdlib\RequestInterface as Request;
class Literal extends LiteralBase {
- public function match(Request $request, $pathOffset = null)
- {
- if (!method_exists($request, 'getUri')) {
- return;
- }
+ public function match(Request $request, $pathOffset = null) {
+ if (!method_exists($request, 'getUri')) {
+ return;
+ }
+
+ $uri = $request->getUri();
+ $path = $uri->getPath();
- $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));
+ }
+ }
- 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;
+ }
- return;
- }
-
- if (mb_strtolower($path) === mb_strtolower($this->route)) {
- return new RouteMatch($this->defaults, strlen($this->route));
- }
+ if (mb_strtolower($path) === mb_strtolower($this->route)) {
+ return new RouteMatch($this->defaults, strlen($this->route));
+ }
- return;
- }
+ return;
+ }
}
<?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;
+use Zend\Stdlib\RequestInterface as Request;
class Regex extends RegexBase {
- public function match(Request $request, $pathOffset = null)
- {
- if (!method_exists($request, 'getUri')) {
- return;
- }
+ public function match(Request $request, $pathOffset = null) {
+ if (!method_exists($request, 'getUri')) {
+ return;
+ }
+
+ $uri = $request->getUri();
+ $path = $uri->getPath();
- $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 ($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;
+ }
- if (!$result) {
- return;
- }
+ $matchedLength = strlen($matches[0]);
- $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);
+ }
+ }
- 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);
- }
+ return new RouteMatch(array_merge($this->defaults, $matches), $matchedLength);
+ }
}