Contents

Adding symfony console support to silex application

Adding console support to Silex application

Silex is a micro-framework and as such doesn’t force you to use so many components included in full stack symfony framework. But, if we want to use some of them we need to do some extra work.

Install console component

Installing with composer is simple, just add additional requirements for “symfony/console”  to composer.json file. The full content of my composer.json file as currently is :

{ “name”: “igor.babic/bisaga”, “description”: “Sample silex application”, “license”: “MIT”, “type”: “project”, “require”: { “php”: “>=5.5.9”, “silex/silex”: “~1.3”, “doctrine/dbal”: “~2.2”, “twig/twig”: “^1.23”, “symfony/twig-bridge”: “^2.7”, “symfony/console”: “^2.7”, “doctrine/migrations”: “^1.1”
}, “autoload”: { “psr-4” : { “Bisaga\\” : “src/” } } }

After changing composer.json file just don’t forget to execute update command.

H:\Ampps\www\silex03>composer update

This way all required components for console support are installed. We can always check “vendor” folder after update, there will be everything required by composer definitions.

Creating main console program

To be able to use “console” command, we need console.php program first. We have very easy job here, because everything is already written, we just need to get it from symfony site .

We create console.php file with following content: