Composer The Latest of Our Alpha – Symfony2 Tricks

Ok folks, time to get up to speed with the latest developments in composer. Composer is trying hard to get out of alpha version. Let’s help spread the word to summon support and contribute. Here is the run down of new/updated features you may want to have under your arsenal belt:

[logo made by @wizardcat, btw i met this guy in Warsaw :)]

Suppose we were to start with a composer.json something like this:

    "type": "project",
    "license": "proprietary2",
    "require": {
        "lib-ICU": ">=53.1",
        "php-64bit": ">=5.5",
        "doctrine/orm" : "*",
        "symfony/event-dispatcher": ">=2.1"
    "scripts": {
        "post-update-cmd": [

Notice the new type `project`, and also the first couple of requires. Let’s validate it:

~ composer validate
./composer.json is valid for simple usage with composer but has
strict errors that make it unable to be published as a package:
See for details on the schema
name : is missing and it is required
description : is missing and it is required
License "proprietary2" is not a valid SPDX license identifier, see if you use an open license.
If the software is closed-source, you may use "proprietary" as license.

It even offers us the right suggestion. Now suppose we have network problems, and we want to report it or reproduce the problem. No worries, diagnose command to the rescue:

~ composer diagnose
Checking platform settings: OK
Checking http connectivity: OK
Checking composer.json: OK
Checking oauth access: OK
Checking disk free space: OK
Checking composer version: FAIL
Your are not running the latest version

Suppose you get concerned by a rumor some of your bundles have GPL or such forbidding licenses, then just list them with `composer licenses | grep ‘GPL’` or even fail a test if this is different than empty :):

~ composer licenses
Name: __root__
Version: dev-master
Licenses: proprietary
  doctrine/annotations       v1.1.2   MIT
  doctrine/cache             v1.3.0   MIT
  doctrine/collections       v1.1     MIT
  doctrine/common            v2.4.1   MIT
  doctrine/dbal              v2.4.1   MIT
  doctrine/inflector         v1.0     MIT
  doctrine/lexer             v1.0     MIT
  doctrine/orm               v2.4.1   MIT
  symfony/console            v2.4.0   MIT
  symfony/event-dispatcher   v2.4.0   MIT

Try running `composer install` now with a mac with updated brew formulas on icu. Currently we are on 52.1 so we will need to downgrade the 53.1 to 52.1 to be able to install the dependencies of our composer.json above or we get this:

    - The requested linked library lib-icu >=53.1 has the wrong version installed, try upgrading the intl extension.

Now because you contribute a lot you need to have a way to see if some of your dependencies have been modified and you need to launch a couple of PRs to your peeps. No worries, got you covered with `status` command:

~ composer status -v
You have changes in the following dependencies:
composer archive symfony/event-dispatcher

One more time you gotta run the test suite on your project, then use `run-script` (warning: currently only event named commands are allowed):

composer run-script post-update-cmd
PHPUnit 3.7.28 by Sebastian Bergmann.
// ...

Then imagine you are under pressure and composer did not work because of a low timeout number. You can display the merged configuration with the `config` command:

~ composer config --list
[repositories.0.type] composer
[repositories.0.url] http://satis.l
[repositories.packagist.type] composer
[repositories.packagist.url] https?://
[repositories.packagist.allow_ssl_downgrade] true
[process-timeout] 300
[use-include-path] false
[preferred-install] auto
[notify-on-install] true
[github-protocols] [git, https]
[vendor-dir] vendor
[bin-dir] {$vendor-dir}/bin (vendor/bin)
[cache-dir] /Users/cordoval/.composer/cache
[cache-files-dir] {$cache-dir}/files (/Users/cordoval/.composer/cache/files)
[cache-repo-dir] {$cache-dir}/repo (/Users/cordoval/.composer/cache/repo)
[cache-vcs-dir] {$cache-dir}/vcs (/Users/cordoval/.composer/cache/vcs)
[cache-ttl] 15552000
[cache-files-ttl] 15552000
[cache-files-maxsize] 300MiB (314572800)
[discard-changes] false
[prepend-autoloader] true
[github-domains] []
[home] /Users/cordoval/.composer

Then run the `config` with `–global key value` to up your network setting for composer to work:

composer config --global process-timeout 400

Inside your `~/.composer/config.json` will look like this:

~ cat ~/.composer/config.json
    "config": {
        "github-oauth": {
            "": "KEYHERE"
        "process-timeout": 400
    "repositories": [
            "type": "composer",
            "url": "http://satis.l"

Finally, you are just tired of copying or typing your `composer.json` by hand. You then will like the `init` command to do like a boss:

~ composer init
  Welcome to the Composer config generator
This command will guide you through creating your composer.json config.
Package name (<vendor>/<name>) []: cordoval/experiment
Description []: some description
Author [Luis Cordova <>]:
Minimum Stability []: dev
License []: MIT
Define your dependencies.
Would you like to define your dependencies (require) interactively [yes]?
Search for a package []: monolog
Found 15 packages matching monolog
   [0] monolog/monolog
   [1] symfony/monolog-bundle
   [2] symfony/monolog-bridge
   [3] kamisama/monolog-init
   [4] flynsarmy/slim-monolog
   [5] logentries/logentries-monolog-handler
   [6] ddtraceweb/monolog-parser
   [7] enlitepro/enlite-monolog
   [8] fancyguy/wordpress-monolog
   [9] swestcott/monolog-extension
  [10] lexik/monolog-browser-bundle
  [11] bazo/nette-monolog-extension
  [12] nodepub/monolog-json-service-provider
  [13] 0x20h/monoconf
  [14] beberlei/loggly-bundle
Enter package # to add, or the complete package name if it is not listed []: 0
Enter the version constraint to require []: dev-master
Search for a package []:
Would you like to define your dev dependencies (require-dev) interactively [yes]? n
    "name": "cordoval/experiment",
    "description": "some description",
    "require": {
        "monolog/monolog": "dev-master"
    "license": "MIT",
    "authors": [
            "name": "Luis Cordova",
            "email": ""
    "minimum-stability": "dev"
Do you confirm generation [yes]?

You forgot what you were doing and wanted to see what it was installed?

~ composer show --installed
doctrine/annotations     v1.1.2 Docblock Annotations Parser
doctrine/cache           v1.3.0 Caching library offering an object-oriented API for many cache backends
doctrine/collections     v1.1   Collections Abstraction library
doctrine/common          v2.4.1 Common Library for Doctrine projects
doctrine/dbal            v2.4.1 Database Abstraction Layer
doctrine/inflector       v1.0   Common String Manipulations with regard to casing and singular/plural rules.
doctrine/lexer           v1.0   Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
doctrine/orm             v2.4.1 Object-Relational-Mapper for PHP
symfony/console          v2.4.0 Symfony Console Component
symfony/event-dispatcher v2.4.0 Symfony EventDispatcher Component

Encouragements in all good, totally undeserving it and enjoying grace,

your friend @cordoval

4 thoughts on “Composer The Latest of Our Alpha – Symfony2 Tricks

  1. Nice one. I saw the ad on sylius, it is a nice idea. I’ll buy your book i’m interested in sylius. The idea of showing a preview when you add the book to cart is nice. In my case I would not have buy your symfony ecommerce book if it was not on sylius.

    Thank you too for the drill on the exam it is a nice post where we learn a lot.

Leave a Reply to Reece Fowell Cancel reply

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