{"action":"created","comment":{"url":"https://api.github.com/repos/symfony/symfony-docs/pulls/comments/28232229","id":28232229,"diff_hunk":"@@ -0,0 +1,86 @@\n+.. index::\n+   single: Console; How to Call a Command from a controller\n+\n+How to Call a Command from a Controller\n+=======================================\n+\n+The :doc:`Console component documentation </components/console/introduction>` covers\n+how to create a console command. This cookbook article covers how to use a console command\n+directly from your controller. \n+\n+You may have the need to execute some function that is only available in a console command. \n+Usually, you should refactor the command and move some logic into a service that can be \n+reused in the controller. However, when the command is part of a third-party library, you \n+wouldn't want to modify or duplicate their code, but want to directly execute the command \n+instead.\n+\n+.. caution::\n+\n+    In comparison with a direct call from the console, calling a command from a controller\n+    has a slight performance impact because of the request stack overhead. This way of\n+    calling a command is only useful for small tasks.\n+\n+An example of this is sending the emails that Swift Mailer spooled earlier\n+:doc:`using the swiftmailer:spool:send command </cookbook/email/spool>`. Symfony\n+allows you to directly execute a registered command inside your controller::\n+\n+    // src/AppBundle/Controller/SpoolController.php\n+    namespace AppBundle\\Controller;\n+\n+    use Symfony\\Bundle\\FrameworkBundle\\Console\\Application;\n+    use Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller;\n+    use Symfony\\Component\\Console\\Input\\ArrayInput;\n+    use Symfony\\Component\\Console\\Output\\StreamOutput;\n+\n+    class SpoolController extend Controller\n+    {\n+        public function sendSpoolAction($messages = 10)\n+        {\n+            $kernel = $this->get('kernel');\n+            $application = new Application($kernel);\n+            $application->setAutoExit(false);\n+\n+            $input = new ArrayInput(array(\n+               'command' => 'swiftmailer:spool:send',\n+               '--message-limit' => $messages,\n+            ));\n+            $output = new StreamOutput(tmpfile(), StreamOutput::VERBOSITY_NORMAL);\n+            $application->run($input, $output);\n+\n+            rewind($output->getStream());\n+            $content = stream_get_contents($output->getStream());\n+            fclose($output->getStream());\n+\n+            return $content;\n+        }\n+    }\n+\n+Showing Colorized Command Output\n+--------------------------------\n+\n+By telling the ``StreamOutput`` it is decorated via the third parameter, it will return \n+the Ansi color-coded content. The `SensioLabs AnsiToHtml converter`_ can be required \n+using ``Composer`` and helps you to get colorful HTML::","path":"cookbook/console/command_in_controller.rst","position":63,"original_position":63,"commit_id":"62ae7c37a1e6c8b34b52023b33cc65435ca66626","original_commit_id":"62ae7c37a1e6c8b34b52023b33cc65435ca66626","user":{"login":"cordoval","id":328359,"avatar_url":"https://avatars.githubusercontent.com/u/328359?v=3","gravatar_id":"","url":"https://api.github.com/users/cordoval","html_url":"https://github.com/cordoval","followers_url":"https://api.github.com/users/cordoval/followers","following_url":"https://api.github.com/users/cordoval/following{/other_user}","gists_url":"https://api.github.com/users/cordoval/gists{/gist_id}","starred_url":"https://api.github.com/users/cordoval/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cordoval/subscriptions","organizations_url":"https://api.github.com/users/cordoval/orgs","repos_url":"https://api.github.com/users/cordoval/repos","events_url":"https://api.github.com/users/cordoval/events{/privacy}","received_events_url":"https://api.github.com/users/cordoval/received_events","type":"User","site_admin":false},"body":"helps you to get -> helps you getting?","created_at":"2015-04-13T12:01:32Z","updated_at":"2015-04-13T12:01:32Z","html_url":"https://github.com/symfony/symfony-docs/pull/5062#discussion_r28232229","pull_request_url":"https://api.github.com/repos/symfony/symfony-docs/pulls/5062","_links":{"self":{"href":"https://api.github.com/repos/symfony/symfony-docs/pulls/comments/28232229"},"html":{"href":"https://github.com/symfony/symfony-docs/pull/5062#discussion_r28232229"},"pull_request":{"href":"https://api.github.com/repos/symfony/symfony-docs/pulls/5062"}}},"pull_request":{"url":"https://api.github.com/repos/symfony/symfony-docs/pulls/5062","id":30637516,"html_url":"https://github.com/symfony/symfony-docs/pull/5062","diff_url":"https://github.com/symfony/symfony-docs/pull/5062.diff","patch_url":"https://github.com/symfony/symfony-docs/pull/5062.patch","issue_url":"https://api.github.com/repos/symfony/symfony-docs/issues/5062","number":5062,"state":"open","locked":false,"title":"Cookbook about Command in Application with AnsiToHtml","user":{"login":"Rvanlaak","id":2707563,"avatar_url":"https://avatars.githubusercontent.com/u/2707563?v=3","gravatar_id":"","url":"https://api.github.com/users/Rvanlaak","html_url":"https://github.com/Rvanlaak","followers_url":"https://api.github.com/users/Rvanlaak/followers","following_url":"https://api.github.com/users/Rvanlaak/following{/other_user}","gists_url":"https://api.github.com/users/Rvanlaak/gists{/gist_id}","starred_url":"https://api.github.com/users/Rvanlaak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rvanlaak/subscriptions","organizations_url":"https://api.github.com/users/Rvanlaak/orgs","repos_url":"https://api.github.com/users/Rvanlaak/repos","events_url":"https://api.github.com/users/Rvanlaak/events{/privacy}","received_events_url":"https://api.github.com/users/Rvanlaak/received_events","type":"User","site_admin":false},"body":"| Q             | A\r\n| ------------- | ---\r\n| Doc fix?      | no\r\n| New docs?     | yes\r\n| Applies to    | >= 2.3\r\n| Fixed tickets | https://github.com/symfony/symfony/issues/11392","created_at":"2015-03-06T11:20:02Z","updated_at":"2015-04-13T12:01:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d5612150574b6c759df0f0f48836cc9c991dbe60","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/symfony/symfony-docs/pulls/5062/commits","review_comments_url":"https://api.github.com/repos/symfony/symfony-docs/pulls/5062/comments","review_comment_url":"https://api.github.com/repos/symfony/symfony-docs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/symfony/symfony-docs/issues/5062/comments","statuses_url":"https://api.github.com/repos/symfony/symfony-docs/statuses/62ae7c37a1e6c8b34b52023b33cc65435ca66626","head":{"label":"Rvanlaak:2.7","ref":"2.7","sha":"62ae7c37a1e6c8b34b52023b33cc65435ca66626","user":{"login":"Rvanlaak","id":2707563,"avatar_url":"https://avatars.githubusercontent.com/u/2707563?v=3","gravatar_id":"","url":"https://api.github.com/users/Rvanlaak","html_url":"https://github.com/Rvanlaak","followers_url":"https://api.github.com/users/Rvanlaak/followers","following_url":"https://api.github.com/users/Rvanlaak/following{/other_user}","gists_url":"https://api.github.com/users/Rvanlaak/gists{/gist_id}","starred_url":"https://api.github.com/users/Rvanlaak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rvanlaak/subscriptions","organizations_url":"https://api.github.com/users/Rvanlaak/orgs","repos_url":"https://api.github.com/users/Rvanlaak/repos","events_url":"https://api.github.com/users/Rvanlaak/events{/privacy}","received_events_url":"https://api.github.com/users/Rvanlaak/received_events","type":"User","site_admin":false},"repo":{"id":30647792,"name":"symfony-docs","full_name":"Rvanlaak/symfony-docs","owner":{"login":"Rvanlaak","id":2707563,"avatar_url":"https://avatars.githubusercontent.com/u/2707563?v=3","gravatar_id":"","url":"https://api.github.com/users/Rvanlaak","html_url":"https://github.com/Rvanlaak","followers_url":"https://api.github.com/users/Rvanlaak/followers","following_url":"https://api.github.com/users/Rvanlaak/following{/other_user}","gists_url":"https://api.github.com/users/Rvanlaak/gists{/gist_id}","starred_url":"https://api.github.com/users/Rvanlaak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rvanlaak/subscriptions","organizations_url":"https://api.github.com/users/Rvanlaak/orgs","repos_url":"https://api.github.com/users/Rvanlaak/repos","events_url":"https://api.github.com/users/Rvanlaak/events{/privacy}","received_events_url":"https://api.github.com/users/Rvanlaak/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Rvanlaak/symfony-docs","description":"The Symfony2 documentation","fork":true,"url":"https://api.github.com/repos/Rvanlaak/symfony-docs","forks_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/forks","keys_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/teams","hooks_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/hooks","issue_events_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/issues/events{/number}","events_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/events","assignees_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/assignees{/user}","branches_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/branches{/branch}","tags_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/tags","blobs_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/git/refs{/sha}","trees_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/statuses/{sha}","languages_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/languages","stargazers_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/stargazers","contributors_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/contributors","subscribers_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/subscribers","subscription_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/subscription","commits_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/commits{/sha}","git_commits_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/git/commits{/sha}","comments_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/comments{/number}","issue_comment_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/issues/comments{/number}","contents_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/contents/{+path}","compare_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/merges","archive_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/downloads","issues_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/issues{/number}","pulls_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/pulls{/number}","milestones_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/milestones{/number}","notifications_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/labels{/name}","releases_url":"https://api.github.com/repos/Rvanlaak/symfony-docs/releases{/id}","created_at":"2015-02-11T12:59:10Z","updated_at":"2015-02-11T12:59:14Z","pushed_at":"2015-04-13T10:11:11Z","git_url":"git://github.com/Rvanlaak/symfony-docs.git","ssh_url":"git@github.com:Rvanlaak/symfony-docs.git","clone_url":"https://github.com/Rvanlaak/symfony-docs.git","svn_url":"https://github.com/Rvanlaak/symfony-docs","homepage":"http://symfony.com/doc/current/","size":26441,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"symfony:2.7","ref":"2.7","sha":"56a80f8073de9cfdfbf815d77ceea10f3853a628","user":{"login":"symfony","id":143937,"avatar_url":"https://avatars.githubusercontent.com/u/143937?v=3","gravatar_id":"","url":"https://api.github.com/users/symfony","html_url":"https://github.com/symfony","followers_url":"https://api.github.com/users/symfony/followers","following_url":"https://api.github.com/users/symfony/following{/other_user}","gists_url":"https://api.github.com/users/symfony/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony/subscriptions","organizations_url":"https://api.github.com/users/symfony/orgs","repos_url":"https://api.github.com/users/symfony/repos","events_url":"https://api.github.com/users/symfony/events{/privacy}","received_events_url":"https://api.github.com/users/symfony/received_events","type":"Organization","site_admin":false},"repo":{"id":521583,"name":"symfony-docs","full_name":"symfony/symfony-docs","owner":{"login":"symfony","id":143937,"avatar_url":"https://avatars.githubusercontent.com/u/143937?v=3","gravatar_id":"","url":"https://api.github.com/users/symfony","html_url":"https://github.com/symfony","followers_url":"https://api.github.com/users/symfony/followers","following_url":"https://api.github.com/users/symfony/following{/other_user}","gists_url":"https://api.github.com/users/symfony/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony/subscriptions","organizations_url":"https://api.github.com/users/symfony/orgs","repos_url":"https://api.github.com/users/symfony/repos","events_url":"https://api.github.com/users/symfony/events{/privacy}","received_events_url":"https://api.github.com/users/symfony/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/symfony/symfony-docs","description":"The Symfony2 documentation","fork":false,"url":"https://api.github.com/repos/symfony/symfony-docs","forks_url":"https://api.github.com/repos/symfony/symfony-docs/forks","keys_url":"https://api.github.com/repos/symfony/symfony-docs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/symfony/symfony-docs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/symfony/symfony-docs/teams","hooks_url":"https://api.github.com/repos/symfony/symfony-docs/hooks","issue_events_url":"https://api.github.com/repos/symfony/symfony-docs/issues/events{/number}","events_url":"https://api.github.com/repos/symfony/symfony-docs/events","assignees_url":"https://api.github.com/repos/symfony/symfony-docs/assignees{/user}","branches_url":"https://api.github.com/repos/symfony/symfony-docs/branches{/branch}","tags_url":"https://api.github.com/repos/symfony/symfony-docs/tags","blobs_url":"https://api.github.com/repos/symfony/symfony-docs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/symfony/symfony-docs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/symfony/symfony-docs/git/refs{/sha}","trees_url":"https://api.github.com/repos/symfony/symfony-docs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/symfony/symfony-docs/statuses/{sha}","languages_url":"https://api.github.com/repos/symfony/symfony-docs/languages","stargazers_url":"https://api.github.com/repos/symfony/symfony-docs/stargazers","contributors_url":"https://api.github.com/repos/symfony/symfony-docs/contributors","subscribers_url":"https://api.github.com/repos/symfony/symfony-docs/subscribers","subscription_url":"https://api.github.com/repos/symfony/symfony-docs/subscription","commits_url":"https://api.github.com/repos/symfony/symfony-docs/commits{/sha}","git_commits_url":"https://api.github.com/repos/symfony/symfony-docs/git/commits{/sha}","comments_url":"https://api.github.com/repos/symfony/symfony-docs/comments{/number}","issue_comment_url":"https://api.github.com/repos/symfony/symfony-docs/issues/comments{/number}","contents_url":"https://api.github.com/repos/symfony/symfony-docs/contents/{+path}","compare_url":"https://api.github.com/repos/symfony/symfony-docs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/symfony/symfony-docs/merges","archive_url":"https://api.github.com/repos/symfony/symfony-docs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/symfony/symfony-docs/downloads","issues_url":"https://api.github.com/repos/symfony/symfony-docs/issues{/number}","pulls_url":"https://api.github.com/repos/symfony/symfony-docs/pulls{/number}","milestones_url":"https://api.github.com/repos/symfony/symfony-docs/milestones{/number}","notifications_url":"https://api.github.com/repos/symfony/symfony-docs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/symfony/symfony-docs/labels{/name}","releases_url":"https://api.github.com/repos/symfony/symfony-docs/releases{/id}","created_at":"2010-02-17T08:43:51Z","updated_at":"2015-04-12T20:18:54Z","pushed_at":"2015-04-13T11:03:58Z","git_url":"git://github.com/symfony/symfony-docs.git","ssh_url":"git@github.com:symfony/symfony-docs.git","clone_url":"https://github.com/symfony/symfony-docs.git","svn_url":"https://github.com/symfony/symfony-docs","homepage":"http://symfony.com/doc/current/","size":61444,"stargazers_count":972,"watchers_count":972,"language":"Python","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":1795,"mirror_url":null,"open_issues_count":284,"forks":1795,"open_issues":284,"watchers":972,"default_branch":"2.7"}},"_links":{"self":{"href":"https://api.github.com/repos/symfony/symfony-docs/pulls/5062"},"html":{"href":"https://github.com/symfony/symfony-docs/pull/5062"},"issue":{"href":"https://api.github.com/repos/symfony/symfony-docs/issues/5062"},"comments":{"href":"https://api.github.com/repos/symfony/symfony-docs/issues/5062/comments"},"review_comments":{"href":"https://api.github.com/repos/symfony/symfony-docs/pulls/5062/comments"},"review_comment":{"href":"https://api.github.com/repos/symfony/symfony-docs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/symfony/symfony-docs/pulls/5062/commits"},"statuses":{"href":"https://api.github.com/repos/symfony/symfony-docs/statuses/62ae7c37a1e6c8b34b52023b33cc65435ca66626"}}}}