For modern languages, Package Manager is basically standard. Java has maven,python have Pip,ruby have Gem,nodejs have NPM. PHP is pear, but pear pits a lot:
Dependency processing prone to problems
Very complex configuration
Hard-to-use command-line interface
Fortunately, we have composer,php rely on the management of the weapon. It's open source, it's easy to use, and it's easy to submit your own package.
Installing composer
Composer requires PHP 5.3.2+ to run.
$ CURL-SS Https://getcomposer.org/installer | Php
This command will be composer.phar
downloaded to the current directory. PHAR (PHP compression package) is a compressed format that can be run directly under the command line.
You can use the --install-dir
option to install composer to the specified directory, for example:
$ CURL-SS Https://getcomposer.org/installer | PHP----install-dir=bin
Of course, you can also do a global installation:
$ CURL-SS Https://getcomposer.org/installer | php$ MV Composer.phar/usr/local/bin/composer
You can also use the homebrew installation under Mac OS x:
Brew Tap Josegonzalez/homebrew-phpbrew Install Josegonzalez/php/composer
However, it is usually only composer.phar
possible to add a location to PATH
it, not necessarily a global installation.
Claim dependent
Create a file in the project directory composer.json
that indicates dependencies, for example, your project relies on Monolog:
{"Require": {"Monolog/monolog": "1.2.*"}}
Installation dependencies
Installation dependencies are simple, just run in the project directory:
Composer Install
If there is no global installation, then run:
PHP Composer.phar Install
Auto Load
Composer provides an auto-load feature that simply includes the following line in the initialization section of your code:
Require ' vendor/autoload.php ';
Module Warehouse
Packagist.org is a warehouse of composer, where many well-known PHP libraries can be found. You can also submit your own work.
Advanced Features
The above describes the basic usage of composer. Composer also has some advanced features that, although not required, can often be handy for PHP development.
Project Home
For more information, please visit Composer's homepage.
Domestic mirror
http://pkg.phpcomposer.com/
Composer a new era of PHP dependency management