The Console ComponentEdit this page
Warning: You are browsing the documentation for Symfony 4.2, which is no longer maintained.
Read the updated version of this page for Symfony 6.1 (the current stable version).
The Console component eases the creation of beautiful and testable command line interfaces.
The Console component allows you to create command-line commands. Your console commands can be used for any recurring task, such as cronjobs, imports, or other batch jobs.
$ composer require symfony/console
If you install this component outside of a Symfony application, you must
vendor/autoload.php file in your code to enable the class
autoloading mechanism provided by Composer. Read
this article for more details.
This article explains how to use the Console features as an independent component in any PHP application. Read the Console Commands article to learn about how to use it in Symfony applications.
First, you need to create a PHP script to define the console application:
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/usr/bin/env php // application.php require __DIR__.'/vendor/autoload.php'; use Symfony\Component\Console\Application; $application = new Application(); // ... register commands $application->run();
Then, you can register the commands using add():
// ... $application->add(new GenerateAdminCommand());
See the Console Commands article for information about how to create commands.
- Console Commands
- Changing the Default Command
- Understanding how Console Arguments and Options Are Handled
- Using Events
- Debug Formatter Helper
- Formatter Helper
- The Console Helpers
- Process Helper
- Progress Bar
- Question Helper
- Using the Logger
- Building a single Command Application
- Using Console Commands, Shortcuts and Built-in Commands
- The Console Helpers
- How to Call Other Commands
- How to Color and Style the Console Output
- How to Call a Command from a Controller
- How to Define Commands as Services
- How to Hide Console Commands
- Console Input (Arguments & Options)
- How to Make Commands Lazily Loaded
- Prevent Multiple Executions of a Console Command
- How to Generate URLs from the Console
- How to Style a Console Command
- Verbosity Levels