Command line interface
The command line presents a clean implementation of the Symfony Command Line. See their documentation on how to use the command line general.
#
SetupIt's requires a small setup to get to command line running. If you set up using the swift-starter template this is already in place.
- Create a folder 'bin' in your project root
- Create a file (without extension) named 'console' with the content from below
This should be all. Open your command line in the root of the project and run php bin/console list
.
#
Creating a custom commandIt is very easy to add your own command for running tasks, changing settings, creating cron commands, etc. Create a command by extending the Swift\Console\Command\AbstractCommand
.
This class requires to create a method getCommandName() which should return the name of the command. Further this is an extension of the Symfony Command class with some handy utilities. It will automatically be recognized by the container and registered as a command.
#
OutputSymfony automatically provides a 'simple' output helper as the second argument for the execute method. If you desire some more styling to your command or for e.g. tables. Abstract Command already populated a Symfony Style class ready to use e.g. $this->io->title(...)
.
#
Default commandsThe system comes with a batch of useful commands. Get a list of all available commands by running php bin/console list
from the command line in the root of your project. The specifics of each command will be explained in their respective chapters.
This should look something like this: