Why Composer Matters

I've heard about composer long before I started using it. I couldn't understand why it's so much cooler than downloading dependencies manually. I couldn't understand why it's worth running composer install after every code fetch.

This article is for guys like me in the past. If you're already using composer you can stop reading.

Easy installing

Writing one command in console is really faster then download+unzip. But usually you have to do something to attach library into your code. With composer you don't. Library is visible in your project without any code modifications.

Easy updating

To update dependencies you just need to run composer update and hope everything still works. You don't need to repeat download+unzip cycle for every dependency.

The bonus is you are sure nobody edited dependencies code. Yep, that's illegal but it happens.

Easy autoloading

Before composer every library had to care about autoloading. Some people created files like load.php that include every file in liblary. Some people created their own autoloading functions that conflicted with frameworks. Now no one should care about autoloading - composer does.

Easy components creation

One time I created a facebook api client wrapper with bells and whistles. And then I wanted to publish it on github. Here's when problem occured. Of course it depends on facebook client. So I could:

  1. Inject facebook client into wrapper project (and update it from time to time).
  2. Create an ugly interface and make everyone download client and inject it.

My solution was brilliant. I published nothing.

But with composer if your small-but-cool library depends on something - that's not a problem. You just declare it and everything works.

Easy deploy

Imagine the situation: you have no unit tests. You project is big enough and there's one small class which uses one php extension.

You deploy you project to new server and everything seems to be working. It doesn't work because that php extension is disabled but you dont't notice it. Bad situation.

You can setup your system requirements like php version and installed extensions in composer.json. It will check it on every install and inform you if something is wrong.

P.S.: Here's one good slideshow about composer.

Tags: ,