$language = self::getLangByUrl($url); self::$current = ($language === null) ? self::getDefaultLang() : $language; Yii::$app->language = self::$current->local; } //Получения объекта языка по умолчанию static function getDefaultLang() { if (($list = strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']))) { if (preg_match_all('/([a-z]{1,8}(?:-[a-z]{1,8})?)(?:;q=([0-9.]+))?/', $list, $list)) { $language = array_combine($list[1], $list[2]); foreach ($language as $n => $v) { $k = strtok($n, '-'); if ($k=='uk') $k='ua'; /*------------------------------*/ if (!isset($lang[$k])) $lang[$k] = $v ? $v : 1;
} //Получения объекта языка по умолчанию static function getDefaultLang() { if (($list = strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']))) { if (preg_match_all('/([a-z]{1,8}(?:-[a-z]{1,8})?)(?:;q=([0-9.]+))?/', $list, $list)) { $language = array_combine($list[1], $list[2]); foreach ($language as $n => $v) { $k = strtok($n, '-');
} //Установка текущего объекта языка и локаль пользователя static function setCurrent($url = null) { $language = self::getLangByUrl($url); self::$current = ($language === null) ? self::getDefaultLang() : $language; Yii::$app->language = self::$current->local; } //Получения объекта языка по умолчанию static function getDefaultLang() {
$this->_lang_url = $this->getUrl(); $url_list = explode('/', $this->_lang_url); $lang_url = isset($url_list[1]) ? $url_list[1] : null; SysLang::setCurrent($lang_url); if( $lang_url !== null && $lang_url === SysLang::getCurrent()->lang_kod && strpos($this->_lang_url, SysLang::getCurrent()->lang_kod) === 1 ) { $this->_lang_url = substr($this->_lang_url, strlen(SysLang::getCurrent()->lang_kod)+1); }
return $this->_lang_url; } protected function resolvePathInfo() { $pathInfo = $this->getLangUrl(); if (($pos = strpos($pathInfo, '?')) !== false) { $pathInfo = substr($pathInfo, 0, $pos); } $pathInfo = urldecode($pathInfo);
* Note, the returned path info is already URL-decoded. * @throws InvalidConfigException if the path info cannot be determined due to unexpected server configuration */ public function getPathInfo() { if ($this->_pathInfo === null) { $this->_pathInfo = $this->resolvePathInfo(); } return $this->_pathInfo; } /**
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);
*/ public function parseRequest($request) { if ($this->enablePrettyUrl) { /* @var $rule UrlRule */ foreach ($this->rules as $rule) { $result = $rule->parseRequest($this, $request); if (YII_DEBUG) { Yii::debug([ 'rule' => method_exists($rule, '__toString') ? $rule->__toString() : get_class($rule), 'match' => $result !== false, 'parent' => null, ], __METHOD__);
* Resolves the current request into a route and the associated parameters. * @return array the first element is the route, and the second is the associated parameters. * @throws NotFoundHttpException if the request cannot be resolved. */ public function resolve() { $result = Yii::$app->getUrlManager()->parseRequest($this); if ($result !== false) { list($route, $params) = $result; if ($this->_queryParams === null) { $_GET = $params + $_GET; // preserve numeric keys } else { $this->_queryParams = $params + $this->_queryParams;
* @throws NotFoundHttpException if the requested route is invalid */ public function handleRequest($request) { if (empty($this->catchAll)) { try { list($route, $params) = $request->resolve(); } catch (UrlNormalizerRedirectException $e) { $url = $e->url; if (is_array($url)) { if (isset($url[0])) { // ensure the route is absolute $url[0] = '/' . ltrim($url[0], '/');
{ try { $this->state = self::STATE_BEFORE_REQUEST; $this->trigger(self::EVENT_BEFORE_REQUEST); $this->state = self::STATE_HANDLING_REQUEST; $response = $this->handleRequest($this->getRequest()); $this->state = self::STATE_AFTER_REQUEST; $this->trigger(self::EVENT_AFTER_REQUEST); $this->state = self::STATE_SENDING_RESPONSE; $response->send();
require __DIR__ . '/../../common/config/main.php', require __DIR__ . '/../../common/config/main-local.php', require __DIR__ . '/../config/main.php', require __DIR__ . '/../config/main-local.php' ); (new yii\web\Application($config))->run();