From 42ff7a20e3e937c36eb354fa1c7b67e277dd69cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dami=C3=A1n=20Nohales?= Date: Tue, 6 Mar 2012 17:10:32 -0300 Subject: [PATCH] Some changelog, code and documentation fixes on CConsoleCommand::prompt --- CHANGELOG | 2 +- framework/console/CConsoleCommand.php | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c2facb2cfc..f80b37f3cc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -20,7 +20,7 @@ Version 1.1.11 work in progress - Enh #237: The tabs of CTabView now support the property 'visible' (DaSourcerer) - Enh #356: Improved extendability of CDetailView by adding method renderItem() (cebe) - Enh #414: Added sort parameter to yiic message command that sorts messages by key when merging (ranvis) -- Enh #455: Added support for default value in CConsoleCommand::prompt. +- Enh #455: Added support for default value in CConsoleCommand::prompt (eagleoneraptor) - Enh: Added getIsFlashRequest(), proper handling of Flash/Flex request when using CWebLogRoute with FireBug (resurtm) - Enh: Added CBreadcrumbs::$activeLinkTemplate and CBreadcrumbs::$inactiveLinkTemplate properties which allows to change each item's template (resurtm) - Enh: Added full-featured behaviors and events CConsoleCommand::onBeforeAction & CConsoleCommand::onAfterAction (Yiivgeny) diff --git a/framework/console/CConsoleCommand.php b/framework/console/CConsoleCommand.php index 8f94fca65e..199d52c6db 100644 --- a/framework/console/CConsoleCommand.php +++ b/framework/console/CConsoleCommand.php @@ -506,33 +506,36 @@ public function pluralize($name) * * @param string $message to echo out before waiting for user input * @param string $default the default string to be returned when user does not write anything. - * Defaults to null. + * Defaults to null. This parameter is available since version 1.1.11. * @return mixed line read as a string, or false if input has been closed * * @since 1.1.9 */ - public function prompt($message, $default = null) + public function prompt($message,$default=null) { - if($default !== null) - $message .= " [$default] "; + if($default!==null) + $message.=" [$default] "; else - $message .= ' '; + $message.=' '; if(extension_loaded('readline')) { - $input = readline($message); - readline_add_history($input); + $input=readline($message); + if($input!==false) + readline_add_history($input); } else { echo $message; - $input = trim(fgets(STDIN)); + $input=fgets(STDIN); } - if($input === false) - return false - else - return empty($input)? $default:$input; + if($input===false) + return false; + else{ + $input=trim($input); + return (empty($input) && $default!==null) ? $default : $input; + } } /**