Views: 4472
Last Modified: 30.03.2022
Composer - is package app level manager for PHP programming language, that offers tools for managing dependencies in PHP application.
In the version 18.0.5 we started to use composer inside the product in development mode. It will be required, if you would like to use such advantages, as ORM class annotation and generally in CLI command line interface. If you already use composer in your Bitrix24 project, we have prepared a completed integration profile with your dependencies configuration.
First, you need to have an installed composer. The installation manual is available at the official website.
Below description will be based in the tact that composer is installed globally and is called by a simple command:
$ composer -V
Composer version 1.6.5 2018-05-04 11:44:59
Dependency configuration
1. You are not using composer in the project yet
Set dependencies from our bitrix/composer-bx.json
:
$ cd bitrix
$ COMPOSER=composer-bx.json composer install
After that, folder bitrix/vendor
is created with necessary libraries installed. When you want to specify another location for this directory, you need to create your own composer.json - look up the second option for dependencies config below.
2. You need your own composer.json configuration
Be default, system awaits to see your file composer.json
in the folder bitrix
, but we recommend to locate it somewhere outside DOCUMENT_ROOT
(for it not to be available publicly). In this case, specify the path to file in .settings.php, for it's configuration to be used in the product.
File .settings.php:
<?php
return [
'composer' => [
'value' => ['config_path' => '/path/to/your/composer.json']
],
// ...
];
Inside, connect our file with dependencies bitrix/composer-bx.json
via the plugin Composer Merge Plugin. Minimally, your composer.json must contain plugin call and our configuration connection.
File composer.json (can be copied from bitrix/composer.json.example
):
{
"require": {
"wikimedia/composer-merge-plugin": "dev-master"
},
"extra": {
"merge-plugin": {
"require": [
"/path/to/bitrix/composer-bx.json"
]
}
}
}
Instead of /path/to/bitrix/
you need to specify a real path to folder bitrix
.
You can add your dependencies and settings. For example, to directly specify path to vendor
folder (by default it will be in the same location as the file composer.json), use the command "vendor-dir"
.
File composer.json:
{
"require": {
"wikimedia/composer-merge-plugin": "dev-master"
},
"config": {
"vendor-dir": "../../vendor"
},
"extra": {
"merge-plugin": {
"require": [
"/path/to/bitrix/composer-bx.json"
]
}
}
}
After describing your configuration, install libraries:
$ composer install
Now you can use the advantages of composer in your project, connecting the file vendor/autoload.php. When using the CLI-commands, it is connected automatically.