%PDF- %PDF-
Server IP : 37.220.80.31 / Your IP : 18.119.118.210 Web Server : Apache/2.4.52 (Ubuntu) System : Linux 3051455-guretool.twc1.net 5.15.0-107-generic #117-Ubuntu SMP Fri Apr 26 12:26:49 UTC 2024 x86_64 User : www-root ( 1010) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/www-root/data/www/dev.artlot24.ru/bitrix/modules/main/lib/routing/ |
Upload File : |
<?php /** * Bitrix Framework * @package bitrix * @subpackage main * @copyright 2001-2020 Bitrix */ namespace Bitrix\Main\Routing; use Bitrix\Main\Type\ParameterDictionary; /** * @package bitrix * @subpackage main */ class Route { /** @var string Defined by user */ protected $uri; /** @var string uri with prefix */ protected $fullUri; /** @var string Defined by compile() */ protected $matchUri; /** @var array [name => pattern] Defined by compile() */ protected $parameters; /** @var ParameterDictionary Set by router->match() */ protected $parametersValues; /** @var callable */ protected $controller; /** @var Options */ protected $options; public function __construct($uri, $controller) { $this->uri = $uri; $this->controller = $controller; } /** * @return Options */ public function getOptions() { return $this->options; } /** * @param Options $options */ public function setOptions($options) { $this->options = $options; } /** * @return callable */ public function getController() { return $this->controller; } /** * @return array */ public function getParameters() { return $this->parameters; } /** * @return ParameterDictionary */ public function getParametersValues() { if ($this->parametersValues === null) { $this->parametersValues = new ParameterDictionary; } return $this->parametersValues; } public function getParameterValue($name) { return $this->getParametersValues()->get($name); } public function compile() { if ($this->matchUri !== null) { return; } $this->matchUri = "#^{$this->getUri()}$#"; $this->parameters = []; // there are parameters, collect them preg_match_all('/{([a-z0-9_]+)}/i', $this->getUri(), $matches); $parameterNames = $matches[1]; foreach ($parameterNames as $parameterName) { $pattern = null; // check options for custom pattern if ($this->options) { if ($this->options->hasWhere($parameterName)) { // custom pattern $pattern = $this->options->getWhere($parameterName); } elseif ($this->options->hasDefault($parameterName)) { // can be empty $pattern = '[^/]*'; } } if ($pattern === null) { // general case $pattern = '[^/]+'; } $this->parameters[$parameterName] = $pattern; // put pattern in uri $this->matchUri = str_replace( "{{$parameterName}}", "(?<{$parameterName}>{$pattern})", $this->matchUri ); } } public function compileFromCache($cacheData) { $this->matchUri = $cacheData['matchUri']; $this->parameters = $cacheData['parameters']; } public function getCompileCache() { $this->compile(); return [ 'matchUri' => $this->matchUri, 'parameters' => $this->parameters ]; } public function match($uriPath) { if (strpos($this->getUri(), '{') !== false) { // compile regexp $this->compile(); // match $result = preg_match($this->matchUri, $uriPath, $matches); if ($result) { // set parameters to the request $requestParameters = []; $parametersList = array_keys($this->parameters); foreach ($parametersList as $parameter) { if ($matches[$parameter] === '' && $this->options && $this->options->hasDefault($parameter)) { // set default value if optional parameter is empty $requestParameters[$parameter] = $this->options->getDefault($parameter); } else { $requestParameters[$parameter] = $matches[$parameter]; } } // set default values if parameter with the same name wasn't set in request // e.g. "RULE" => "download=1&objectId=\$1" if (!empty($defaultValues = $this->options->getDefault())) { foreach ($defaultValues as $parameter => $defaultValue) { if (!in_array($parameter, $parametersList)) { $requestParameters[$parameter] = $defaultValue; } } } return $requestParameters; } } else { if ($uriPath === $this->getUri()) { $requestParameters = []; // set default values if parameter with the same name wasn't set in request // e.g. "RULE" => "download=1&objectId=\$1" if (!empty($defaultValues = $this->options->getDefault())) { foreach ($defaultValues as $parameter => $defaultValue) { $requestParameters[$parameter] = $defaultValue; } } return $requestParameters ?: true; } } return false; } function getUri() { if ($this->fullUri === null) { $this->fullUri = $this->uri; // concat with option prefix and cache if ($this->options && $this->options->hasPrefix()) { $this->fullUri = $this->options->getFullPrefix().'/'.$this->uri; } } return $this->fullUri; } }