Skip to content

Using Composer

Andrey Savchenko edited this page Jan 21, 2015 · 7 revisions

⚠️ This document describes upcoming features and procedures, still being worked on.

Introduction

Composer is a dependency manager for PHP projects. It is a command line utility, easy to install and use.

WordPress SEO uses it to include and load libraries required (License Manager and i18n module at the moment), while keeping their development standalone.

WordPress SEO comes with composer.json configuration and is available through the central Packagist repository under yoast/wordpress-seo.

Prerequisites

Composer needs to be installed in build environment, following installation instructions.

PHP 5.3+ is required to run Composer itself, but resulting WordPress SEO project can still be run in PHP 5.2 environment.

Procedures

Creating a basic WordPress SEO project

The following command will run a full process to:

  1. retrieve WordPress SEO code (at latest stable version)
  2. library dependencies
  3. build a working plugin instance
composer create-project yoast/wordpress-seo

Installing dependencies in Git checkout

The following command will retrieve dependencies and build a working plugin at the state, captured in working copy of checked out version control.

git clone https://github.com/Yoast/wordpress-seo
cd wordpress-seo
composer install

If working copy is switched to a different branch composer install can be used again to switch state of dependencies accordingly.

Updating state of dependencies

Composer tracks the state of the project in composer.lock file. Install will always reproduce that state, ensuring developers have consistent shared access to it.

When dependencies need to be updated the following command will bring them to the latest versions, allowed by composer.json configuration.

composer update

After that the updated composer.lock file needs to be committed into version control to capture the new state.

Using Composer in Travis tests

Travis provides Composer natively in its PHP environment.

Since some of the WordPress SEO tests run in PHP 5.2 environment, the PHP is temporarily switched to later version for the purposes of Composer build process.

phpenv local 5.6
composer install --no-interaction
phpenv local --unset

Building WordPress SEO for distribution

The following command will build the plugin, as its meant to be distributed to end users. It will:

  • omit development–only dependencies
  • prefer to skip version control sources
  • produce autoload, optimized for production environment
composer create-project yoast/wordpress-seo --no-dev --prefer-dist --optimize-autoload

archive command can be further used to produce a compressed package:

cd wordpress-seo
composer archive --format zip

Clone this wiki locally