'Action' => Literal::factory([ 'route' => 'Action', 'defaults' => [ 'controller' => 'dns\page\ActionPage' ] ]),
'DomainList' => Literal::factory([ 'route' => 'DomainList', 'defaults' => [ 'controller' => 'dns\page\DomainListPage' ] ]),
'DomainAdd' => Literal::factory([ 'route' => 'DomainAdd', 'defaults' => [ 'controller' => 'dns\page\DomainAddPage' ] ]),
- 'RecordList' => Regex::factory([ 'regex' => 'RecordList/(?P<id>\d+)(/)?(?:-(?P<title>[^/]+))?', 'defaults' => [ 'controller' => 'dns\page\RecordListPage' ], 'spec' => 'RecordList/%id%-%title%' ]),
- 'RecordEdit' => Regex::factory([ 'regex' => 'RecordEdit/(?P<id>\d+)(/)?', 'defaults' => [ 'controller' => 'dns\page\RecordEditPage' ], 'spec' => 'RecordEdit/%id%' ]),
- 'RecordAdd' => Regex::factory([ 'regex' => 'RecordAdd/(?P<id>\d+)(/)?', 'defaults' => [ 'controller' => 'dns\page\RecordAddPage' ], 'spec' => 'RecordAdd/%id%' ]),
- 'SecList' => Regex::factory([ 'regex' => 'SecList/(?P<id>\d+)(/)?(?:-(?P<title>[^/]+))?', 'defaults' => [ 'controller' => 'dns\page\SecListPage' ], 'spec' => 'SecList/%id%-%title%' ]),
+ 'RecordList' => Segment::factory([ 'route' => 'RecordList/:id[-:title]', 'constraints' => [ 'id' => '[0-9]+', 'title' => '[a-zA-Z0-9_.-/]+' ], 'defaults' => [ 'controller' => 'dns\page\RecordListPage' ] ]),
+ 'RecordEdit' => Segment::factory([ 'route' => 'RecordEdit/:id', 'constraints' => [ 'id' => '[0-9]+' ], 'defaults' => [ 'controller' => 'dns\page\RecordEditPage' ] ]),
+ 'RecordAdd' => Segment::factory([ 'route' => 'RecordAdd/:id', 'constraints' => [ 'id' => '[0-9]+' ], 'defaults' => [ 'controller' => 'dns\page\RecordAddPage' ] ]),
+ 'SecList' => Segment::factory([ 'route' => 'SecList/:id[-:title]', 'constraints' => [ 'id' => '[0-9]+', 'title' => '[a-zA-Z0-9_.-/]+' ], 'defaults' => [ 'controller' => 'dns\page\SecListPage' ] ]),
];
$this->router->setRoutes($routes);
--- /dev/null
+<?php
+namespace dns\system\route;
+use Zend\Mvc\Router\Http\Segment as SegmentBase;
+use Zend\Mvc\Router\Http\RouteMatch;
+use Zend\Stdlib\RequestInterface as Request;
+
+class Segment extends SegmentBase {
+ public function match(Request $request, $pathOffset = null, array $options = []) {
+ if (!method_exists($request, 'getPath')) {
+ return;
+ }
+
+ $path = $request->getPath();
+
+ $regex = $this->regex;
+
+ if ($this->translationKeys) {
+ if (!isset($options['translator']) || !$options['translator'] instanceof Translator) {
+ throw new Exception\RuntimeException('No translator provided');
+ }
+
+ $translator = $options['translator'];
+ $textDomain = (isset($options['text_domain']) ? $options['text_domain'] : 'default');
+ $locale = (isset($options['locale']) ? $options['locale'] : null);
+
+ foreach ($this->translationKeys as $key) {
+ $regex = str_replace('#' . $key . '#', $translator->translate($key, $textDomain, $locale), $regex);
+ }
+ }
+
+ if ($pathOffset !== null) {
+ $result = preg_match('(\G' . $regex . ')i', $path, $matches, null, $pathOffset);
+ }
+ else {
+ $result = preg_match('(^' . $regex . '$)i', $path, $matches);
+ }
+
+ if (!$result) {
+ return;
+ }
+
+ $matchedLength = strlen($matches[0]);
+ $params = [];
+
+ foreach ($this->paramMap as $index => $name) {
+ if (isset($matches[$index]) && $matches[$index] !== '') {
+ $params[$name] = $this->decode($matches[$index]);
+ }
+ }
+
+ return new RouteMatch(array_merge($this->defaults, $params), $matchedLength);
+ }
+}