Skip to content

Commit

Permalink
Some changelog, code and documentation fixes on CConsoleCommand::prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
dnohales committed Mar 6, 2012
1 parent e70404b commit 42ff7a2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG
Expand Up @@ -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)
Expand Down
27 changes: 15 additions & 12 deletions framework/console/CConsoleCommand.php
Expand Up @@ -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;
}
}

/**
Expand Down

0 comments on commit 42ff7a2

Please sign in to comment.