Bitrix API

Loader

Class Loader loads required files, classes and modules. It is the only class which is included directly.

Table of Contents

Constants

ALPHA_LOWER  = "qwertyuioplkjhgfdsazxcvbnm"
ALPHA_UPPER  = "QWERTYUIOPLKJHGFDSAZXCVBNM"
BITRIX_HOLDER  = "bitrix"
LOCAL_HOLDER  = "local"
MODULE_DEMO  = 2
Returned by includeSharewareModule() if module works in demo mode
MODULE_DEMO_EXPIRED  = 3
Returned by includeSharewareModule() if the trial period is expired
MODULE_INSTALLED  = 1
Returned by includeSharewareModule() if module is installed
MODULE_NOT_FOUND  = 0
Returned by includeSharewareModule() if module is not found
SAFE_MODE  = false
Can be used to prevent loading all modules except main and fileman

Methods

autoLoad()  : mixed
PSR-4 compatible autoloader.
clearModuleCache()  : mixed
getDocumentRoot()  : string
Returns document root
getLocal()  : string|bool
Checks if file exists in /local or /bitrix directories
getNamespaces()  : array<string|int, mixed>
getPersonal()  : string|bool
Checks if file exists in personal directory.
includeComposerAutoload()  : void
Include autoload.php files from composer folder.
includeModule()  : bool
Includes a module by its name.
includeSharewareModule()  : int
Includes shareware module by its name.
registerAutoLoadClasses()  : mixed
Registers classes for autoloading.
registerClassAliases()  : void
Registers class aliases for autoloading.
registerHandler()  : mixed
Registers an additional autoload handler.
registerNamespace()  : mixed
Registers namespaces with custom paths.
requireClass()  : mixed
requireModule()  : bool
Includes module by its name, throws an exception in case of failure
setRequireThrowException()  : mixed
Changes requireModule behavior
unregisterNamespace()  : mixed
Unregisters a namespace.

Constants

ALPHA_LOWER

public mixed ALPHA_LOWER = "qwertyuioplkjhgfdsazxcvbnm"

ALPHA_UPPER

public mixed ALPHA_UPPER = "QWERTYUIOPLKJHGFDSAZXCVBNM"

BITRIX_HOLDER

public mixed BITRIX_HOLDER = "bitrix"

LOCAL_HOLDER

public mixed LOCAL_HOLDER = "local"

MODULE_DEMO

Returned by includeSharewareModule() if module works in demo mode

public mixed MODULE_DEMO = 2

MODULE_DEMO_EXPIRED

Returned by includeSharewareModule() if the trial period is expired

public mixed MODULE_DEMO_EXPIRED = 3

MODULE_INSTALLED

Returned by includeSharewareModule() if module is installed

public mixed MODULE_INSTALLED = 1

MODULE_NOT_FOUND

Returned by includeSharewareModule() if module is not found

public mixed MODULE_NOT_FOUND = 0

SAFE_MODE

Can be used to prevent loading all modules except main and fileman

public mixed SAFE_MODE = false

Methods

autoLoad()

PSR-4 compatible autoloader.

public static autoLoad(string $className) : mixed

https://www.php-fig.org/psr/psr-4/

Parameters
$className : string

clearModuleCache()

public static clearModuleCache(mixed $moduleName) : mixed
Parameters
$moduleName : mixed

getDocumentRoot()

Returns document root

public static getDocumentRoot() : string
Return values
string —

Document root

getLocal()

Checks if file exists in /local or /bitrix directories

public static getLocal(string $path[, string|null $root = null ]) : string|bool
Parameters
$path : string

File path relative to /local/ or /bitrix/

$root : string|null = null

Server document root, default self::getDocumentRoot()

Return values
string|bool —

Returns combined path or false if the file does not exist in both dirs

getNamespaces()

public static getNamespaces() : array<string|int, mixed>
Return values
array<string|int, mixed>

getPersonal()

Checks if file exists in personal directory.

public static getPersonal(string $path) : string|bool

If $_SERVER["BX_PERSONAL_ROOT"] is not set than personal directory is equal to /bitrix/

Parameters
$path : string

File path relative to personal directory

Return values
string|bool —

Returns combined path or false if the file does not exist

includeComposerAutoload()

Include autoload.php files from composer folder.

public static includeComposerAutoload() : void

includeModule()

Includes a module by its name.

public static includeModule(string $moduleName) : bool
Parameters
$moduleName : string

Name of the included module

Tags
throws
LoaderException
Return values
bool —

Returns true if module was included successfully, otherwise returns false

includeSharewareModule()

Includes shareware module by its name.

public static includeSharewareModule(string $moduleName) : int

Module must initialize constant _DEMO = Y in include.php to define demo mode. include.php must return false to define trial period expiration. Constants are used because it is easy to obfuscate them.

Parameters
$moduleName : string

Name of the included module

Return values
int —

One of the following constant: Loader::MODULE_NOT_FOUND, Loader::MODULE_INSTALLED, Loader::MODULE_DEMO, Loader::MODULE_DEMO_EXPIRED

registerAutoLoadClasses()

Registers classes for autoloading.

public static registerAutoLoadClasses(string $moduleName, array<string|int, mixed> $classes) : mixed

All the frequently used classes should be registered for autoloading (performance). It is not necessary to register rarely used classes. They can be found and loaded dynamically.

Parameters
$moduleName : string

Name of the module. Can be null if classes are not part of any module

$classes : array<string|int, mixed>

Array of classes with class names as keys and paths as values.

Tags
throws
LoaderException

registerClassAliases()

Registers class aliases for autoloading.

public static registerClassAliases(array<string|int, mixed> $aliases) : void
Parameters
$aliases : array<string|int, mixed>

Array with aliases as keys and classes as values.

registerHandler()

Registers an additional autoload handler.

public static registerHandler(callable $handler) : mixed
Parameters
$handler : callable

registerNamespace()

Registers namespaces with custom paths.

public static registerNamespace(string $namespace, string $path) : mixed

e.g. ('Bitrix\Main\Dev', '/home/bitrix/web/site/bitrix/modules/main/dev/lib')

Parameters
$namespace : string

A namespace prefix.

$path : string

An absolute path.

requireClass()

public static requireClass(string $className) : mixed
Parameters
$className : string
Tags
throws
LoaderException

requireModule()

Includes module by its name, throws an exception in case of failure

public static requireModule(string $moduleName) : bool
Parameters
$moduleName : string
Tags
throws
LoaderException
Return values
bool

setRequireThrowException()

Changes requireModule behavior

public static setRequireThrowException(bool $requireThrowException) : mixed
Parameters
$requireThrowException : bool

unregisterNamespace()

Unregisters a namespace.

public static unregisterNamespace(string $namespace) : mixed
Parameters
$namespace : string

        
On this page

Search results