= 0) { if (($pos2 = strpos($this->pattern, '/', 2)) !== false) { $this->host = substr($this->pattern, 0, $pos2); } else { $this->host = $this->pattern; } } else { $this->pattern = '/' . $this->pattern . '/'; } if (strpos($this->route, '<') !== false && preg_match_all('/<([\w._-]+)>/', $this->route, $matches)) { foreach ($matches[1] as $name) { $this->_routeParams[$name] = "<$name>"; } } $this->translatePattern(true); } /** * Prepares [[$pattern]] on rule initialization - replace parameter names by placeholders. * * @param bool $allowAppendSlash Defines position of slash in the param pattern in [[$pattern]]. * If `false` slash will be placed at the beginning of param pattern. If `true` slash position will be detected * depending on non-optional pattern part. */ private function translatePattern($allowAppendSlash) { $tr = [ '.' => '\\.', '*' => '\\*', '$' => '\\$', '[' => '\\[', ']' => '\\]', '(' => '\\(', ')' => '\\)', ]; $tr2 = []; $requiredPatternPart = $this->pattern; $oldOffset = 0; if (preg_match_all('/<([\w._-]+):?([^>]+)?>/', $this->pattern, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { $appendSlash = false; foreach ($matches as $match) { $name = $match[1][0]; $pattern = isset($match[2][0]) ? $match[2][0] : '[^\/]+'; $placeholder = 'a' . hash('crc32b', $name); // placeholder must begin with a letter $this->placeholders[$placeholder] = $name; if (array_key_exists($name, $this->defaults)) { $length = strlen($match[0][0]); $offset = $match[0][1]; $requiredPatternPart = str_replace("/{$match[0][0]}/", '//', $requiredPatternPart); if ( $allowAppendSlash && ($appendSlash || $offset === 1) && (($offset - $oldOffset) === 1) && isset($this->pattern[$offset + $length]) && $this->pattern[$offset + $length] === '/' && isset($this->pattern[$offset + $length + 1]) ) { // if pattern starts from optional params, put slash at the end of param pattern // @see https://github.com/yiisoft/yii2/issues/13086 $appendSlash = true; $tr["<$name>/"] = "((?P<$placeholder>$pattern)/)?"; } elseif ( $offset > 1 && $this->pattern[$offset - 1] === '/' && (!isset($this->pattern[$offset + $length]) || $this->pattern[$offset + $length] === '/') ) { $appendSlash = false; $tr["/<$name>"] = "(/(?P<$placeholder>$pattern))?"; } $tr["<$name>"] = "(?P<$placeholder>$pattern)?"; $oldOffset = $offset + $length; } else { $appendSlash = false; $tr["<$name>"] = "(?P<$placeholder>$pattern)"; } if (isset($this->_routeParams[$name])) { $tr2["<$name>"] = "(?P<$placeholder>$pattern)"; } else { $this->_paramRules[$name] = $pattern === '[^\/]+' ? '' : "#^$pattern$#u"; } } } // we have only optional params in route - ensure slash position on param patterns if ($allowAppendSlash && trim($requiredPatternPart, '/') === '') { $this->translatePattern(false); return; } $this->_template = preg_replace('/<([\w._-]+):?([^>]+)?>/', '<$1>', $this->pattern); $this->pattern = '#^' . trim(strtr($this->_template, $tr), '/') . '$#u'; // if host starts with relative scheme, then insert pattern to match any if (strncmp($this->host, '//', 2) === 0) { $this->pattern = substr_replace($this->pattern, '[\w]+://', 2, 0); } if (!empty($this->_routeParams)) { $this->_routeRule = '#^' . strtr($this->route, $tr2) . '$#u'; } } /** * @param UrlManager $manager the URL manager * @return UrlNormalizer|null * @since 2.0.10 */ protected function getNormalizer($manager) { if ($this->normalizer === null) { return $manager->normalizer; } return $this->normalizer; } /** * @param UrlManager $manager the URL manager * @return bool * @since 2.0.10 */ protected function hasNormalizer($manager) { return $this->getNormalizer($manager) instanceof UrlNormalizer; } /** * Parses the given request and returns the corresponding route and parameters. * @param UrlManager $manager the URL manager * @param Request $request the request component * @return array|bool the parsing result. The route and the parameters are returned as an array. * If `false`, it means this rule cannot be used to parse this path info. */ public function parseRequest($manager, $request) { if ($this->mode === self::CREATION_ONLY) { return false; } if (!empty($this->verb) && !in_array($request->getMethod(), $this->verb, true)) { return false; } $suffix = (string) ($this->suffix === null ? $manager->suffix : $this->suffix); $pathInfo = $request->getPathInfo(); $normalized = false; if ($this->hasNormalizer($manager)) { $pathInfo = $this->getNormalizer($manager)->normalizePathInfo($pathInfo, $suffix, $normalized); } if ($suffix !== '' && $pathInfo !== '') { $n = strlen($suffix); if (substr_compare($pathInfo, $suffix, -$n, $n) === 0) { $pathInfo = substr($pathInfo, 0, -$n); if ($pathInfo === '') { // suffix alone is not allowed return false; } } else { return false; } } if ($this->host !== null) { $pathInfo = strtolower($request->getHostInfo()) . ($pathInfo === '' ? '' : '/' . $pathInfo); } if (!preg_match($this->pattern, $pathInfo, $matches)) { return false; } $matches = $this->substitutePlaceholderNames($matches); foreach ($this->defaults as $name => $value) { if (!isset($matches[$name]) || $matches[$name] === '') { $matches[$name] = $value; } } $params = $this->defaults; $tr = []; foreach ($matches as $name => $value) { if (isset($this->_routeParams[$name])) { $tr[$this->_routeParams[$name]] = $value; unset($params[$name]); } elseif (isset($this->_paramRules[$name])) { $params[$name] = $value; } } if ($this->_routeRule !== null) { $route = strtr($this->route, $tr); } else { $route = $this->route; } Yii::debug("Request parsed with URL rule: {$this->name}", __METHOD__); if ($normalized) { // pathInfo was changed by normalizer - we need also normalize route return $this->getNormalizer($manager)->normalizeRoute([$route, $params]); } return [$route, $params]; } /** * Creates a URL according to the given route and parameters. * @param UrlManager $manager the URL manager * @param string $route the route. It should not have slashes at the beginning or the end. * @param array $params the parameters * @return string|bool the created URL, or `false` if this rule cannot be used for creating this URL. */ public function createUrl($manager, $route, $params) { if ($this->mode === self::PARSING_ONLY) { $this->createStatus = self::CREATE_STATUS_PARSING_ONLY; return false; } $tr = []; // match the route part first if ($route !== $this->route) { if ($this->_routeRule !== null && preg_match($this->_routeRule, $route, $matches)) { $matches = $this->substitutePlaceholderNames($matches); foreach ($this->_routeParams as $name => $token) { if (isset($this->defaults[$name]) && strcmp($this->defaults[$name], $matches[$name]) === 0) { $tr[$token] = ''; } else { $tr[$token] = $matches[$name]; } } } else { $this->createStatus = self::CREATE_STATUS_ROUTE_MISMATCH; return false; } } // match default params // if a default param is not in the route pattern, its value must also be matched foreach ($this->defaults as $name => $value) { if (isset($this->_routeParams[$name])) { continue; } if (!isset($params[$name])) { // allow omit empty optional params // @see https://github.com/yiisoft/yii2/issues/10970 if (in_array($name, $this->placeholders) && strcmp($value, '') === 0) { $params[$name] = ''; } else { $this->createStatus = self::CREATE_STATUS_PARAMS_MISMATCH; return false; } } if (strcmp($params[$name], $value) === 0) { // strcmp will do string conversion automatically unset($params[$name]); if (isset($this->_paramRules[$name])) { $tr["<$name>"] = ''; } } elseif (!isset($this->_paramRules[$name])) { $this->createStatus = self::CREATE_STATUS_PARAMS_MISMATCH; return false; } } // match params in the pattern foreach ($this->_paramRules as $name => $rule) { if (isset($params[$name]) && !is_array($params[$name]) && ($rule === '' || preg_match($rule, $params[$name]))) { $tr["<$name>"] = $this->encodeParams ? urlencode($params[$name]) : $params[$name]; unset($params[$name]); } elseif (!isset($this->defaults[$name]) || isset($params[$name])) { $this->createStatus = self::CREATE_STATUS_PARAMS_MISMATCH; return false; } } $url = $this->trimSlashes(strtr($this->_template, $tr)); if ($this->host !== null) { $pos = strpos($url, '/', 8); if ($pos !== false) { $url = substr($url, 0, $pos) . preg_replace('#/+#', '/', substr($url, $pos)); } } elseif (strpos($url, '//') !== false) { $url = preg_replace('#/+#', '/', trim($url, '/')); } if ($url !== '') { $url .= ($this->suffix === null ? $manager->suffix : $this->suffix); } if (!empty($params) && ($query = http_build_query($params)) !== '') { $url .= '?' . $query; } $this->createStatus = self::CREATE_STATUS_SUCCESS; return $url; } /** * Returns status of the URL creation after the last [[createUrl()]] call. * * @return null|int Status of the URL creation after the last [[createUrl()]] call. `null` if rule does not provide * info about create status. * @see $createStatus * @since 2.0.12 */ public function getCreateUrlStatus() { return $this->createStatus; } /** * Returns list of regex for matching parameter. * @return array parameter keys and regexp rules. * * @since 2.0.6 */ protected function getParamRules() { return $this->_paramRules; } /** * Iterates over [[placeholders]] and checks whether each placeholder exists as a key in $matches array. * When found - replaces this placeholder key with a appropriate name of matching parameter. * Used in [[parseRequest()]], [[createUrl()]]. * * @param array $matches result of `preg_match()` call * @return array input array with replaced placeholder keys * @see placeholders * @since 2.0.7 */ protected function substitutePlaceholderNames(array $matches) { foreach ($this->placeholders as $placeholder => $name) { if (isset($matches[$placeholder])) { $matches[$name] = $matches[$placeholder]; unset($matches[$placeholder]); } } return $matches; } /** * Trim slashes in passed string. If string begins with '//', two slashes are left as is * in the beginning of a string. * * @param string $string * @return string */ private function trimSlashes($string) { if (strncmp($string, '//', 2) === 0) { return '//' . trim($string, '/'); } return trim($string, '/'); } }
An Error occurred while handling another error: yii\web\HeadersAlreadySentException: Headers already sent in /var/www/vhosts/vassh.com.vn/vassh.vn/vendor/yiisoft/yii2/web/UrlRule.php on line 1. in /var/www/vhosts/vassh.com.vn/vassh.vn/vendor/yiisoft/yii2/web/Response.php:373 Stack trace: #0 /var/www/vhosts/vassh.com.vn/vassh.vn/vendor/yiisoft/yii2/web/Response.php(346): yii\web\Response->sendHeaders() #1 /var/www/vhosts/vassh.com.vn/vassh.vn/vendor/yiisoft/yii2/web/ErrorHandler.php(136): yii\web\Response->send() #2 /var/www/vhosts/vassh.com.vn/vassh.vn/vendor/yiisoft/yii2/base/ErrorHandler.php(135): yii\web\ErrorHandler->renderException() #3 [internal function]: yii\base\ErrorHandler->handleException() #4 {main} Previous exception: yii\base\UnknownClassException: Unable to find 'yii\web\UrlRule' in file: /var/www/vhosts/vassh.com.vn/vassh.vn/vendor/yiisoft/yii2/web/UrlRule.php. Namespace missing? in /var/www/vhosts/vassh.com.vn/vassh.vn/vendor/yiisoft/yii2/BaseYii.php:296 Stack trace: #0 [internal function]: yii\BaseYii::autoload() #1 [internal function]: spl_autoload_call() #2 /var/www/vhosts/vassh.com.vn/vassh.vn/vendor/yiisoft/yii2/caching/Cache.php(138): unserialize() #3 /var/www/vhosts/vassh.com.vn/vassh.vn/vendor/yiisoft/yii2/web/UrlManager.php(299): yii\caching\Cache->get() #4 /var/www/vhosts/vassh.com.vn/vassh.vn/vendor/yiisoft/yii2/web/UrlManager.php(236): yii\web\UrlManager->getBuiltRulesFromCache() #5 /var/www/vhosts/vassh.com.vn/vassh.vn/vendor/yiisoft/yii2/web/UrlManager.php(198): yii\web\UrlManager->buildRules() #6 /var/www/vhosts/vassh.com.vn/vassh.vn/vendor/yiisoft/yii2/base/BaseObject.php(109): yii\web\UrlManager->init() #7 [internal function]: yii\base\BaseObject->__construct() #8 /var/www/vhosts/vassh.com.vn/vassh.vn/vendor/yiisoft/yii2/di/Container.php(420): ReflectionClass->newInstanceArgs() #9 /var/www/vhosts/vassh.com.vn/vassh.vn/vendor/yiisoft/yii2/di/Container.php(171): yii\di\Container->build() #10 /var/www/vhosts/vassh.com.vn/vassh.vn/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get() #11 /var/www/vhosts/vassh.com.vn/vassh.vn/vendor/yiisoft/yii2/di/ServiceLocator.php(137): yii\BaseYii::createObject() #12 /var/www/vhosts/vassh.com.vn/vassh.vn/vendor/yiisoft/yii2/base/Module.php(748): yii\di\ServiceLocator->get() #13 /var/www/vhosts/vassh.com.vn/vassh.vn/vendor/yiisoft/yii2/base/Application.php(577): yii\base\Module->get() #14 /var/www/vhosts/vassh.com.vn/vassh.vn/vendor/yiisoft/yii2-gii/src/Module.php(89): yii\base\Application->getUrlManager() #15 /var/www/vhosts/vassh.com.vn/vassh.vn/vendor/yiisoft/yii2/base/Application.php(333): yii\gii\Module->bootstrap() #16 /var/www/vhosts/vassh.com.vn/vassh.vn/vendor/yiisoft/yii2/web/Application.php(70): yii\base\Application->bootstrap() #17 /var/www/vhosts/vassh.com.vn/vassh.vn/vendor/yiisoft/yii2/base/Application.php(279): yii\web\Application->bootstrap() #18 /var/www/vhosts/vassh.com.vn/vassh.vn/vendor/yiisoft/yii2/base/BaseObject.php(109): yii\base\Application->init() #19 /var/www/vhosts/vassh.com.vn/vassh.vn/vendor/yiisoft/yii2/base/Application.php(212): yii\base\BaseObject->__construct() #20 /var/www/vhosts/vassh.com.vn/vassh.vn/index.php(17): yii\base\Application->__construct() #21 {main}