Bitrix-D7  20.5.0
main/lib/server.php
См. документацию.
1 <?php
2 namespace Bitrix\Main;
3 
5 
6 /**
7  * Represents server.
8  */
9 class Server
10  extends ParameterDictionary
11 {
12  /**
13  * Creates server object.
14  *
15  * @param array $arServer
16  */
17  public function __construct(array $arServer)
18  {
19  if (isset($arServer["DOCUMENT_ROOT"]))
20  $arServer["DOCUMENT_ROOT"] = rtrim($arServer["DOCUMENT_ROOT"], "/\\");
21 
22  parent::__construct($arServer);
23  }
24 
25  public function addFilter(Type\IRequestFilter $filter)
26  {
27  $filteredValues = $filter->filter($this->values);
28 
29  if ($filteredValues != null)
30  $this->setValuesNoDemand($filteredValues);
31  }
32 
33  /**
34  * Returns server document root.
35  *
36  * @return string | null
37  */
38  public function getDocumentRoot()
39  {
40  return $this->get("DOCUMENT_ROOT");
41  }
42 
43  /**
44  * Returns custom root folder.
45  * Server variable BX_PERSONAL_ROOT is used. If empty - returns /bitrix.
46  *
47  * @return string | null
48  */
49  public function getPersonalRoot()
50  {
51  $r = $this->get("BX_PERSONAL_ROOT");
52  if ($r == null || $r == "")
53  $r = "/bitrix";
54 
55  return $r;
56  }
57 
58  /**
59  * Returns server http host.
60  *
61  * @return string | null
62  */
63  public function getHttpHost()
64  {
65  return $this->get("HTTP_HOST");
66  }
67 
68  /**
69  * Returns server name.
70  *
71  * @return string | null
72  */
73  public function getServerName()
74  {
75  return $this->get("SERVER_NAME");
76  }
77 
78  /**
79  * Returns server address.
80  *
81  * @return string | null
82  */
83  public function getServerAddr()
84  {
85  return $this->get("SERVER_ADDR");
86  }
87 
88  /**
89  * Returns remote address.
90  * @return string|null
91  */
92  public function getRemoteAddr()
93  {
94  return $this->get("REMOTE_ADDR");
95  }
96 
97  /**
98  * Returns user agent.
99  * @return string|null
100  */
101  public function getUserAgent()
102  {
103  return $this->get("HTTP_USER_AGENT");
104  }
105 
106  /**
107  * Returns server port.
108  *
109  * @return string | null
110  */
111  public function getServerPort()
112  {
113  return $this->get("SERVER_PORT");
114  }
115 
116  public function getRequestScheme()
117  {
118  return $this->get("REQUEST_SCHEME");
119  }
120 
121  /**
122  * Returns requested uri.
123  * /index.php/test1/test2?login=yes&back_url_admin=/
124  *
125  * @return string | null
126  */
127  public function getRequestUri()
128  {
129  return $this->get("REQUEST_URI");
130  }
131 
132  /**
133  * Returns requested method.
134  *
135  * @return string | null
136  */
137  public function getRequestMethod()
138  {
139  return $this->get("REQUEST_METHOD");
140  }
141 
142  /**
143  * Returns PHP_SELF.
144  * /index.php/test1/test2
145  *
146  * @return string | null
147  */
148  public function getPhpSelf()
149  {
150  return $this->get("PHP_SELF");
151  }
152 
153  /**
154  * Returns SCRIPT_NAME.
155  * /index.php
156  *
157  * @return string | null
158  */
159  public function getScriptName()
160  {
161  return $this->get("SCRIPT_NAME");
162  }
163 
164  public function rewriteUri($url, $queryString, $redirectStatus = null)
165  {
166  $this->values["REQUEST_URI"] = $url;
167  $this->values["QUERY_STRING"] = $queryString;
168  if ($redirectStatus != null)
169  $this->values["REDIRECT_STATUS"] = $redirectStatus;
170  }
171 
172  public function transferUri($url, $queryString = "")
173  {
174  $this->values["REAL_FILE_PATH"] = $url;
175  if ($queryString != "")
176  {
177  if (!isset($this->values["QUERY_STRING"]))
178  $this->values["QUERY_STRING"] = "";
179  if (isset($this->values["QUERY_STRING"]) && ($this->values["QUERY_STRING"] != ""))
180  $this->values["QUERY_STRING"] .= "&";
181  $this->values["QUERY_STRING"] .= $queryString;
182  }
183  }
184 }
Represents server.
getServerAddr()
Returns server address.
getPhpSelf()
Returns PHP_SELF.
rewriteUri($url, $queryString, $redirectStatus=null)
getServerPort()
Returns server port.
getRemoteAddr()
Returns remote address.
addFilter(Type\IRequestFilter $filter)
getUserAgent()
Returns user agent.
getHttpHost()
Returns server http host.
getScriptName()
Returns SCRIPT_NAME.
transferUri($url, $queryString="")
getPersonalRoot()
Returns custom root folder.
getDocumentRoot()
Returns server document root.
getRequestMethod()
Returns requested method.
getServerName()
Returns server name.
getRequestUri()
Returns requested uri.
__construct(array $arServer)
Creates server object.
__construct(Base $connector)
Constructor.
Definition: resultview.php:40