Friday, February 19, 2010

Try to customize the console script in Symfony2

Yesterday, Symfony Reloaded 2.0 Preview was released.
I have tried to use this by symfony-demo.

Symfony 2 is in marked contrast to symfony 1.x, for example, the amount of the directories in Root is only three: "web", "src" and "cart"! How simple!

I found "console" script in the cart directory. when I ran it with the "--shell" option in my console, "Symfony 2" message was displayed like below:

 
So I tried to customize this "Symfony 2" message to change another one.

Symfony 2 is written in PHP 5.3, so each class has "namespace". I copied the files to change from the Symfony 2 core directory and replaced the namespace below:
// namespace Symfony\Framework\WebBundle\Console; // original
namespace Bundle\CartBundle\Console; // new
 and replaced the use path in the console script, too:
//use Symfony\Framework\WebBundle\Console\Application; // original
use Bundle\CartBundle\Console\Application; // new
 I added an ASCII Art, which is the unofficial charactor of symfony that was born in the Japanese symfony comunity and twitter. Her name is "Symfo-Nyan", she is cute!

You can see the original in this page


OK, after adding the ASCII Art to the message, I ran the console again:




  I saw it is easy to customize Symfony 2 but if you are not used to using "namespace" with PHP, you should learn about it.

No comments:

Post a Comment