PHP Class Horde_Cli, horde

Copyright 2003-2016 Horde LLC (http://www.horde.org/) See the enclosed file COPYING for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.
Author: Chuck Hagenbuch ([email protected])
Author: Jan Schneider ([email protected])
ファイルを表示 Open project: horde/horde Class Usage Examples

Protected Properties

Property Type Description
$_blue_end
$_blue_start
$_bold_end string The string to mark the end of bold text.
$_bold_start string The string to mark the beginning of bold text.
$_clearscreen string The string to use for clearing the screen.
$_console boolean Are we running on a console?
$_green_end
$_green_start
$_indent string The indent string to use.
$_newline string The newline string to use.
$_red_end string The strings to mark the end of coloured text.
$_red_start string The strings to mark the beginning of coloured text.
$_terminalBackgrounds array Terminal background color codes. Not used yet.
$_terminalForegrounds array Terminal foreground color codes. Not used yet.
$_yellow_end
$_yellow_start

Public Methods

Method Description
__construct ( ) Detect the current environment (web server or console) and sets internal values accordingly.
blue ( string $text ) : string Returns a blue version of $text.
bold ( string $text ) : string Returns a bold version of $text.
clearScreen ( ) Clears the entire screen, if possible.
fatal ( mixed $error ) Displays a fatal error message.
green ( string $text ) : string Returns a green version of $text.
indent ( string $text ) : string Returns the indented string.
init ( ) : Horde_Cli CLI scripts shouldn't timeout, so try to set the time limit to none. Also initialize a few variables in $_SERVER that aren't present from the CLI.
message ( $message, string $type = 'cli.message' ) Displays a message.
passwordPrompt ( string $prompt ) : string Interactively prompts for input without echoing to the terminal.
prompt ( string $prompt, array $choices = null, string $default = null ) : mixed Prompts for a user response.
readStdin ( ) : string Reads everything that is sent through standard input and returns it as a single string.
red ( string $text ) : string Returns a red version of $text.
runningFromCLI ( ) : boolean Make sure we're being called from the command line, and not via the web.
shutdown ( ) Destroys any session on script end.
writeln ( string $text = '', boolean $pre = false ) Prints $text on a single line.
yellow ( string $text ) : string Returns a yellow version of $text.

Method Details

__construct() public method

Use init() if you also want to set environment variables that may be missing in a CLI environment.
public __construct ( )

blue() public method

Returns a blue version of $text.
public blue ( string $text ) : string
$text string The text to print in blue.
return string The blue text.

bold() public method

Returns a bold version of $text.
public bold ( string $text ) : string
$text string The text to bold.
return string The bolded text.

clearScreen() public method

Clears the entire screen, if possible.
public clearScreen ( )

fatal() public method

Displays a fatal error message.
public fatal ( mixed $error )
$error mixed The error text to display, an exception or an object with a getMessage() method.

green() public method

Returns a green version of $text.
public green ( string $text ) : string
$text string The text to print in green.
return string The green text.

indent() public method

Returns the indented string.
public indent ( string $text ) : string
$text string The text to indent.
return string The indented text.

init() public static method

CLI scripts shouldn't timeout, so try to set the time limit to none. Also initialize a few variables in $_SERVER that aren't present from the CLI.
public static init ( ) : Horde_Cli
return Horde_Cli A Horde_Cli instance.

message() public method

Displays a message.
public message ( $message, string $type = 'cli.message' )
$type string The type of message: 'cli.error', 'cli.warning', 'cli.success', or 'cli.message'.

passwordPrompt() public method

Requires a bash shell or Windows and won't work with safe_mode settings (uses shell_exec). From: http://www.sitepoint.com/blogs/2009/05/01/interactive-cli-password-prompt-in-php/
public passwordPrompt ( string $prompt ) : string
$prompt string The message to display when prompting the user.
return string The user's response to the prompt.

prompt() public method

Prompts for a user response.
public prompt ( string $prompt, array $choices = null, string $default = null ) : mixed
$prompt string The message to display when prompting the user.
$choices array The choices available to the user or null for a text input.
$default string The default value if no value specified.
return mixed The user's response to the prompt.

readStdin() public method

Reads everything that is sent through standard input and returns it as a single string.
public readStdin ( ) : string
return string The contents of the standard input.

red() public method

Returns a red version of $text.
public red ( string $text ) : string
$text string The text to print in red.
return string The red text.

runningFromCLI() public static method

Make sure we're being called from the command line, and not via the web.
public static runningFromCLI ( ) : boolean
return boolean True if we are, false otherwise.

shutdown() public method

Destroys any session on script end.
public shutdown ( )

writeln() public method

Prints $text on a single line.
public writeln ( string $text = '', boolean $pre = false )
$text string The text to print.
$pre boolean If true the linebreak is printed before the text instead of after it.

yellow() public method

Returns a yellow version of $text.
public yellow ( string $text ) : string
$text string The text to print in yellow.
return string The yellow text.

Property Details

$_blue_end protected_oe property

protected $_blue_end

$_blue_start protected_oe property

protected $_blue_start

$_bold_end protected_oe property

The string to mark the end of bold text.
protected string $_bold_end
return string

$_bold_start protected_oe property

The string to mark the beginning of bold text.
protected string $_bold_start
return string

$_clearscreen protected_oe property

The string to use for clearing the screen.
protected string $_clearscreen
return string

$_console protected_oe property

Are we running on a console?
protected bool $_console
return boolean

$_green_end protected_oe property

protected $_green_end

$_green_start protected_oe property

protected $_green_start

$_indent protected_oe property

The indent string to use.
protected string $_indent
return string

$_newline protected_oe property

The newline string to use.
protected string $_newline
return string

$_red_end protected_oe property

The strings to mark the end of coloured text.
protected string $_red_end
return string

$_red_start protected_oe property

The strings to mark the beginning of coloured text.
protected string $_red_start
return string

$_terminalBackgrounds protected_oe property

Terminal background color codes. Not used yet.
protected array $_terminalBackgrounds
return array

$_terminalForegrounds protected_oe property

Terminal foreground color codes. Not used yet.
protected array $_terminalForegrounds
return array

$_yellow_end protected_oe property

protected $_yellow_end

$_yellow_start protected_oe property

protected $_yellow_start