Views: 4809 (Data available since 06.02.2017)
The notion of name spaces permits giving system elements clearer names, getting rid of numerous name prefixes, and also avoiding potential conflicts. All classes delivered in a standard installation package must be located in the Bitrix name space that does not overlap either with PHP or with partner implementations. Each standard module determines its subspace in the Bitrix name space which coincides with the module name. For example, for the forum module Bitrix\Forum will be the name space, and for the main module – Bitrix\Main.
. For partner classes, the namespace can be as follows:
class CountersTable extends Entity\DataManager
This means that this class (in
/lib/) belongs to the module asd.metrika and it can be addressed as follows (after the indicated module is connected):
The class itself is located in the file
If necessary, a module may organize subspaces inside its name space. For example, Bitrix\Main\IO, Bitrix\Forum\Somename\Somename2. But this option should be used only if it is justified for the organization of a correct architecture of this module.
- Name spaces must be named in “UpperCamelCase.”
- Names cannot contain any symbols but for Latin letters.
- Class name must be a noun. Unnecessary acronyms and abbreviations should be avoided.
Abbreviations that are not generally accepted (in Bitrix Framework) cannot be used.
The examples that are provided does do not mention name spaces. It make the text more readable and easier to comprehend. Prior using the examples provided in the documentation, a name space must be added.
It ca be done as follows:
- By using PHPdoc;
- By using IDE;
- additionally, the documentation context usually clarifies which class is described.
Full address line can be abridged. Instead
\Bitrix\Main\Class::Function() you can specify
Synonyms also can be used instead of long name spaces. To do it,
use is inserted. For example, the following long structure is available:
To abridge it, declare a synonym at the start of the file and use an abridged variant of the call afterwards: