Composer (software)
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. They began development in April 2011 and first released it on March 1, 2012. Composer is strongly inspired by Node.js's "npm" and Ruby's "bundler". The project's dependency solving algorithm started out as a PHP-based port of openSUSE's libzypp satsolver.
Composer runs from the command line and installs dependencies for an application. It also allows users to install PHP applications that are available on "Packagist" which is its main repository containing available packages. It also provides autoload capabilities for libraries that specify autoload information to ease usage of third-party code.
Syntax
Commands
Composer offers several parameters including :-
require
: add the library in parameter to the file composer.json, and install it. -
install
: install all libraries from composer.json. It's the command to use to download all PHP repository dependencies. -
update
: update all libraries from composer.json, according to the allowed versions mentioned into it. -
remove
: uninstall a library and remove it from composer.json.Libraries definition
composer require monolog/monolog
Versions
The different authorized versions of the libraries are defined by:Symbol | Role | Example |
>= | allows to extend the number. Moreover, we can use: >, <, <=. | "php": ">=5.5.9" includes PHP 7. |
!= | excludes a version. | |
- | defines a range of versions. | |
¦¦ | add possibles versions. | "symfony/symfony": "2.8 ¦¦ 3.0" regroups only these two versions. |
* | extends to all subversions. | "symfony/symfony": "3.1.*" includes the 3.1.1. |
~ | extends to the next versions of the same level. | "doctrine/orm": "~2.5" also concerns the 2.6, but neither the 2.4 nor the 3.0. |
^ | same as tilde, only if there is a backward compatibility. |
Supported frameworks
- Symfony version 2 and later
- Laravel version 4 and later
- CodeIgniter version 3.0 and later
- CakePHP version 3.0 and later
- FuelPHP version 2.0 and later
- Drupal version 8 and later
- TYPO3 version 6.2 and later
- SilverStripe version 3.0 later
- Magento version 2.0 later
- Yii version 1.1 and later
- Zend Framework version 1 and later
- Silex
- Lumen