Bitrix-D7  20.5.0
main/lib/context.php
См. документацию.
1 <?php
2 /**
3  * Bitrix Framework
4  * @package bitrix
5  * @subpackage main
6  * @copyright 2001-2012 Bitrix
7  */
8 namespace Bitrix\Main;
9 
10 /**
11  * Context of current request.
12  */
13 class Context
14 {
15  /** @var Application */
16  protected $application;
17 
18  /** @var Response */
19  protected $response;
20 
21  /** @var Request */
22  protected $request;
23 
24  /** @var Server */
25  protected $server;
26 
27  /** @var string */
28  private $language;
29 
30  /** @var string */
31  private $site;
32 
33  /** @var Environment */
34  protected $env;
35 
36  /** @var \Bitrix\Main\Context\Culture */
37  protected $culture;
38 
39  /** @var array */
40  protected $params;
41 
42  /**
43  * Creates new instance of context.
44  *
45  * @param Application $application
46  */
48  {
49  $this->application = $application;
50  }
51 
52  /**
53  * Initializes context by request and response objects.
54  *
55  * @param Request $request
56  * @param Response $response
57  * @param Server $server
58  * @param Environment $env
59  */
60  public function initialize(Request $request, Response $response = null, Server $server, array $params = array())
61  {
62  $this->request = $request;
63  $this->response = $response;
64  $this->server = $server;
65  $this->params = $params;
66  }
67 
68  public function getEnvironment()
69  {
70  if ($this->env === null)
71  $this->env = new Environment($this->params["env"]);
72  return $this->env;
73  }
74 
75  /**
76  * Returns response object of the context.
77  *
78  * @return HttpResponse
79  */
80  public function getResponse()
81  {
82  return $this->response;
83  }
84 
85  /**
86  * Sets response of the context.
87  *
88  * @param Response $response Response.
89  * @return void
90  */
91  public function setResponse(Response $response)
92  {
93  $this->response = $response;
94  }
95 
96  /**
97  * Returns request object of the context.
98  *
99  * @return HttpRequest
100  */
101  public function getRequest()
102  {
103  return $this->request;
104  }
105 
106  /**
107  * Returns server object of the context.
108  *
109  * @return Server
110  */
111  public function getServer()
112  {
113  return $this->server;
114  }
115 
116  /**
117  * Returns backreference to Application.
118  *
119  * @return Application
120  */
121  public function getApplication()
122  {
123  return $this->application;
124  }
125 
126  /**
127  * Returns culture of the context.
128  *
129  * @return \Bitrix\Main\Context\Culture
130  */
131  public function getCulture()
132  {
133  if ($this->culture === null)
134  $this->culture = new Context\Culture();
135  return $this->culture;
136  }
137 
138  /**
139  * Returns current language (en, ru)
140  *
141  * @return string
142  */
143  public function getLanguage()
144  {
145  return $this->language;
146  }
147 
148  /**
149  * Returns current site
150  *
151  * @return string
152  */
153  public function getSite()
154  {
155  return $this->site;
156  }
157 
158  /**
159  * Sets culture of the context.
160  *
161  * @param \Bitrix\Main\Context\Culture $culture
162  */
164  {
165  $this->culture = $culture;
166  }
167 
168  /**
169  * Sets language of the context.
170  *
171  * @param string $language
172  */
173  public function setLanguage($language)
174  {
175  $this->language = $language;
176  }
177 
178  /**
179  * Sets site of the context.
180  *
181  * @param string $site
182  */
183  public function setSite($site)
184  {
185  $this->site = $site;
186  }
187 
188  /**
189  * Static method returns current instance of context.
190  *
191  * @static
192  * @return Context
193  */
194  public static function getCurrent()
195  {
197  return $application->getContext();
198  }
199 }
Base class for any application.
static getInstance()
Returns current instance of the Application.
Context of current request.
getCulture()
Returns culture of the context.
getSite()
Returns current site.
__construct(Application $application)
Creates new instance of context.
static getCurrent()
Static method returns current instance of context.
getResponse()
Returns response object of the context.
initialize(Request $request, Response $response=null, Server $server, array $params=array())
Initializes context by request and response objects.
setLanguage($language)
Sets language of the context.
getApplication()
Returns backreference to Application.
getServer()
Returns server object of the context.
setResponse(Response $response)
Sets response of the context.
getRequest()
Returns request object of the context.
setCulture(Context\Culture $culture)
Sets culture of the context.
setSite($site)
Sets site of the context.
getLanguage()
Returns current language (en, ru)
Represents server.