How to add a Logo to Symfony Console Component

Currently I am creating a small console application for AceProject. (Github) I never worked with the Symfony CLI Component (CLI = Command Line Interface) but it works like a charm. You can create your own CLI applications in a breeze. And I already tried other php command line frameworks – most of the frameworks were complicated, complicated in the sense of understanding and creating simple CLI apps.

So what I wanted was to add a big ascii logo like the one in composer:

I could not simply print the logo in the constructor or on top of the script because the symfony component uses own “print” methods (write / writeln) and you can hide them with the –quiet option, you cant do this when you use your own print function.

So, the way to show own logo above the help screen is to create own Class which extends the Application Class. Then instead of creating an instance of Application I create an instance of my own class. My own class then has the definition for my own logo. At first, here is the old way (without the logo)

file: myapp.php

And now with the logo:

At first we create a new class – lets name it myapp.php (you need to autoload it!)

 

And now you simply change the second line from the first example. It should instanciate MyApp and not Application.

That way you can not only add a custom ascii logo but you can also change the behaviour how your app initializes or shows the help message.

BTW: I use this page to create ASCII Logos. 🙂

Please follow and like me:

Leave a Reply

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