From f9cf92b8542da837f3a8920f24d4c530052e085d Mon Sep 17 00:00:00 2001 From: florianv Date: Mon, 17 Mar 2014 17:08:32 +0100 Subject: [PATCH] [Console] Added ability to set the process title --- src/Symfony/Component/Console/Application.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 44b8a9393b7be..9754661fb5ff3 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -68,6 +68,7 @@ class Application private $dispatcher; private $terminalDimensions; private $defaultCommand; + private $processTitle = '%app% - %cmd%'; /** * Constructor. @@ -883,6 +884,15 @@ protected function configureIO(InputInterface $input, OutputInterface $output) */ protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output) { + if (version_compare(PHP_VERSION, '5.5.0') >= 0) { + $processTitle = strtr($this->processTitle, array( + '%app%' => $this->name, + '%cmd%' => $command->getName(), + )); + + @cli_set_process_title($processTitle); + } + foreach ($command->getHelperSet() as $helper) { if ($helper instanceof InputAwareInterface) { $helper->setInput($input); @@ -1109,4 +1119,18 @@ public function setDefaultCommand($commandName) { $this->defaultCommand = $commandName; } + + /** + * Sets the process title visible in tools such as top and ps. + * The available placeholders are: + * + * - %app% This application name + * - %cmd% The running command name + * + * @param string $processTitle The process title + */ + public function setProcessTitle($processTitle) + { + $this->processTitle = $processTitle; + } }