1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
router.php
См. документацию.
1
<?php
8
9
namespace
Bitrix\Main\Routing;
10
11
use Bitrix\Main\HttpRequest;
12
use Bitrix\Main\Routing\Exceptions\ParameterNotFoundException;
13
18
class
Router
19
{
21
protected
$routes
= [];
22
24
protected
$routesByName
= [];
25
27
protected
$configurations
= [];
28
29
public
function
registerConfiguration
($configuration)
30
{
31
$this->configurations[] = $configuration;
32
}
33
34
public
function
releaseRoutes
()
35
{
36
// go recursively through routes tree
37
$i
= -1;
38
while
(isset($this->configurations[++
$i
]))
39
{
40
$this->routes = array_merge($this->routes, $this->configurations[
$i
]->release());
41
}
42
43
// reindex
44
$this->
reindexRoutes
();
45
46
// don't need them anymore
47
$this->configurations = [];
48
}
49
50
protected
function
reindexRoutes
()
51
{
52
$this->routesByName = [];
53
54
foreach
($this->routes as
$route
)
55
{
56
if
(
$route
->getOptions() &&
$route
->getOptions()->hasName())
57
{
58
$this->routesByName[
$route
->getOptions()->getFullName()] =
$route
;
59
}
60
}
61
}
62
68
public
function
match
(
$request
)
69
{
70
$path
= urldecode($this->
getUriPath
(
$request
));
71
72
foreach
($this->routes as
$route
)
73
{
74
if
($matchResult =
$route
->match(
$path
))
75
{
76
// check method
77
if
(!empty(
$route
->getOptions()->getMethods())
78
&& !in_array(
$request
->getRequestMethod(),
$route
->getOptions()->getMethods(),
true
))
79
{
80
continue
;
81
}
82
83
if
(is_array($matchResult))
84
{
85
$route
->getParametersValues()->setValues($matchResult);
86
}
87
88
return
$route
;
89
}
90
}
91
}
92
98
protected
function
getUriPath
(
$request
)
99
{
100
// cut GET parameters
101
$path
= str_replace(
102
'?'
.
$request
->getServer()->get(
'QUERY_STRING'
),
103
''
,
104
$request
->getRequestUri()
105
);
106
107
// cut scheme and domain
108
$scheme =
$request
->isHttps() ?
'https://'
:
'http://'
;
109
$schemeLen = strlen($scheme);
110
111
if
(substr(
$path
, 0, $schemeLen) === $scheme)
112
{
113
$pathSlashPos = strpos(substr(
$path
, $schemeLen),
'/'
) + $schemeLen;
114
$path
= substr(
$path
, $pathSlashPos);
115
}
116
117
return
$path
;
118
}
119
120
public
function
url
(
$url
, $parameters = [])
121
{
122
// scheme, domain?
123
$finalUrl =
$url
;
124
125
if
(!empty($parameters))
126
{
127
$finalUrl .=
'?'
.http_build_query($parameters);
128
}
129
130
return
$finalUrl;
131
}
132
139
public
function
route
(
$name
, $parameters = [])
140
{
141
if
(!empty($this->routesByName[
$name
]))
142
{
143
// route should be compiled
144
$route
= $this->routesByName[
$name
];
145
$route
->compile();
146
147
$uri
=
$route
->getUri();
148
149
if
(!empty($routeParameters =
$route
->getParameters()))
150
{
151
foreach
($routeParameters as $parameterName =>
$pattern
)
152
{
153
if
(array_key_exists($parameterName, $parameters))
154
{
155
// get from user
156
$value = $parameters[$parameterName];
157
158
// remove from user list
159
unset($parameters[$parameterName]);
160
}
161
elseif
(
$route
->getOptions() &&
$route
->getOptions()->hasDefault($parameterName))
162
{
163
$value =
$route
->getOptions()->getDefault($parameterName);
164
}
165
else
166
{
167
throw
new
ParameterNotFoundException
;
168
}
169
170
// check with pattern?
171
172
$uri
= str_replace(
"{{$parameterName}}"
, urlencode($value),
$uri
);
173
}
174
}
175
176
// additional parameters as query string
177
if
(!empty($parameters))
178
{
179
$uri
.=
'?'
.http_build_query($parameters);
180
}
181
182
return
$uri
;
183
}
184
185
return
null
;
186
}
187
191
public
function
getRoutes
()
192
{
193
return
$this->routes;
194
}
195
}
$path
$path
Определения
access_edit.php:21
$request
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения
catalog_reindex.php:36
Bitrix\Main\Engine\Router
Определения
router.php:17
Bitrix\Main\Routing\Exceptions\ParameterNotFoundException
Определения
parameternotfoundexception.php:18
Bitrix\Main\Routing\Router\getUriPath
getUriPath($request)
Определения
router.php:98
Bitrix\Main\Routing\Router\$routesByName
$routesByName
Определения
router.php:24
Bitrix\Main\Routing\Router\getRoutes
getRoutes()
Определения
router.php:191
Bitrix\Main\Routing\Router\reindexRoutes
reindexRoutes()
Определения
router.php:50
Bitrix\Main\Routing\Router\registerConfiguration
registerConfiguration($configuration)
Определения
router.php:29
Bitrix\Main\Routing\Router\$configurations
$configurations
Определения
router.php:27
Bitrix\Main\Routing\Router\url
url($url, $parameters=[])
Определения
router.php:120
Bitrix\Main\Routing\Router\$routes
$routes
Определения
router.php:21
Bitrix\Main\Routing\Router\releaseRoutes
releaseRoutes()
Определения
router.php:34
Bitrix\Main\Routing\Router\route
route($name, $parameters=[])
Определения
router.php:139
Bitrix\Main\Routing\Router\match
match($request)
Определения
router.php:68
$uri
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
Определения
urlrewrite.php:61
$name
$name
Определения
menu_edit.php:35
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$route
$route
Определения
routing_index.php:35
$i
$i
Определения
factura.php:643
$pattern
if(!Loader::includeModule('sale')) $pattern
Определения
index.php:20
$url
$url
Определения
iframe.php:7
bitrix
modules
main
lib
routing
router.php
Создано системой
1.14.0