What is Composer?

Composer is a dependency manager for PHP which allows us to quickly and efficiently manage dependant library within our workflow. It installs packages locally. A package is essentially just a directory containing something which has a name and a version. The name and the version are used to identify the package allowing us to quickly deploy new versions of our code whilst keeping a track of them.

A Dependency is a broad software engineering term used to express when a piece of software relies on another.

Why use Composer?

As a design and development agency we try not to be limited to building WordPress sites, all of our projects are designed for specific uses for each client and can vary from being a simple brochure site to an advanced booking and review platform. The CMS therefore becomes a dependancy of the project, rather than the project as a whole. Using Composer has several advantages:

  • Dependencies are declared in a single place.
  • Installing and updating is completed quickly at command line.
  • The project is locked into specific versions when required.
  • We don’t need to include the actual 3rd party code in our Git repository.

Optimising workflow

Using our own boilerplate composer.json template we can quickly create a new WordPress installation using our preferred plugins, wp-config.php settings can then be transferred on deployment when a change is pushed to staging or production. After installing the dependencies, Composer writes the list of the exact versions it installed into a composer.lock file. This locks the project to those specific versions and gives us a record.

Composer with WordPress

As WordPress doesn’t ship with composer support we use a GitHub fork by johnpbloch which is currently the most popular/accepted package. It effectivly syncs the main WordPress brand every fifteen minutes and adds a composer.json package.

You can view it here https://github.com/johnpbloch/wordpress or via packagist.

WordPress Packagist

Packagist mirrors the WordPress plugin and theme directories and provides them as a Composer repository. The example below is taken straight from the Packagist site and shows how quickly it can be implemented into a project.

This example composer.json file adds the Wpackagist repository and includes the latest version of Akismet, at least version 3.9 of Captcha, and the latest Hueman theme along with the Amazon Web Services SDK from the main Packagist repository.

Third party plugins

As a development agency we often write our own modules to be independent of themes or use premium third party plugins such as Advanced Custom Fields Pro or Gravity Forms.

As these plugins are not hosted in the WordPress directory we store them on GitHub or within an S3 bucket and call them into the project using authenticated URL’s. this ensures a quick but effective way to manage our dependancies whilst not sharing premium plugins with the wider world.

AUTHOR

Charles Sellers

With a background in development and marketing, Charles has grown the business over the past four years to a small but agile team.