...
In this chapter, we will create a new command, identified as ezpublish:cookbook:hello
, that takes an optional name argument, and greets that name. To do so, we need one thing: a class with a name ending with "Command" that extends Symfony\Component\Console\Command\Command
. Note that in our case, we use ContainerAwareCommand
instead of Command
, since we need the dependency injection container to interact with the Public API). In your bundle's directory (src/EzSystems/CookbookBundle
), create a new directory named Command
, and in this directory, a new file named HelloCommand.php
.
...
First, we use setName() to set our command's name to "ezpublish:cookbook:hello
". We then use setDefinition()
to add an argument, named name
, to our command.
You can read more about arguments definitions and further options in the Symfony 2 Console documentation. Once this is done, if you run php ezpublish/console list
, you should see ezpublish:cookbook:hello
listed in the available commands. If you run it, it should just do nothing.
...