Composer is a dependency manager for PHP. Drupal can be updated through composer using the command line.
Composer is an application-level package manager for the PHP programming language that provides a standard format for managing dependencies of PHP software and required libraries. It was developed by Nils Adermann and Jordi Boggiano, who continue to manage the project.
Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you. Drupal uses Composer to manage the various libraries that it depends on. Modules can also use Composer to include 3rd party libraries.
Drupal update through composer using the following command.
To update Drupal using composer, run the command 'composer update drupal/core --with-dependencies'
Using Composer with Drupal 8
There are many benefits to using Composer. In short, it allows us to systematically manage a sprawling list of dependencies (and their subsidiary dependencies). It assists with locating, downloading, validating, and loading said packages, all while ensuring that exactly the right versions for each package are used.
Composer.json
Composer retrieves information from packagist.org to download packages, Drupal projects are not listed on Packagist, instead, Drupal.org provides its own repository of composer metadata for Drupal projects.
The Composer template, already includes it in therepositories ofcomposer.json:
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
}
],
Core version
In Composer, Drupal core is a package like any other. So it is added to your project by adding a dependency to your composer.json.
Adding the following information to the composer.json will download the latest Drupal 7 release and place it in the web/-folder of the Composer project.
{
"require": {
"composer/installers": "~1.0",
"drupal/drupal": "7.*"
},
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/7"
}
],
"extra": {
"installer-paths": {
"web/": [
"type:drupal-core"
]
}
}
}
With Drupal 8 we can choose the same approach ("drupal/drupal": "8.*") or we can use the subtree-split of the core-directory ("drupal/core": "8.*").
You can use the ready to go template for each version: Branch 8.x for Drupal 8 or Branch 7.x for Drupal 7
Projects
All Drupal projects to be retrieved should be added as dependencies in semantic versioning format.
The following will download the Chaos tool suite (ctools) module version 1.4 for Drupal 7.
{
"require": {
"drupal/ctools": "1.4"
}
}
The module will be placed under sites/all/modules/contrib/.
You can also run php composer.phar require drupal/ctools from the command line in the root directory of the project. This will prompt for any additional information needed and update composer.json accordingly.
Since many Drupal projects are not available from the default Composer package repository Packagist, they will be downloaded from the Drupal repository defined in the composer.json
No comments:
Post a Comment