1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
route.php
См. документацию.
1
<?php
8
9
namespace
Bitrix\Main\Routing;
10
11
use Bitrix\Main\Type\Dictionary;
12
17
class
Route
18
{
20
protected
$uri
;
21
23
protected
$fullUri
;
24
26
protected
$matchUri
;
27
29
protected
$parameters
;
30
32
protected
$parametersValues
;
33
35
protected
$controller
;
36
38
protected
$options
;
39
40
public
function
__construct
(
$uri
,
$controller
)
41
{
42
$this->uri =
$uri
;
43
$this->controller =
$controller
;
44
}
45
49
public
function
getOptions
()
50
{
51
return
$this->options
;
52
}
53
57
public
function
setOptions
(
$options
)
58
{
59
$this->options =
$options
;
60
}
61
65
public
function
getController
()
66
{
67
return
$this->controller
;
68
}
69
73
public
function
getParameters
()
74
{
75
return
$this->parameters
;
76
}
77
81
public
function
getParametersValues
()
82
{
83
if
($this->parametersValues ===
null
)
84
{
85
$this->parametersValues =
new
Dictionary
();
86
}
87
88
return
$this->parametersValues
;
89
}
90
91
public
function
getParameterValue
(
$name
)
92
{
93
return
$this->
getParametersValues
()->get(
$name
);
94
}
95
96
public
function
compile
()
97
{
98
if
($this->matchUri !==
null
)
99
{
100
return
;
101
}
102
103
$this->matchUri =
"#^{$this->getUri()}$#"
;
104
$this->parameters = [];
105
106
// there are parameters, collect them
107
preg_match_all(
'/{([a-z0-9_]+)}/i'
, $this->
getUri
(),
$matches
);
108
$parameterNames =
$matches
[1];
109
110
foreach
($parameterNames as $parameterName)
111
{
112
$pattern
=
null
;
113
114
// check options for custom pattern
115
if
($this->options)
116
{
117
if
($this->options->hasWhere($parameterName))
118
{
119
// custom pattern
120
$pattern
= $this->options->getWhere($parameterName);
121
}
122
elseif
($this->options->hasDefault($parameterName))
123
{
124
// can be empty
125
$pattern
=
'[^/]*'
;
126
}
127
}
128
129
if
(
$pattern
===
null
)
130
{
131
// general case
132
$pattern
=
'[^/]+'
;
133
}
134
135
$this->parameters[$parameterName] =
$pattern
;
136
137
// put pattern in uri
138
$this->matchUri = str_replace(
139
"{{$parameterName}}"
,
140
"(?<{$parameterName}>{$pattern})"
,
141
$this->matchUri
142
);
143
}
144
}
145
146
public
function
compileFromCache
($cacheData)
147
{
148
$this->matchUri = $cacheData[
'matchUri'
];
149
$this->parameters = $cacheData[
'parameters'
];
150
}
151
152
public
function
getCompileCache
()
153
{
154
$this->
compile
();
155
156
return
[
157
'matchUri'
=>
$this->matchUri
,
158
'parameters'
=>
$this->parameters
159
];
160
}
161
162
public
function
match
($uriPath)
163
{
164
if
(str_contains($this->
getUri
(),
'{'
))
165
{
166
// compile regexp
167
$this->
compile
();
168
169
// match
170
$result
= preg_match($this->matchUri, $uriPath,
$matches
);
171
172
if
(
$result
)
173
{
174
// set parameters to the request
175
$requestParameters = [];
176
$parametersList = array_keys($this->parameters);
177
178
foreach
($parametersList as $parameter)
179
{
180
if
(
$matches
[$parameter] ===
''
&& $this->options && $this->options->hasDefault($parameter))
181
{
182
// set default value if optional parameter is empty
183
$requestParameters[$parameter] = $this->options->getDefault($parameter);
184
}
185
else
186
{
187
$requestParameters[$parameter] =
$matches
[$parameter];
188
}
189
}
190
191
// set default values if parameter with the same name wasn't set in request
192
// e.g. "RULE" => "download=1&objectId=\$1"
193
if
(!empty(
$defaultValues
= $this->options->getDefault()))
194
{
195
foreach
(
$defaultValues
as $parameter =>
$defaultValue
)
196
{
197
if
(!in_array($parameter, $parametersList))
198
{
199
$requestParameters[$parameter] =
$defaultValue
;
200
}
201
}
202
}
203
204
return
$requestParameters;
205
}
206
}
207
else
208
{
209
if
($uriPath === $this->
getUri
())
210
{
211
$requestParameters = [];
212
213
// set default values if parameter with the same name wasn't set in request
214
// e.g. "RULE" => "download=1&objectId=\$1"
215
if
(!empty(
$defaultValues
= $this->options->getDefault()))
216
{
217
foreach
(
$defaultValues
as $parameter =>
$defaultValue
)
218
{
219
$requestParameters[$parameter] =
$defaultValue
;
220
}
221
}
222
223
return
$requestParameters ?:
true
;
224
}
225
}
226
227
return
false
;
228
}
229
230
function
getUri
()
231
{
232
if
($this->fullUri ===
null
)
233
{
234
$this->fullUri =
$this->uri
;
235
236
// concat with option prefix and cache
237
if
($this->options && $this->options->hasPrefix())
238
{
239
$this->fullUri = $this->options->getFullPrefix().
'/'
.
$this->uri
;
240
}
241
}
242
243
return
$this->fullUri
;
244
}
245
}
$defaultValue
if($_SERVER $defaultValue['REQUEST_METHOD']==="GET" &&!empty($RestoreDefaults) && $bizprocPerms==="W" &&check_bitrix_sessid())
Определения
options.php:32
Bitrix\Main\Routing\Route
Определения
route.php:18
Bitrix\Main\Routing\Route\$options
$options
Определения
route.php:38
Bitrix\Main\Routing\Route\getParameters
getParameters()
Определения
route.php:73
Bitrix\Main\Routing\Route\match
match($uriPath)
Определения
route.php:162
Bitrix\Main\Routing\Route\getOptions
getOptions()
Определения
route.php:49
Bitrix\Main\Routing\Route\compileFromCache
compileFromCache($cacheData)
Определения
route.php:146
Bitrix\Main\Routing\Route\getUri
getUri()
Определения
route.php:230
Bitrix\Main\Routing\Route\compile
compile()
Определения
route.php:96
Bitrix\Main\Routing\Route\$controller
$controller
Определения
route.php:35
Bitrix\Main\Routing\Route\$fullUri
$fullUri
Определения
route.php:23
Bitrix\Main\Routing\Route\$parametersValues
$parametersValues
Определения
route.php:32
Bitrix\Main\Routing\Route\__construct
__construct($uri, $controller)
Определения
route.php:40
Bitrix\Main\Routing\Route\$uri
$uri
Определения
route.php:20
Bitrix\Main\Routing\Route\setOptions
setOptions($options)
Определения
route.php:57
Bitrix\Main\Routing\Route\getCompileCache
getCompileCache()
Определения
route.php:152
Bitrix\Main\Routing\Route\getParameterValue
getParameterValue($name)
Определения
route.php:91
Bitrix\Main\Routing\Route\getController
getController()
Определения
route.php:65
Bitrix\Main\Routing\Route\$parameters
$parameters
Определения
route.php:29
Bitrix\Main\Routing\Route\getParametersValues
getParametersValues()
Определения
route.php:81
Bitrix\Main\Routing\Route\$matchUri
$matchUri
Определения
route.php:26
Bitrix\Main\Type\Dictionary
Определения
dictionary.php:6
$result
$result
Определения
get_property_values.php:14
$defaultValues
$defaultValues
Определения
iblock_catalog_edit.php:124
$name
$name
Определения
menu_edit.php:35
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$pattern
if(!Loader::includeModule('sale')) $pattern
Определения
index.php:20
$matches
$matches
Определения
index.php:22
bitrix
modules
main
lib
routing
route.php
Создано системой
1.14.0