-
-
Notifications
You must be signed in to change notification settings - Fork 188
/
StaticRoutePart.php
74 lines (68 loc) · 2.04 KB
/
StaticRoutePart.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace Neos\Flow\Mvc\Routing;
/*
* This file is part of the Neos.Flow package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
/**
* Static Route Part
*
*/
class StaticRoutePart extends \Neos\Flow\Mvc\Routing\AbstractRoutePart
{
/**
* Gets default value of the Route Part.
*
* @return string
*/
public function getDefaultValue()
{
return $this->name;
}
/**
* Checks whether this Static Route Part correspond to the given $routePath.
* This is true if $routePath is not empty and the first part is equal to the Route Part name.
*
* @param string|null $routePath The request path to be matched - without query parameters, host and fragment.
* @return boolean true if Route Part matched $routePath, otherwise false.
*/
public function match(&$routePath)
{
$routePath = (string)$routePath;
$this->value = null;
if ($this->name === null || $this->name === '') {
return false;
}
if ($routePath === '' || $routePath === null) {
return false;
}
$valueToMatch = substr($routePath, 0, strlen($this->name));
if ($valueToMatch !== $this->name) {
return false;
}
$routePath = substr($routePath, strlen($valueToMatch));
return true;
}
/**
* Sets the Route Part value to the Route Part name and returns true if successful.
*
* @param array $routeValues not used but needed to implement \Neos\Flow\Mvc\Routing\AbstractRoutePart
* @return boolean
*/
public function resolve(array &$routeValues)
{
if ($this->name === null || $this->name === '') {
return false;
}
$this->value = $this->name;
if ($this->lowerCase) {
$this->value = strtolower($this->value);
}
return true;
}
}