I have been a PHP developer for some years, and I have always found it hard to maintain dependencies on my projects. You had to download this and that, use different loaders for different libraries, create a bootstrap and if you are lucky it works!

But now all that have changed with composer, and if your libraries follow the PSR-0 standard the composer will configure and use the autoloader for you as well.

Composer is a command-line tool that installs packages, inspired by NPM and Bundler, it contains an dependency solver that is able to recursively resolve package dependencies.



All you should do is create a composer.json file into your project where you will state your dependencies and run php composer.phar install. Packeges are registered at packagist.org and are easy to depend on, but you can also use custom/other repositories as well.

Let’s take an example, I have created a zend framework skeleton application that use composer, check it out and downloaded from here, open the composer.json file to take a look, on this file I have stated the dependencies for this application, in this case zend framework 2 beta 5,

{
    "name": "empirio/zf2skeleton",
    "description": "ZF2 skeleton application",
    "homepage": "http://www.empirio.no/",
    "require": {
        "php": ">=5.3.3",
        "zendframework/zendframework": "2.0.0beta5"
    }
}

Line 2-4 are self-explained, on line 5 we tell the composer the requires for our applications, in this case we have 2 requirements, one, php version equal or larger than 5.3.3 and the zend framework 2 beta 5, the package name for zf2 on packagist.org is “zendframework/zendframework” and the tag for beta 5 is “2.0.0beta5”.

Now download the skeleton from github (zf2skeleton) and run command from the terminal to install the dependencies:

php composer.phar install

As u can see inside the vendor folder the composer installed the zend framework 2 beta 5 for you.

For more information about Composer. Check out their webpage at getcomposer.org.