Views: 12082
Last Modified: 27.05.2021

Application is an object responsible for core initialization.

Application is the entry base point (router) for query to (kernel) core global entities: connection with data sources, managed cache, etc. Also, the application contains global data that belongs to the site itself and do not depend on a specific hit. I.e. the application is an unaltered part not dependent on a specific hit.

Any specific class of application is a successor of the abstract class Bitrix\Main\Application.

The specific class Bitrix\Main\HttpApplication is responsible for a regular http hit on the site.

The application supports the Singleton template. I.e. as a part of the hit there is only one copy of a specific type of application. It can be obtained using the instruction:

$application = Application::getInstance();

Context is an object responsible for a specific hit. It contains a query of a current hit, response to it, and also the server parameters of the current hit. I.e. it is a variable part that depends on the current hit.

Any specific class of a context is a successor of the abstract class Bitrix\Main\Context. Two specific classes of the context are supported – Bitrix\Main\HttpContext and Bitrix\Main\CliContext. The specific class Bitrix\Main\HttpContext is responsible for a regular http hit on the site.

The following code may be used in order to obtain a context of the current hit execution:

$context = Application::getInstance()->getContext();

If the application of the Bitrix\Main\HttpApplication type was initiated, this call will bring an instance of the Bitrix\Main\HttpContext context type.

The context contains a query of the current hit. In order to receive the query the following code may be used:

$context = Application::getInstance()->getContext();
$request = $context->getRequest();

Note: In all the examples, a full form of record is used (sometimes without indicating name spaces) that permits you to obtain the result from any code point. However, short forms may exist for this specific code point in order to access the result.

A request is a class instance that is a successor of the Bitrix\Main\Request class. In case of a normal http request the request will be a class instance of Bitrix\Main\HttpRequest that extends Bitrix\Main\Request. This class is a dictionary providing access to “key-value” pairs of incoming parameters.

The following code may be used in order to access an incoming parameter transmitted by the GET or POST methods:

$value = $request->get("some_name");
$value = $request["some_name"];

Note: Code $value = $request["some_name"]; returns string processed by the security module filters. However, this doesn't signify about its security, all depends on how it will be used further.

Other useful query methods:

$value = $request->getQuery("some_name");   // receive GET parameter
$value = $request->getPost("some_name");   // receive POST parameter
$value = $request->getFile("some_name");   // receive downloaded file
$value = $request->getCookie("some_name");   // receive cookie value
$uri = $request->getRequestUri();   // receive an address requested
$method = $request->getRequestMethod();   // receive a request method
$flag = $request->isPost();      // true - POST-request, otherwise false

Courses developed by Bitrix24