1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Fwk |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2011-2014, Julien Ballestracci <[email protected]>. |
6
|
|
|
* All rights reserved. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
12
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
13
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
14
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
15
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
16
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
17
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
18
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
19
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
20
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
21
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
22
|
|
|
* POSSIBILITY OF SUCH DAMAGE. |
23
|
|
|
* |
24
|
|
|
* PHP Version 5.3 |
25
|
|
|
* |
26
|
|
|
* @category Core |
27
|
|
|
* @package Fwk\Core |
28
|
|
|
* @subpackage Components |
29
|
|
|
* @author Julien Ballestracci <[email protected]> |
30
|
|
|
* @copyright 2011-2014 Julien Ballestracci <[email protected]> |
31
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
32
|
|
|
* @link http://www.fwk.pw |
33
|
|
|
*/ |
34
|
|
|
namespace Fwk\Core\Components\UrlRewriter; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Route Parameter |
38
|
|
|
* |
39
|
|
|
* @category Utilities |
40
|
|
|
* @package Fwk\Core |
41
|
|
|
* @subpackage Components |
42
|
|
|
* @author Julien Ballestracci <[email protected]> |
43
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
44
|
|
|
* @link http://www.phpfwk.com |
45
|
|
|
*/ |
46
|
|
|
class RouteParameter |
47
|
|
|
{ |
48
|
|
|
const DEFAULT_REGEX = '.[^/\.]{0,}'; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
protected $name; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* |
58
|
|
|
* @var boolean |
59
|
|
|
*/ |
60
|
|
|
protected $required; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* |
64
|
|
|
* @var string |
65
|
|
|
*/ |
66
|
|
|
protected $regex; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* |
70
|
|
|
* @var mixed |
71
|
|
|
*/ |
72
|
|
|
protected $default; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* |
76
|
|
|
* @var string |
77
|
|
|
*/ |
78
|
|
|
protected $value; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* |
82
|
|
|
* @param type $name |
83
|
|
|
* @param type $default |
|
|
|
|
84
|
|
|
* @param type $regex |
|
|
|
|
85
|
|
|
* @param type $required |
|
|
|
|
86
|
|
|
* @param type $value |
|
|
|
|
87
|
|
|
* |
88
|
|
|
* @return void |
|
|
|
|
89
|
|
|
*/ |
90
|
13 |
|
public function __construct($name, $default = null, |
91
|
|
|
$regex = null, $required = true, $value = null |
92
|
|
|
) { |
93
|
13 |
|
$this->name = (string)$name; |
94
|
13 |
|
$this->default = $default; |
95
|
13 |
|
$this->required = (bool)$required; |
96
|
13 |
|
$this->regex = (empty($regex) ? self::DEFAULT_REGEX : $regex); |
|
|
|
|
97
|
13 |
|
$this->value = $value; |
|
|
|
|
98
|
13 |
|
} |
99
|
|
|
|
100
|
13 |
|
public function getName() |
101
|
|
|
{ |
102
|
13 |
|
return $this->name; |
103
|
|
|
} |
104
|
|
|
|
105
|
7 |
|
public function isRequired() |
106
|
|
|
{ |
107
|
7 |
|
return $this->required; |
108
|
|
|
} |
109
|
|
|
|
110
|
7 |
|
public function getRegex() |
111
|
|
|
{ |
112
|
7 |
|
return $this->regex; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function getDefault() |
116
|
|
|
{ |
117
|
|
|
return $this->default; |
118
|
|
|
} |
119
|
|
|
|
120
|
4 |
|
public function getValueOrDefault() |
121
|
|
|
{ |
122
|
4 |
|
return (!empty($this->value) ? $this->value : $this->default); |
123
|
|
|
} |
124
|
|
|
|
125
|
2 |
|
public function setValue($value) |
126
|
|
|
{ |
127
|
2 |
|
$this->value = $value; |
128
|
2 |
|
} |
129
|
|
|
|
130
|
3 |
|
public function getValue() |
131
|
|
|
{ |
132
|
3 |
|
return $this->value; |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.