PHP Класс lithium\console\Command

Наследование: extends lithium\core\Object
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$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)

Свойство Тип Описание
$_autoConfig array Auto configuration.
$_classes array Dynamic dependencies.

Открытые методы

Метод Описание
__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.

Защищенные методы

Метод Описание
_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.

Описание методов

__construct() публичный Метод

Constructor.
public __construct ( array $config = [] ) : void
$config array Available configuration options are: - `'request'` _object|null_ - `'response'` _array_ - `'classes'` _array_
Результат void

__invoke() публичный Метод

Called by the Dispatcher class to invoke an action.
См. также: lithium\console\Dispatcher
См. также: 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.
Результат object The response object associated with this command.

_help() защищенный Метод

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
Результат boolean

_init() защищенный Метод

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
Результат void

_response() защищенный Метод

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.
Результат void

clear() публичный Метод

Clears the entire screen.
public clear ( ) : void
Результат void

columns() публичный Метод

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.
См. также: 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
Результат void

error() публичный Метод

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.
Результат integer

header() публичный Метод

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.
Результат void

hr() публичный Метод

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.
Результат integer

in() публичный Метод

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
Результат string | boolean Returns the result of the input data. If the input is equal to the `quit` option boolean `false` is returned.

nl() публичный Метод

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.
Результат string

out() публичный Метод

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.
Результат integer

stop() публичный Метод

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.
Результат void

Описание свойств

$_autoConfig защищенное свойство

Auto configuration.
protected array $_autoConfig
Результат array

$_classes защищенное свойство

Dynamic dependencies.
protected array $_classes
Результат array

$help публичное свойство

Similar to running li3 help COMMAND.
public bool $help
Результат boolean

$plain публичное свойство

Only shows only text output without styles.
public bool $plain
Результат boolean

$request публичное свойство

A Request object.
См. также: lithium\console\Request
public object $request
Результат object

$response публичное свойство

A Response object.
См. также: lithium\console\Response
public object $response
Результат object

$silent публичное свойство

Only shows error output.
public bool $silent
Результат boolean