How To Learn: Composer

Our How-To-Learns are concise articles with information about how to learn various tools, techniques, skills, etc. These articles won’t teach you directly, instead they’ll make it easier to find authoritative, up-to-date, and relevant information to master the topic.

Intro

For the past several years…. ok, maybe a decade… I’ve been happily growing my personal, private collection of reusable PHP classes, plugins, libraries, modules, themes and even frameworks and a CMS. All coded by me, from scratch. Imagine my excitement – and more than a little embarrassment – when I discovered Packagist and the amazing tool of Composer which pulls the libraries published on Packagist into your project with a snap. It’s beautiful. And it’s become the industry standard along with the autoloading library it comes with. How can we learn Composer?

What Is Composer?

Composer is a project dependency management tool. It allows you to easily download and install 3rd party libraries into your PHP projects, manage their updates, autoload their classes, and specify versions. It’s a big step up from downloading it yourself and finding a place to put it in your project, then remembering to update it.

How Do I learn Composer?

Practise Exercises

The best way to cement your Composer skills is to actually use it. Such is the case for most tools, but here are some tasks to try out:

  1. Install Composer. Get it working it.
  2. Create an empty project folder and try using Composer to bring a few libraries into it. Monolog is a nice one to play with.
  3. Check out how the included libraries are organized in your project folder. Note how you will have to add the vendor directory and composer.lock to your Git/repo ignore list.
  4. Try changing the requested versions for some of the packages, delete them and have Composer bring them back.
  5. Do you have a nice library you could share? Learn how to publish one of your own packages on Packagist.

Getting Help With Composer

Unfortunately, neither the Composer or Packagist websites have forums at this time. So the best bets for getting help are places where you’ll find general PHP help, like your favourite web development or PHP forum, Stack Overflow’s Compser tag, the PHP Reddit, or fire out a question on Twitter.

Leave a Reply

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