Last Updated: February 25, 2016
·
544
· grevenx

Manage PHP project dependencies with composer

NodeJS programmers are used to npm and managing dependencies in a package.json file. Composer is solution that tries to solve much of the same things for PHP programmers.

It provides dependency management, central place for "bin" files and autoloading for composer-enabled projects that supports it. The official repo of composer packages is available at http://packagist.org where you can search for what you need.

To declare dependencies you create a packages.json file in your project:

{
    "require": {
        "monolog/monolog": "1.0.*"
    }
}

and to install the packages you use:

composer.phar install

This installs the dependencies into a directory called "vendor" and generates a "lock-file" with an overview of the versions for the dependencies that was installed so you can (and should) add this lockfile in your project's version-control system. When the project is deployed and you run composer.phar install again, the exact same versions of your dependencies will be installed on the deployed server without including the dependencies themselves in your version-control system.
(You will want to add *vendor/** to your .gitignore)*

Read more about composer at http://getcomposer.org/.

Bare in mind, the project is not yet considered stable and is frequently updated. It hasn't stopped great frameworks like Symfony, Silex and Propelorm to use it though