Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
httpcontext.php
1<?php
2
3namespace Bitrix\Main;
4
7
12class HttpContext extends Context
13{
14 public const CACHE_TTL = 86400;
15
22 {
23 parent::__construct($application);
24 }
25
26 public function rewriteUri($url, $queryString, $redirectStatus = null)
27 {
29 $request->modifyByQueryString($queryString);
30
31 $this->server->rewriteUri($url, $queryString, $redirectStatus);
32 }
33
34 public function transferUri($url, $queryString)
35 {
37 $request->modifyByQueryString($queryString);
38
39 $this->server->transferUri($url, $queryString);
40 }
41
48 public function initializeCulture($definedSite = null, $definedLanguage = null): void
49 {
50 $request = $this->getRequest();
51
52 $language = null;
53 $culture = null;
54 $site = null;
55
56 if ($definedSite === null && $request->isAdminSection())
57 {
58 $lang = $request->get('lang');
59 if ($lang == '')
60 {
61 $lang = Config\Option::get('main', 'admin_lid', 'ru');
62 }
63
64 if ($lang != '')
65 {
66 $language = Localization\LanguageTable::getList([
67 'filter' => ['=LID' => $lang, '=ACTIVE' => 'Y'],
68 'cache' => ['ttl' => static::CACHE_TTL],
69 ])->fetchObject();
70 }
71
72 if (!$language)
73 {
74 // no language found - get default
75 $language = Localization\LanguageTable::getList([
76 'filter' => ['=ACTIVE' => 'Y'],
77 'order' => ['DEF' => 'DESC'],
78 'cache' => ['ttl' => static::CACHE_TTL],
79 ])->fetchObject();
80 }
81
82 if ($language)
83 {
84 $culture = Localization\CultureTable::getByPrimary($language->getCultureId(), ['cache' => ['ttl' => static::CACHE_TTL]])->fetchObject();
85 }
86 }
87 else
88 {
89 if ($definedSite !== null)
90 {
91 $site = SiteTable::getByPrimary($definedSite, ['cache' => ['ttl' => static::CACHE_TTL]])->fetch();
92 if (!$site)
93 {
94 throw new SystemException('Incorrect site: ' . $definedSite . '.');
95 }
96 }
97 else
98 {
99 // get the site by domain or path
100 $site = SiteTable::getByDomain($request->getHttpHost(), $request->getRequestedPageDirectory());
101 }
102
103 if ($site)
104 {
105 $languageId = $definedLanguage ?? $site['LANGUAGE_ID'];
106 $language = Localization\LanguageTable::getByPrimary($languageId, ['cache' => ['ttl' => static::CACHE_TTL]])->fetchObject();
107
108 $culture = Localization\CultureTable::getByPrimary($site['CULTURE_ID'], ['cache' => ['ttl' => static::CACHE_TTL]])->fetchObject();
109 }
110 }
111
112 if ($culture === null || $language === null)
113 {
114 throw new SystemException("Culture not found, or there are no active sites or languages.");
115 }
116
117 $this->setLanguage($language);
118 $this->setCulture($culture);
119
120 if ($site)
121 {
123 }
124 }
125}
setLanguage($language)
Definition context.php:201
setCulture(Context\Culture $culture)
Definition context.php:189
rewriteUri($url, $queryString, $redirectStatus=null)
transferUri($url, $queryString)
initializeCulture($definedSite=null, $definedLanguage=null)
__construct(HttpApplication $application)
static getByPrimary($primary, array $parameters=array())
static getByDomain(string $host, string $directory)
Definition site.php:141