Composer a new era of PHP dependency management

Source: Internet
Author: User
Tags pear composer install

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.