Bitrix-D7  20.5.0
main/lib/request.php
См. документацию.
1 <?php
2 namespace Bitrix\Main;
3 
7 
8 /**
9  * Class Request contains current request
10  * @package Bitrix\Main
11  */
12 abstract class Request
14 {
15  /**
16  * @var Server
17  */
18  protected $server;
19 
20  protected $requestedPage = null;
21  protected $requestedPageDirectory = null;
22 
23  public function __construct(Server $server, array $request)
24  {
26 
27  $this->server = $server;
28  }
29 
30  public function addFilter(Type\IRequestFilter $filter)
31  {
32  $filteredValues = $filter->filter($this->values);
33 
34  if ($filteredValues != null)
35  $this->setValuesNoDemand($filteredValues);
36  }
37 
38  /**
39  * @return Server
40  */
41  public function getServer()
42  {
43  return $this->server;
44  }
45 
46  public function getPhpSelf()
47  {
48  return $this->server->getPhpSelf();
49  }
50 
51  public function getScriptName()
52  {
53  return $this->server->getScriptName();
54  }
55 
56  public function getRequestedPage()
57  {
58  if ($this->requestedPage === null)
59  {
60  $page = $this->getScriptName();
61  if (!empty($page))
62  {
63  $page = IO\Path::normalize($page);
64 
65  if (mb_substr($page, 0, 1) !== "/" && !preg_match("#^[a-z]:[/\\\\]#i", $page))
66  {
67  $page = "/".$page;
68  }
69  }
70  $this->requestedPage = $page;
71  }
72 
73  return $this->requestedPage;
74  }
75 
76  public function getRequestedPageDirectory()
77  {
78  if ($this->requestedPageDirectory === null)
79  {
81  $this->requestedPageDirectory = IO\Path::getDirectory($requestedPage);
82  }
84  }
85 
86  public function isAdminSection()
87  {
88  $requestedDir = $this->getRequestedPageDirectory();
89  return (mb_substr($requestedDir, 0, mb_strlen("/bitrix/admin/")) == "/bitrix/admin/"
90  || mb_substr($requestedDir, 0, mb_strlen("/bitrix/updates/")) == "/bitrix/updates/"
91  || (defined("ADMIN_SECTION") && ADMIN_SECTION == true)
92  || (defined("BX_PUBLIC_TOOLS") && BX_PUBLIC_TOOLS === true)
93  );
94  }
95 
96  /**
97  * Returns true if current request is AJAX
98  * @return bool
99  */
100  public function isAjaxRequest()
101  {
102  return
103  $this->server->get("HTTP_BX_AJAX") !== null ||
104  $this->server->get("HTTP_X_REQUESTED_WITH") === "XMLHttpRequest";
105  }
106 }
static normalize($path)
static getDirectory($path)
isAjaxRequest()
Returns true if current request is AJAX.
__construct(Server $server, array $request)
addFilter(Type\IRequestFilter $filter)
Represents server.
__construct(Base $connector)
Constructor.
Definition: resultview.php:40