Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
context.php
1<?php
2
4
6
12final class Context
13{
14 private $url;
15
19 public function __construct()
20 {
21 $this->url = $this->getCurrentUrl();
22 }
23
27 public function setUrl(string $url): void
28 {
29 $this->url = $url;
30 }
31
35 public function getUrl(): string
36 {
37 return $this->url;
38 }
39
43 private function getCurrentUrl(): string
44 {
45 $request = Main\Application::getInstance()->getContext()->getRequest();
46
47 $requestUri = null;
48 $host = null;
49 if (class_exists('\LandingPubComponent'))
50 {
51 $landingInstance = \LandingPubComponent::getMainInstance();
52 if ($landingInstance)
53 {
54 $context = Main\Context::getCurrent();
55
56 $realFilePath = $context->getServer()->get('REAL_FILE_PATH');
57 if (!$realFilePath)
58 {
59 $realFilePath = $_SERVER['REAL_FILE_PATH'] ?? null;
60 }
61 if (!$realFilePath)
62 {
63 $realFilePath = $context->getServer()->get('SCRIPT_NAME');
64 }
65
66 $realFilePath = str_replace('/index.php', '/', $realFilePath);
67 $requestUri = $request->getRequestUri();
68
69 $landingUrl = \Bitrix\Landing\Site::getPublicUrl($landingInstance['SITE_ID']);
70 if (mb_strpos($landingUrl, $realFilePath) === false)
71 {
72 $requestUri = str_replace($realFilePath.$landingInstance['SITE_ID'], '', $requestUri);
73 }
74
75 $uri = new Main\Web\Uri($landingUrl);
76 $host = $uri->getHost();
77 }
78 }
79
80 if (!$host)
81 {
82 $host = $request->getHttpHost();
83 }
84
85 if (!$requestUri)
86 {
87 $requestUri = $request->getRequestUri();
88 }
89
90 return ($request->isHttps() ? "https://" : "http://").$host.$requestUri;
91 }
92}