8000 symfony-docs/console.rst at 4.1 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content
{"payload":{"allShortcutsEnabled":false,"fileTree":{"":{"items":[{"name":".github","path":".github","contentType":"directory"},{"name":".symfony","path":".symfony","contentType":"directory"},{"name":"_build","path":"_build","contentType":"directory"},{"name":"_images","path":"_images","contentType":"directory"},{"name":"_includes","path":"_includes","contentType":"directory"},{"name":"best_practices","path":"best_practices","contentType":"directory"},{"name":"bundles","path":"bundles","contentType":"directory"},{"name":"components","path":"components","contentType":"directory"},{"name":"configuration","path":"configuration","contentType":"directory"},{"name":"console","path":"console","contentType":"directory"},{"name":"contributing","path":"contributing","contentType":"directory"},{"name":"controller","path":"controller","contentType":"directory"},{"name":"create_framework","path":"create_framework","contentType":"directory"},{"name":"deployment","path":"deployment","contentType":"directory"},{"name":"doctrine","path":"doctrine","contentType":"directory"},{"name":"email","path":"email","contentType":"directory"},{"name":"event_dispatcher","path":"event_dispatcher","contentType":"directory"},{"name":"form","path":"form","contentType":"directory"},{"name":"frontend","path":"frontend","contentType":"directory"},{"name":"getting_started","path":"getting_started","contentType":"directory"},{"name":"http_cache","path":"http_cache","contentType":"directory"},{"name":"introduction","path":"introduction","contentType":"directory"},{"name":"logging","path":"logging","contentType":"directory"},{"name":"messenger","path":"messenger","contentType":"directory"},{"name":"profiler","path":"profiler","contentType":"directory"},{"name":"quick_tour","path":"quick_tour","contentType":"directory"},{"name":"reference","path":"reference","contentType":"directory"},{"name":"routing","path":"routing","contentType":"directory"},{"name":"security","path":"security","contentType":"directory"},{"name":"serializer","path":"serializer","contentType":"directory"},{"name":"service_container","path":"service_container","contentType":"directory"},{"name":"session","path":"session","contentType":"directory"},{"name":"setup","path":"setup","contentType":"directory"},{"name":"templating","path":"templating","contentType":"directory"},{"name":"testing","path":"testing","contentType":"directory"},{"name":"translation","path":"translation","contentType":"directory"},{"name":"validation","path":"validation","contentType":"directory"},{"name":"workflow","path":"workflow","contentType":"directory"},{"name":".editorconfig","path":".editorconfig","contentType":"file"},{"name":".gitignore","path":".gitignore","contentType":"file"},{"name":".symfony.cloud.yaml","path":".symfony.cloud.yaml","contentType":"file"},{"name":".travis.yml","path":".travis.yml","contentType":"file"},{"name":"Dockerfile","path":"Dockerfile","contentType":"file"},{"name":"README.markdown","path":"README.markdown","contentType":"file"},{"name":"bundles.rst","path":"bundles.rst","contentType":"file"},{"name":"configuration.rst","path":"configuration.rst","contentType":"file"},{"name":"console.rst","path":"console.rst","contentType":"file"},{"name":"controller.rst","path":"controller.rst","contentType":"file"},{"name":"deployment.rst","path":"deployment.rst","contentType":"file"},{"name":"doctrine.rst","path":"doctrine.rst","contentType":"file"},{"name":"email.rst","path":"email.rst","contentType":"file"},{"name":"event_dispatcher.rst","path":"event_dispatcher.rst","contentType":"file"},{"name":"forms.rst","path":"forms.rst","contentType":"file"},{"name":"frontend.rst","path":"frontend.rst","contentType":"file"},{"name":"http_cache.rst","path":"http_cache.rst","contentType":"file"},{"name":"index.rst","path":"index.rst","contentType":"file"},{"name":"logging.rst","path":"logging.rst","contentType":"file"},{"name":"messenger.rst","path":"messenger.rst","contentType":"file"},{"name":"page_creation.rst","path":"page_creation.rst","contentType":"file"},{"name":"performance.rst","path":"performance.rst","contentType":"file"},{"name":"profiler.rst","path":"profiler.rst","contentType":"file"},{"name":"routing.rst","path":"routing.rst","contentType":"file"},{"name":"security.rst","path":"security.rst","contentType":"file"},{"name":"serializer.rst","path":"serializer.rst","contentType":"file"},{"name":"service_container.rst","path":"service_container.rst","contentType":"file"},{"name":"session.rst","path":"session.rst","contentType":"file"},{"name":"setup.rst","path":"setup.rst","contentType":"file"},{"name":"templating.rst","path":"templating.rst","contentType":"file"},{"name":"testing.rst","path":"testing.rst","contentType":"file"},{"name":"translation.rst","path":"translation.rst","contentType":"file"},{"name":"validation.rst","path":"validation.rst","contentType":"file"},{"name":"web_link.rst","path":"web_link.rst","contentType":"file"},{"name":"workflow.rst","path":"workflow.rst","contentType":"file"}],"totalCount":73}},"fileTreeProcessingTime":5.17559,"foldersToFetch":[],"incompleteFileTree":false,"repo":{"id":521583,"defaultBranch":"7.3","name":"symfony-docs","ownerLogin":"symfony","currentUserCanPush":false,"isFork":false,"isEmpty":false,"createdAt":"2010-02-17T08:43:51.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/143937?v=4","public":true,"private":false,"isOrgOwned":true},"codeLineWrapEnabled":false,"symbolsExpanded":false,"treeExpanded":true,"refInfo":{"name":"4.1","listCacheKey":"v0:1748857018.0","canEdit":false,"refType":"branch","currentOid":"5b918a281ee0087e8afa3421372456c841beab09"},"path":"console.rst","currentUser":null,"blob":{"rawLines":null,"stylingDirectives":null,"colorizedLines":null,"csv":null,"csvError":null,"dependabotInfo":{"showConfigurationBanner":false,"configFilePath":null,"networkDependabotPath":"/symfony/symfony-docs/network/updates","dismissConfigurationNoticePath":"/settings/dismiss-notice/dependabot_configuration_notice","configurationNoticeDismissed":null},"displayName":"console.rst","displayUrl":"https://github.com/symfony/symfony-docs/blob/4.1/console.rst?raw=true","headerInfo":{"blobSize":"12.7 KB","deleteTooltip":"You must be signed in to make or propose changes","editTooltip":"You must be signed in to make or propose changes","ghDesktopPath":"https://desktop.github.com","isGitLfs":false,"onBranch":true,"shortPath":"cf44954","siteNavLoginPath":"/login?return_to=https%3A%2F%2Fgithub.com%2Fsymfony%2Fsymfony-docs%2Fblob%2F4.1%2Fconsole.rst","isCSV":false,"isRichtext":true,"toc":[{"level":2,"text":"Console Commands","anchor":"console-commands","htmlText":"Console Commands"},{"level":3,"text":"The Console: APP_ENV \u0026 APP_DEBUG","anchor":"the-console-app_env--app_debug","htmlText":"The Console: APP_ENV \u0026amp; APP_DEBUG"},{"level":3,"text":"Creating a Command","anchor":"creating-a-command","htmlText":"Creating a Command"},{"level":3,"text":"Configuring the Command","anchor":"configuring-the-command","htmlText":"Configuring the Command"},{"level":3,"text":"Registering the Command","anchor":"registering-the-command","htmlText":"Registering the Command"},{"level":3,"text":"Executing the Command","anchor":"executing-the-command","htmlText":"Executing the Command"},{"level":3,"text":"Console Output","anchor":"console-output","htmlText":"Console Output"},{"level":4,"text":"Output Sections","anchor":"output-sections","htmlText":"Output Sections"},{"level":3,"text":"Console Input","anchor":"console-input","htmlText":"Console Input"},{"level":3,"text":"Getting Services from the Service Container","anchor":"getting-services-from-the-service-container","htmlText":"Getting Services from the Service Container"},{"level":3,"text":"Command Lifecycle","anchor":"command-lifecycle","htmlText":"Command Lifecycle"},{"level":3,"text":"Testing Commands","anchor":"testing-commands","htmlText":"Testing Commands"},{"level":3,"text":"Logging Command Errors","anchor":"logging-command-errors","htmlText":"Logging Command Errors"},{"level":3,"text":"Learn More","anchor":"learn-more","htmlText":"Learn More"}],"lineInfo":{"truncatedLoc":"400","truncatedSloc":"299"},"mode":"file"},"image":false,"isCodeownersFile":null,"isPlain":false,"isValidLegacyIssueTemplate":false,"issueTemplate":null,"discussionTemplate":null,"language":"reStructuredText","languageID":419,"large":false,"planSupportInfo":{"repoIsFork":null,"repoOwnedByCurrentUser":null,"requestFullPath":"/symfony/symfony-docs/blob/4.1/console.rst","showFreeOrgGatedFeatureMessage":null,"showPlanSupportBanner":null,"upgradeDataAttributes":null,"upgradePath":null},"publishBannersInfo":{"dismissActionNoticePath":"/settings/dismiss-notice/publish_action_from_dockerfile","releasePath":"/symfony/symfony-docs/releases/new?marketplace=true","showPublishActionBanner":false},"rawBlobUrl":"https://github.com/symfony/symfony-docs/raw/refs/heads/4.1/console.rst","renderImageOrRaw":false,"richText":"\u003carticle class=\"markdown-body entry-content container-lg\" itemprop=\"text\"\u003e\u003cpre\u003e.. index::\n single: Console; Create commands\n\n\u003c/pre\u003e\n\u003ca name=\"user-content-console-commands\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eConsole Commands\u003c/h2\u003e\u003ca id=\"user-content-console-commands\" class=\"anchor\" aria-label=\"Permalink: Console Commands\" href=\"#console-commands\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eThe Symfony framework provides lots of commands through the \u003ccode\u003ebin/console\u003c/code\u003e script\n(e.g. the well-known \u003ccode\u003ebin/console cache:clear\u003c/code\u003e command). These commands are\ncreated with the \u003ca href=\"#id1\"\u003e\u003cspan id=\"user-content-id2\"\u003e:doc:`Console component \u0026lt;/components/console\u0026gt;`\u003c/span\u003e\u003c/a\u003e. You can also\nuse it to create your own commands.\u003c/p\u003e\n\u003ca name=\"user-content-the-console-app-env-app-debug\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eThe Console: APP_ENV \u0026amp; APP_DEBUG\u003c/h3\u003e\u003ca id=\"user-content-the-console-app_env--app_debug\" class=\"anchor\" aria-label=\"Permalink: The Console: APP_ENV \u0026amp; APP_DEBUG\" href=\"#the-console-app_env--app_debug\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eConsole commands run in the \u003ca href=\"#id3\"\u003e\u003cspan id=\"user-content-id4\"\u003e:ref:`environment \u0026lt;config-dot-env\u0026gt;`\u003c/span\u003e\u003c/a\u003e defined in the \u003ccode\u003eAPP_ENV\u003c/code\u003e\nvariable of the \u003ccode\u003e.env\u003c/code\u003e file, which is \u003ccode\u003edev\u003c/code\u003e by default. It also reads the \u003ccode\u003eAPP_DEBUG\u003c/code\u003e\nvalue to turn \"debug\" mode on or off (it defaults to \u003ccode\u003e1\u003c/code\u003e, which is on).\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eTo run the command in another environment or debug mode, edit the value of \u003ccode\u003eAPP_ENV\u003c/code\u003e\nand \u003ccode\u003eAPP_DEBUG\u003c/code\u003e.\u003c/p\u003e\n\u003ca name=\"user-content-creating-a-command\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eCreating a Command\u003c/h3\u003e\u003ca id=\"user-content-creating-a-command\" class=\"anchor\" aria-label=\"Permalink: Creating a Command\" href=\"#creating-a-command\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eCommands are defined in classes extending\n\u003ca href=\"#id5\"\u003e\u003cspan id=\"user-content-id6\"\u003e:class:`Symfony\\\\Component\\\\Console\\\\Command\\\\Command`\u003c/span\u003e\u003c/a\u003e. For example, you may\nwant a command to create a user:\u003c/p\u003e\n\u003cpre\u003e// src/Command/CreateUserCommand.php\nnamespace App\\Command;\n\nuse Symfony\\Component\\Console\\Command\\Command;\nuse Symfony\\Component\\Console\\Input\\InputInterface;\nuse Symfony\\Component\\Console\\Output\\OutputInterface;\n\nclass CreateUserCommand extends Command\n{\n // the name of the command (the part after \"bin/console\")\n protected static $defaultName = 'app:create-user';\n\n protected function configure()\n {\n // ...\n }\n\n protected function execute(InputInterface $input, OutputInterface $output)\n {\n // ...\n }\n}\n\u003c/pre\u003e\n\u003ca name=\"user-content-configuring-the-command\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eConfiguring the Command\u003c/h3\u003e\u003ca id=\"user-content-configuring-the-command\" class=\"anchor\" aria-label=\"Permalink: Configuring the Command\" href=\"#configuring-the-command\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eFirst of all, you must configure the name of the command in the \u003ccode\u003econfigure()\u003c/code\u003e\nmethod. Then you can optionally define a help message and the\n\u003ca href=\"#id7\"\u003e\u003cspan id=\"user-content-id8\"\u003e:doc:`input options and arguments \u0026lt;/console/input\u0026gt;`\u003c/span\u003e\u003c/a\u003e:\u003c/p\u003e\n\u003cpre\u003e// ...\nprotected function configure()\n{\n $this\n // the short description shown while running \"php bin/console list\"\n -\u0026gt;setDescription('Creates a new user.')\n\n // the full command description shown when running the command with\n // the \"--help\" option\n -\u0026gt;setHelp('This command allows you to create a user...')\n ;\n}\n\u003c/pre\u003e\n\u003cp dir=\"auto\"\u003eThe \u003ccode\u003econfigure()\u003c/code\u003e method is called automatically at the end of the command\nconstructor. If your command defines its own constructor, set the properties\nfirst and then call to the parent constructor, to make those properties\navailable in the \u003ccode\u003econfigure()\u003c/code\u003e method:\u003c/p\u003e\n\u003cpre\u003e// ...\nuse Symfony\\Component\\Console\\Command\\Command;\nuse Symfony\\Component\\Console\\Input\\InputArgument;\n\nclass CreateUserCommand extends Command\n{\n // ...\n\n public function __construct(bool $requirePassword = false)\n {\n // best practices recommend to call the parent constructor first and\n // then set your own properties. That wouldn't work in this case\n // because configure() needs the properties set in this constructor\n $this-\u0026gt;requirePassword = $requirePassword;\n\n parent::__construct();\n }\n\n public function configure()\n {\n $this\n // ...\n -\u0026gt;addArgument('password', $this-\u0026gt;requirePassword ? InputArgument::REQUIRED : InputArgument::OPTIONAL, 'User password')\n ;\n }\n}\n\u003c/pre\u003e\n\u003ca name=\"user-content-registering-the-command\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eRegistering the Command\u003c/h3\u003e\u003ca id=\"user-content-registering-the-command\" class=\"anchor\" aria-label=\"Permalink: Registering the Command\" href=\"#registering-the-command\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eSymfony commands must be registered as services and \u003ca href=\"#id9\"\u003e\u003cspan id=\"user-content-id10\"\u003e:doc:`tagged \u0026lt;/service_container/tags\u0026gt;`\u003c/span\u003e\u003c/a\u003e\nwith the \u003ccode\u003econsole.command\u003c/code\u003e tag. If you're using the\n\u003ca href=\"#id11\"\u003e\u003cspan id=\"user-content-id12\"\u003e:ref:`default services.yaml configuration \u0026lt;service-container-services-load-example\u0026gt;`\u003c/span\u003e\u003c/a\u003e,\nthis is already done for you, thanks to \u003ca href=\"#id13\"\u003e\u003cspan id=\"user-content-id14\"\u003e:ref:`autoconfiguration \u0026lt;services-autoconfigure\u0026gt;`\u003c/span\u003e\u003c/a\u003e.\u003c/p\u003e\n\u003ca name=\"user-content-executing-the-command\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eExecuting the Command\u003c/h3\u003e\u003ca id=\"user-content-executing-the-command\" class=\"anchor\" aria-label=\"Permalink: Executing the Command\" href=\"#executing-the-command\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eAfter configuring and registering the command, you can execute it in the terminal:\u003c/p\u003e\n\u003cpre lang=\"terminal\"\u003e$ php bin/console app:create-user\n\u003c/pre\u003e\n\u003cp dir=\"auto\"\u003eAs you might expect, this command will do nothing as you didn't write any logic\nyet. Add your own logic inside the \u003ccode\u003eexecute()\u003c/code\u003e method.\u003c/p\u003e\n\u003ca name=\"user-content-console-output\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eConsole Output\u003c/h3\u003e\u003ca id=\"user-content-console-output\" class=\"anchor\" aria-label=\"Permalink: Console Output\" href=\"#console-output\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eThe \u003ccode\u003eexecute()\u003c/code\u003e method has access to the output stream to write messages to\nthe console:\u003c/p\u003e\n\u003cpre\u003e// ...\nprotected function execute(InputInterface $input, OutputInterface $output)\n{\n // outputs multiple lines to the console (adding \"\\n\" at the end of each line)\n $output-\u0026gt;writeln([\n 'User Creator',\n '============',\n '',\n ]);\n\n // the value returned by someMethod() can be an iterator (https://secure.php.net/iterator)\n // that generates and returns the messages with the 'yield' PHP keyword\n $output-\u0026gt;writeln($this-\u0026gt;someMethod());\n\n // outputs a message followed by a \"\\n\"\n $output-\u0026gt;writeln('Whoa!');\n\n // outputs a message without adding a \"\\n\" at the end of the line\n $output-\u0026gt;write('You are about to ');\n $output-\u0026gt;write('create a user.');\n}\n\u003c/pre\u003e\n\u003cpre\u003e.. versionadded:: 4.1\n The support of PHP iterators in the ``write()`` and ``writeln()`` methods\n was introduced in Symfony 4.1.\n\n\u003c/pre\u003e\n\u003cp dir=\"auto\"\u003eNow, try executing the command:\u003c/p\u003e\n\u003cpre lang=\"terminal\"\u003e$ php bin/console app:create-user\nUser Creator\n============\n\nWhoa!\nYou are about to create a user.\n\u003c/pre\u003e\n\u003ca name=\"user-content-output-sections\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch4 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eOutput Sections\u003c/h4\u003e\u003ca id=\"user-content-output-sections\" class=\"anchor\" aria-label=\"Permalink: Output Sections\" href=\"#output-sections\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cpre\u003e.. versionadded:: 4.1\n Output sections were introduced in Symfony 4.1.\n\n\u003c/pre\u003e\n\u003cp dir=\"auto\"\u003eThe regular console output can be divided into multiple independent regions\ncalled \"output sections\". Create one or more of these sections when you need to\nclear and overwrite the output information.\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eSections are created with the\n\u003ca href=\"#id15\"\u003e\u003cspan id=\"user-content-id16\"\u003e:method:`Symfony\\\\Component\\\\Console\\\\Output\\\\ConsoleOutput::section`\u003c/span\u003e\u003c/a\u003e method,\nwhich returns an instance of\n\u003ca href=\"#id17\"\u003e\u003cspan id=\"user-content-id18\"\u003e:class:`Symfony\\\\Component\\\\Console\\\\Output\\\\ConsoleSectionOutput`\u003c/span\u003e\u003c/a\u003e:\u003c/p\u003e\n\u003cpre\u003eclass MyCommand extends Command\n{\n protected function execute(InputInterface $input, OutputInterface $output)\n {\n $section1 = $output-\u0026gt;section();\n $section2 = $output-\u0026gt;section();\n $section1-\u0026gt;writeln('Hello');\n $section2-\u0026gt;writeln('World!');\n // Output displays \"Hello\\nWorld!\\n\"\n\n // overwrite() replaces all the existing section contents with the given content\n $section1-\u0026gt;overwrite('Goodbye');\n // Output now displays \"Goodbye\\nWorld!\\n\"\n\n // clear() deletes all the section contents...\n $section2-\u0026gt;clear();\n // Output now displays \"Goodbye\\n\"\n\n // ...but you can also delete a given number of lines\n // (this example deletes the last two lines of the section)\n $section1-\u0026gt;clear(2);\n // Output is now completely empty!\n }\n}\n\u003c/pre\u003e\n\u003cdiv dir=\"auto\"\u003e\n\u003cp dir=\"auto\"\u003eNote\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eA new line is appended automatically when displaying information in a section.\u003c/p\u003e\n\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eOutput sections let you manipulate the Console output in advanced ways, such as\n\u003ca href=\"#id19\"\u003e\u003cspan id=\"user-content-id20\"\u003e:ref:`displaying multiple progress bars \u0026lt;console-multiple-progress-bars\u0026gt;`\u003c/span\u003e\u003c/a\u003e which\nare updated independently and \u003ca href=\"#id21\"\u003e\u003cspan id=\"user-content-id22\"\u003e:ref:`appending rows to tables \u0026lt;console-modify-rendered-tables\u0026gt;`\u003c/span\u003e\u003c/a\u003e\nthat have already been rendered.\u003c/p\u003e\n\u003ca name=\"user-content-console-input\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eConsole Input\u003c/h3\u003e\u003ca id=\"user-content-console-input\" class=\"anchor\" aria-label=\"Permalink: Console Input\" href=\"#console-input\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eUse input options or arguments to pass information to the command:\u003c/p\u003e\n\u003cpre\u003euse Symfony\\Component\\Console\\Input\\InputArgument;\n\n// ...\nprotected function configure()\n{\n $this\n // configure an argument\n -\u0026gt;addArgument('username', InputArgument::REQUIRED, 'The username of the user.')\n // ...\n ;\n}\n\n// ...\npublic function execute(InputInterface $input, OutputInterface $output)\n{\n $output-\u0026gt;writeln([\n 'User Creator',\n '============',\n '',\n ]);\n\n // retrieve the argument value using getArgument()\n $output-\u0026gt;writeln('Username: '.$input-\u0026gt;getArgument('username'));\n}\n\u003c/pre\u003e\n\u003cp dir=\"auto\"\u003eNow, you can pass the username to the command:\u003c/p\u003e\n\u003cpre lang=\"terminal\"\u003e$ php bin/console app:create-user Wouter\nUser Creator\n============\n\nUsername: Wouter\n\u003c/pre\u003e\n\u003cpre\u003e.. seealso::\n\n Read :doc:`/console/input` for more information about console options and\n arguments.\n\n\u003c/pre\u003e\n\u003ca name=\"user-content-getting-services-from-the-service-container\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eGetting Services from the Service Container\u003c/h3\u003e\u003ca id=\"user-content-getting-services-from-the-service-container\" class=\"anchor\" aria-label=\"Permalink: Getting Services from the Service Container\" href=\"#getting-services-from-the-service-container\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eTo actually create a new user, the command has to access some\n\u003ca href=\"#id23\"\u003e\u003cspan id=\"user-content-id24\"\u003e:doc:`services \u0026lt;/service_container\u0026gt;`\u003c/span\u003e\u003c/a\u003e. Since your command is already registered\nas a service, you can use normal dependency injection. Imagine you have a\n\u003ccode\u003eApp\\Service\\UserManager\u003c/code\u003e service that you want to access:\u003c/p\u003e\n\u003cpre\u003e// ...\nuse Symfony\\Component\\Console\\Command\\Command;\nuse App\\Service\\UserManager;\n\nclass CreateUserCommand extends Command\n{\n private $userManager;\n\n public function __construct(UserManager $userManager)\n {\n $this-\u0026gt;userManager = $userManager;\n\n parent::__construct();\n }\n\n // ...\n\n protected function execute(InputInterface $input, OutputInterface $output)\n {\n // ...\n\n $this-\u0026gt;userManager-\u0026gt;create($input-\u0026gt;getArgument('username'));\n\n $output-\u0026gt;writeln('User successfully generated!');\n }\n}\n\u003c/pre\u003e\n\u003ca name=\"user-content-command-lifecycle\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eCommand Lifecycle\u003c/h3\u003e\u003ca id=\"user-content-command-lifecycle\" class=\"anchor\" aria-label=\"Permalink: Command Lifecycle\" href=\"#command-lifecycle\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1 54E4 -1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eCommands have three lifecycle methods that are invoked when running the\ncommand:\u003c/p\u003e\n\u003cdl\u003e\n\u003cdt\u003e\u003ca href=\"#id25\"\u003e\u003cspan id=\"user-content-id26\"\u003e:method:`Symfony\\\\Component\\\\Console\\\\Command\\\\Command::initialize`\u003c/span\u003e\u003c/a\u003e \u003cem\u003e(optional)\u003c/em\u003e\u003c/dt\u003e\n\u003cdd\u003eThis method is executed before the \u003ccode\u003einteract()\u003c/code\u003e and the \u003ccode\u003eexecute()\u003c/code\u003e\nmethods. Its main purpose is to initialize variables used in the rest of\nthe command methods.\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#id27\"\u003e\u003cspan id=\"user-content-id28\"\u003e:method:`Symfony\\\\Component\\\\Console\\\\Command\\\\Command::interact`\u003c/span\u003e\u003c/a\u003e \u003cem\u003e(optional)\u003c/em\u003e\u003c/dt\u003e\n\u003cdd\u003eThis method is executed after \u003ccode\u003einitialize()\u003c/code\u003e and before \u003ccode\u003eexecute()\u003c/code\u003e.\nIts purpose is to check if some of the options/arguments are missing\nand interactively ask the user for those values. This is the last place\nwhere you can ask for missing options/arguments. After this command,\nmissing options/arguments will result in an error.\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#id29\"\u003e\u003cspan id=\"user-content-id30\"\u003e:method:`Symfony\\\\Component\\\\Console\\\\Command\\\\Command::execute`\u003c/span\u003e\u003c/a\u003e \u003cem\u003e(required)\u003c/em\u003e\u003c/dt\u003e\n\u003cdd\u003eThis method is executed after \u003ccode\u003einteract()\u003c/code\u003e and \u003ccode\u003einitialize()\u003c/code\u003e.\nIt contains the logic you want the command to execute.\u003c/dd\u003e\n\u003c/dl\u003e\n\u003ca name=\"user-content-testing-commands\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eTesting Commands\u003c/h3\u003e\u003ca id=\"user-content-testing-commands\" class=\"anchor\" aria-label=\"Permalink: Testing Commands\" href=\"#testing-commands\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eSymfony provides several tools to help you test your commands. The most\nuseful one is the \u003ca href=\"#id31\"\u003e\u003cspan id=\"user-content-id32\"\u003e:class:`Symfony\\\\Component\\\\Console\\\\Tester\\\\CommandTester`\u003c/span\u003e\u003c/a\u003e\nclass. It uses special input and output classes to ease testing without a real\nconsole:\u003c/p\u003e\n\u003cpre\u003e// tests/Command/CreateUserCommandTest.php\nnamespace App\\Tests\\Command;\n\nuse App\\Command\\CreateUserCommand;\nuse Symfony\\Bundle\\FrameworkBundle\\Console\\Application;\nuse Symfony\\Bundle\\FrameworkBundle\\Test\\KernelTestCase;\nuse Symfony\\Component\\Console\\Tester\\CommandTester;\n\nclass CreateUserCommandTest extends KernelTestCase\n{\n public function testExecute()\n {\n $kernel = static::createKernel();\n $application = new Application($kernel);\n\n $command = $application-\u0026gt;find('app:create-user');\n $commandTester = new CommandTester($command);\n $commandTester-\u0026gt;execute([\n 'command' =\u0026gt; $command-\u0026gt;getName(),\n\n // pass arguments to the helper\n 'username' =\u0026gt; 'Wouter',\n\n // prefix the key with two dashes when passing options,\n // e.g: '--some-option' =\u0026gt; 'option_value',\n ]);\n\n // the output of the command in the console\n $output = $commandTester-\u0026gt;getDisplay();\n $this-\u0026gt;assertContains('Username: Wouter', $output);\n\n // ...\n }\n}\n\u003c/pre\u003e\n\u003cdiv dir=\"auto\"\u003e\n\u003cp dir=\"auto\"\u003eTip\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eYou can also test a whole console application by using\n\u003ca href=\"#id33\"\u003e\u003cspan id=\"user-content-id34\"\u003e:class:`Symfony\\\\Component\\\\Console\\\\Tester\\\\ApplicationTester`\u003c/span\u003e\u003c/a\u003e.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv dir=\"auto\"\u003e\n\u003cp dir=\"auto\"\u003eNote\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eWhen using the Console component in a standalone project, use\n\u003ca href=\"#id35\"\u003e\u003cspan id=\"user-content-id36\"\u003e:class:`Symfony\\\\Component\\\\Console\\\\Application \u0026lt;Symfony\\\\Component\\\\Console\\\\Application\u0026gt;`\u003c/span\u003e\u003c/a\u003e\nand extend the normal \u003ccode\u003e\\PHPUnit\\Framework\\TestCase\u003c/code\u003e.\u003c/p\u003e\n\u003c/div\u003e\n\u003ca name=\"user-content-logging-command-errors\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eLogging Command Errors\u003c/h3\u003e\u003ca id=\"user-content-logging-command-errors\" class=\"anchor\" aria-label=\"Permalink: Logging Command Errors\" href=\"#logging-command-errors\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eWhenever an exception is thrown while running commands, Symfony adds a log\nmessage for it including the entire failing command. In addition, Symfony\nregisters an \u003ca href=\"#id37\"\u003e\u003cspan id=\"user-content-id38\"\u003e:doc:`event subscriber \u0026lt;/event_dispatcher\u0026gt;`\u003c/span\u003e\u003c/a\u003e to listen to the\n\u003ca href=\"#id39\"\u003e\u003cspan id=\"user-content-id40\"\u003e:ref:`ConsoleEvents::TERMINATE event \u0026lt;console-events-terminate\u0026gt;`\u003c/span\u003e\u003c/a\u003e and adds a log\nmessage whenever a command doesn't finish with the \u003ccode\u003e0\u003c/code\u003e exit status.\u003c/p\u003e\n\u003ca name=\"user-content-learn-more\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eLearn More\u003c/h3\u003e\u003ca id=\"user-content-learn-more\" class=\"anchor\" aria-label=\"Permalink: Learn More\" href=\"#learn-more\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cpre\u003e.. toctree::\n :maxdepth: 1\n :glob:\n\n console/*\n\n\u003c/pre\u003e\n\u003cp dir=\"auto\"\u003eThe console component also contains a set of \"helpers\" - different small\ntools capable of helping you with different tasks:\u003c/p\u003e\n\u003cul dir=\"auto\"\u003e\n\u003cli\u003e\u003ca href=\"#id41\"\u003e\u003cspan id=\"user-content-id42\"\u003e:doc:`/components/console/helpers/questionhelper`\u003c/span\u003e\u003c/a\u003e: interactively ask the user for information\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"#id43\"\u003e\u003cspan id=\"user-content-id44\"\u003e:doc:`/components/console/helpers/formatterhelper`\u003c/span\u003e\u003c/a\u003e: customize the output colorization\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"#id45\"\u003e\u003cspan id=\"user-content-id46\"\u003e:doc:`/components/console/helpers/progressbar`\u003c/span\u003e\u003c/a\u003e: shows a progress bar\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"#id47\"\u003e\u003cspan id=\"user-content-id48\"\u003e:doc:`/components/console/helpers/table`\u003c/span\u003e\u003c/a\u003e: displays tabular data as a table\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003c/article\u003e","renderedFileInfo":null,"shortPath":null,"symbolsEnabled":true,"tabSize":2,"topBannersInfo":{"overridingGlobalFundingFile":false,"globalPreferredFundingPath":"/symfony/.github/blob/6f2ca452c856184a28812bb364b4e34ed50309da/FUNDING.yml","showInvalidCitationWarning":false,"citationHelpUrl":"https://docs.github.com/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-citation-files","actionsOnboardingTip":null},"truncated":false,"viewable":true,"workflowRedirectUrl":null,"symbols":null},"copilotInfo":null,"copilotAccessAllowed":false,"modelsAccessAllowed":false,"modelsRepoIntegrationEnabled":false,"csrf_tokens":{"/symfony/symfony-docs/branches":{"post":"2R1MTlXR4LV_n6CeaOi35UJcq-FazpJU90YS8DfMeMjM6AryvWjqetnXl7eAweNugBrsO80uLbDXeCe2Xsl7ng"},"/repos/preferences":{"post":"PJ1f2SE5AyJx1yoXq0SKiIY4a3QIexqE_xDkQUyV92B817cOQcARRveyL6wWHdMLxWHA6UzImtevfTOGjzEpyA"}}},"title":"symfony-docs/console.rst at 4.1 · symfony/symfony-docs","appPayload":{"helpUrl":"https://docs.github.com","findFileWorkerPath":"/assets-cdn/worker/find-file-worker-263cab1760dd.js","findInFileWorkerPath":"/assets-cdn/worker/find-in-file-worker-b84e9496fc59.js","githubDevUrl":null,"enabled_features":{"code_nav_ui_events":false,"react_blob_overlay":false,"accessible_code_button":true}}}
0