Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Sasa Stamenkovic's Blog:
Building CLI Apps With Symfony Console Component
Dec 31, 2010 @ 00:33:58

Sasa Stamenkovic has submitted a new tutorial he's written up about how to build CLI applications in Symfony with the help of its console component.

When working with PHP, I usually use Zend Framework for my projects. It has nice code generation tool (Zend_Tool), MVC, forms, helpers and it's very flexible. But one aspect where Zend wasn't the best tool for the job is building CLI applications. [...] Symfony Console Component is still under development, and there is no good documentation yet. I managed to google out Fabien Potencier's slides from ConFoo 2010 conference where he mentioned the component and showed one simple example. But still, most of the time working with the component, I find myself reading its source code.

He creates a simple console calculator application that takes in two numbers and calculates the sum of the two numbers. He includes an addition to the "--help" menu. Complete code is included to build the CLI interface and to create the class it uses to make the calculation. He shows how to add new commands and a bit on how to test your new command. Complete source code is available on github.

tagged: symfony console component commandline tutorial