Package manager Composer

The problem

You have devoted many hours of your time to a particular PHP framework; you understand all of it’s cool libraries (database interaction, form builders, API integration etc) and can build projects quickly using this framework. Now, for whatever reason, you need to use a different framework, or perhaps can’t use one at all, for your new project. Assuming the former, you now have to learn all of their cool libraries, whilst assuming the latter, you must cope without any cool libraries at all. Suppose a world where you can start a new project, and choose which libraries you wanted to use, independent of any frameworks. Consider them project specific libraries that you can drag in to your project.

The solution

Composer is a package manager. It allows for developers to create and share packages, allowing other developers to plug them in to their project. It comprises a large repository of packages, whose popularity can be measured by its number of current downloads.

How it works

Put simply, you install PHP packages from the command line directly in to your current project directory. The package will only be available to that specific project. For those familiar with Drupal, this is the equivalent to installing modules on a per project basis, and in the same way that Drupal modules can be dependent on other modules, so too can Composer packages. Composer can automatically handle these dependencies for you.

Vs. Pear

Traditionally, PHP relied on its veteran package manage PEAR. The difference here is that PEAR will install it’s packages globally, meaning that the libraries become available to all projects on that server. Developing a PEAR package requires the code to be in a specific PEAR format, which is no good for libraries already written that would be worth giving to the community. As the community turns towards Composer, it is becoming rare to find a developer who actively uses PEAR, instead choosing a fully supported framework.

The future

Composer picked up a lot of support in 2012, and 2013 can expect to see an even wider spread adoption from the PHP community. In June 2012, there were 2,000 available Composer packages. In January 2013, there are now 7,000 packages. Similarly, in April 2012, Composer reported 200,000 package downloads for that month, compared to 2,000,000 (and counting) downloads for the month of January 2013. Given that many popular frameworks have already adopted Composer, it is sure to become an essential methodology for PHP developers.

Further Reading

Official website

Official package repository

Hands on introduction

This entry was posted in Managed Hosting. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>