Views: 11884
Last Modified: 01.07.2014

Module API (classes) is not divided by databases. ORM takes care of all the twists and turns of work with a specific database.

No prefixes or suffixes shall be used in class names.

Each module API class may be located in a separate file with a name that coincides with the class name written in lower case. The classes located in the root of module namespace must be based in the files of the /lib module folder root. The classes located in subspaces inside the module namespace must be based in the files of the relevant subfolders of the /lib module folder.

For example, the Bitrix\Main\Application class must be located in the file /lib/application.php in respect of the main module root folder; the Bitrix\Main\IO\File class must be located in the file /lib/io/file.php in respect of the main module root folder; and the Bitrix\Forum\Message class must be located in the file /lib/message.php in respect of the root folder of the forum module.

If these naming rules are complied with, once a module is connected, its classes are uploaded automatically upon first call. No additional actions are needed for the registration and connection of files with classes.

Note: However, for performance reasons, additional registration and connection are recommended for classes that are used often.

Classes of the ORM entities (successors of the class Bitrix\Main\Entity\DataManager) constitute an exception from the class and file naming rules. The names of such classes are generated with the Table suffix. E.g., CultureTable, LanguageTable. But file names do not contain the table suffix. Such classes are also connected automatically.

Note: There is a possibility to register a class in the autoload system using the following method:
void Loader::registerAutoLoadClasses(
	$moduleName,
	array $arClasses
)

It can be used in order to merge small classes in one file.

Non-standard classes (partner’s classes) must be located in their own namespaces that coincide with the names of relevant partners. Each partner’s module determines its own subspace in the partner’s namespace that coincides with the module name without the partner’s name. E.g., for the module mycompany.catalog of the partner "Mycompany", the namespace will be MyCompany\Catalog. Other rules are the same as for standard modules.

The following instruction is used in order to connect a module in a new core:

mixed Loader::includeModule($moduleName);


Naming Rules

Classes

  • Classes must be named in UpperCamelCase.
  • Their name cannot contain any other symbols but for Latin letters.
  • Class name must be a noun. Unnecessary acronyms and abbreviations should be avoided.

Examples:

class User;
class UserInformation;

Methods

  • The methods, including class methods, must be named in lowerCamelCase.
  • Their name cannot contain any other symbols but for Latin letters.
  • Numbers may be used, provided that the name cannot be formed otherwise. E.g.: encodeBase64, getSha1Key.
  • The method name must start with a verb.
  • The name length must contain at least 3 characters.

Examples:

run();
setImage();
getName();

Pure data

  • Pure data, including class pure data, must be written in UPPER_REGISTER_WITH_A_FLATWORM_SEPARATOR.
  • May contain Latin letters, flatworm character, and numbers (except for the first position).

Examples:

DATE_TIME_FORMAT
LEVEL_7

Class Members, Method Parameters, and Variables

  • Must be named in a lowerCamelCase.
  • May not contain prefixes meaning membership in class, appurtenance to parameters, type, and other insignificant things. Example of unnecessary prefixes: $this->mAge, function setName($pName), $arrArray.
  • May contain Latin letters and numbers (but for the first position).

Examples:

$firstName = '';
$counter = 0;

Generally Acceptable Abbreviations of the Names of Variables and Methods

  • Abbreviations in the first position must be written in lower case letters, abbreviations in other positions must start with a capital letter, with all other letters being written in lowercase.
  • Class names should start with a upper case letter, with all other letters being written in lower case.

Example:

$xmlDocument
$mainXmlDocument
HttpParser

Abbreviations that are not generally acceptable (in Bitrix) cannot be used.




Courses developed by Bitrix24