PHP Class lithium\console\Command

Inheritance: extends lithium\core\Object
Afficher le fichier Open project: unionofrad/lithium Class Usage Examples

Méthodes publiques

Свойство Type Description
$help boolean Similar to running li3 help COMMAND.
$plain boolean Only shows only text output without styles.
$request object A Request object.
$response object A Response object.
$silent boolean Only shows error output.

Protected Properties

Свойство Type Description
$_autoConfig array Auto configuration.
$_classes array Dynamic dependencies.

Méthodes publiques

Méthode Description
__construct ( array $config = [] ) : void Constructor.
__invoke ( string $action, array $args = [] ) : object Called by the Dispatcher class to invoke an action.
clear ( ) : void Clears the entire screen.
columns ( array $rows, array $options = [] ) : void Writes rows of columns.
error ( string | array $error = null, mixed $options = ['nl' => 1] ) : integer Writes a string to error stream.
header ( string $text, integer $line = null ) : void Writes a header to the output stream. In addition to the actual text, horizontal lines before and afterwards are written. The lines will have the same length as the text. This behavior can be modified by providing the length of lines as a second paramerter.
hr ( integer $length = 80, integer $newlines = 1 ) : integer Adds a horizontal line to output stream.
in ( string $prompt = null, array $options = [] ) : string | boolean Handles input. Will continue to loop until $options['quit'] or result is part of $options['choices'].
nl ( integer $number = 1 ) : string Add newlines ("\n") a given number of times and return them in a single string.
out ( string | array $output = null, mixed $options = ['nl' => 1] ) : integer Writes a string to the output stream.
stop ( integer $status, string | null $message = null ) : void Stop execution, by exiting the script.

Méthodes protégées

Méthode Description
_help ( ) : boolean Invokes the Help command.
_init ( ) : void Command Initializer.
_response ( string $type, string | array $string, mixed $options ) : void Handles the response that is sent to the stream.

Method Details

__construct() public méthode

Constructor.
public __construct ( array $config = [] ) : void
$config array Available configuration options are: - `'request'` _object|null_ - `'response'` _array_ - `'classes'` _array_
Résultat void

__invoke() public méthode

Called by the Dispatcher class to invoke an action.
See also: lithium\console\Dispatcher
See also: lithium\console\Response
public __invoke ( string $action, array $args = [] ) : object
$action string The name of the method to run.
$args array The arguments from the request.
Résultat object The response object associated with this command.

_help() protected méthode

The invoked Help command will take over request and response objects of the originally invoked command. Thus the response of the Help command becomes the response of the original one.
protected _help ( ) : boolean
Résultat boolean

_init() protected méthode

Populates the $response property with a new instance of the Response class passing it configuration and assigns the values from named parameters of the request (if applicable) to properties of the command.
protected _init ( ) : void
Résultat void

_response() protected méthode

Handles the response that is sent to the stream.
protected _response ( string $type, string | array $string, mixed $options ) : void
$type string The stream either output or error.
$string string | array The message to render.
$options mixed When passed an integer or boolean it is used as the number of of new lines, when passed a string it is interpreted as style to use otherwise when an array following options are available: - `'nl'` _integer|boolean_: number of new lines to add at the end. `false` to disable adding a newline. - `'style'` _string_: the style name to wrap around the output.
Résultat void

clear() public méthode

Clears the entire screen.
public clear ( ) : void
Résultat void

columns() public méthode

This method expects asceding integer values as the keys, which map to the appropriate columns. Currently, there is no special "header" option, but you can define them for your own. Example Usage: $output = array( array('Name', 'Age'), array('----', '---'), ); foreach($users as $user) { $output[] = array($user->name, $user->age); } $this->columns($output); Would render something similar to: Name Age ---- --- Jane Doe 22 Foo Bar 18 This method also calculates the needed space between the columns. All option params given also get passed down to the out() method, which allow custom formatting. Passing something like $this->columns($output, array('style' => 'red) would print the table in red.
See also: lithium\console\Response::styles()
public columns ( array $rows, array $options = [] ) : void
$rows array The rows to print, with each column as an array element.
$options array Optional params: - separator : Different column separator, defaults to `\t` - style : the style name to wrap around the columns output
Résultat void

error() public méthode

Writes a string to error stream.
public error ( string | array $error = null, mixed $options = ['nl' => 1] ) : integer
$error string | array The string or an array of strings to write.
$options mixed When passed an integer or boolean it is used as the number of of new lines, when passed a string it is interpreted as style to use otherwise when an array following options are available: - `'nl'` _integer|boolean_: number of new lines to add at the end. `false` to disable adding a newline. - `'style'` _string_: the style name to wrap around the output.
Résultat integer

header() public méthode

Given the text 'Lithium' this generates following output: ------- Lithium -------
public header ( string $text, integer $line = null ) : void
$text string The heading text.
$line integer The length of the line. Defaults to the length of text.
Résultat void

hr() public méthode

Adds a horizontal line to output stream.
public hr ( integer $length = 80, integer $newlines = 1 ) : integer
$length integer The length of the line, defaults to 80.
$newlines integer How many new lines to print afterwards, defaults to 1.
Résultat integer

in() public méthode

Handles input. Will continue to loop until $options['quit'] or result is part of $options['choices'].
public in ( string $prompt = null, array $options = [] ) : string | boolean
$prompt string
$options array
Résultat string | boolean Returns the result of the input data. If the input is equal to the `quit` option boolean `false` is returned.

nl() public méthode

Add newlines ("\n") a given number of times and return them in a single string.
public nl ( integer $number = 1 ) : string
$number integer The number of new lines to fill into a string.
Résultat string

out() public méthode

Writes a string to the output stream.
public out ( string | array $output = null, mixed $options = ['nl' => 1] ) : integer
$output string | array The string or an array of strings to write.
$options mixed When passed an integer or boolean it is used as the number of of new lines, when passed a string it is interpreted as style to use otherwise when an array following options are available: - `'nl'` _integer|boolean_: number of new lines to add at the end. `false` to disable adding a newline. - `'style'` _string_: the style name to wrap around the output.
Résultat integer

stop() public méthode

Stop execution, by exiting the script.
public stop ( integer $status, string | null $message = null ) : void
$status integer Numeric value that will be used on `exit()`.
$message string | null An optional message that will be written to the stream.
Résultat void

Property Details

$_autoConfig protected_oe property

Auto configuration.
protected array $_autoConfig
Résultat array

$_classes protected_oe property

Dynamic dependencies.
protected array $_classes
Résultat array

$help public_oe property

Similar to running li3 help COMMAND.
public bool $help
Résultat boolean

$plain public_oe property

Only shows only text output without styles.
public bool $plain
Résultat boolean

$request public_oe property

A Request object.
See also: lithium\console\Request
public object $request
Résultat object

$response public_oe property

A Response object.
See also: lithium\console\Response
public object $response
Résultat object

$silent public_oe property

Only shows error output.
public bool $silent
Résultat boolean