PHP Класс Cake\Console\Shell

Is the equivalent of Cake\Controller\Controller on the command line.
Наследование: use trait Cake\ORM\Locator\LocatorAwareTrait, use trait Cake\Log\LogTrait, use trait Cake\Utility\MergeVariablesTrait, use trait Cake\Datasource\ModelAwareTrait
Показать файл Открыть проект Примеры использования класса

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

Свойство Тип Описание
$OptionParser Cake\Console\ConsoleOptionParser An instance of ConsoleOptionParser that has been configured for this class.
$Tasks Cake\Console\TaskRegistry Task Collection for the command, used to create Tasks.
$args array Contains arguments parsed from the command line.
$command string The command (method/task) that is being run.
$interactive boolean If true, the script will ask for permission to perform actions.
$name string The name of the shell in camelized.
$params array Contains command switches parsed from the command line.
$plugin string Is automatically set by ShellDispatcher when a shell is constructed.
$taskNames array Contains the loaded tasks
$tasks array Contains tasks to load and instantiate

Защищенные свойства (Protected)

Свойство Тип Описание
$_io ConsoleIo ConsoleIo instance.
$_taskMap array Normalized map of tasks.

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

Метод Описание
__construct ( ConsoleIo $io = null ) Constructs this Shell instance.
__debugInfo ( ) : array Returns an array that can be used to describe the internal state of this object.
__get ( string $name ) : Shell Overload get for lazy building of tasks
abort ( string $message, integer $exitCode = self::CODE_ERROR ) : void Displays a formatted error message and exits the application with status code 1
clear ( ) : void Clear the console
createFile ( string $path, string $contents ) : boolean Creates a file at given path
dispatchShell ( ) : mixed Dispatch a command to another Shell. Similar to Object::requestAction() but intended for running shells from other shells.
err ( string | array | null $message = null, integer $newlines = 1 ) : integer | boolean Outputs a single or multiple error messages to stderr. If no parameters are passed outputs just a newline.
error ( string $title, string | null $message = null, integer $exitCode = self::CODE_ERROR ) : integer Displays a formatted error message and exits the application with status code 1
getOptionParser ( ) : Cake\Console\ConsoleOptionParser Gets the option parser instance and configures it.
hasMethod ( string $name ) : boolean Check to see if this shell has a callable method by the given name.
hasTask ( string $task ) : boolean Check to see if this shell has a task with the provided name.
helper ( string $name, array $settings = [] ) : Cake\Console\Helper Render a Console Helper
hr ( integer $newlines, integer $width = 63 ) : void Outputs a series of minus characters to the standard output, acts as a visual separator.
in ( string $prompt, string | array | null $options = null, string | null $default = null ) : mixed Prompts the user for input, and returns it.
info ( string | array | null $message = null, integer $newlines = 1, integer $level = Shell::NORMAL ) : integer | boolean Convenience method for out() that wraps message between tag
initialize ( ) : void Initializes the Shell acts as constructor for subclasses allows configuration of tasks prior to shell execution
io ( ConsoleIo $io = null ) : ConsoleIo Get/Set the io object for this shell.
loadTasks ( ) : boolean Loads tasks defined in public $tasks
nl ( integer $multiplier = 1 ) : string Returns a single or multiple linefeeds sequences.
out ( string | array | null $message = null, integer $newlines = 1, integer $level = Shell::NORMAL ) : integer | boolean Outputs a single or multiple messages to stdout. If no parameters are passed outputs just a newline.
param ( string $name ) : string | boolean | null Safely access the values in $this->params.
parseDispatchArguments ( array $args ) : array Parses the arguments for the dispatchShell() method.
quiet ( string | array $message, integer $newlines = 1 ) : integer | boolean Output at all levels.
runCommand ( array $argv, boolean $autoMethod = false, array $extra = [] ) : integer | boolean | null Runs the Shell with the provided argv.
shortPath ( string $file ) : string Makes absolute file path easier to read
startup ( ) : void Starts up the Shell and displays the welcome message.
success ( string | array | null $message = null, integer $newlines = 1, integer $level = Shell::NORMAL ) : integer | boolean Convenience method for out() that wraps message between tag
verbose ( string | array $message, integer $newlines = 1 ) : integer | boolean Output at the verbose level.
warn ( string | array | null $message = null, integer $newlines = 1 ) : integer | boolean Convenience method for err() that wraps message between tag
wrapText ( string $text, integer | array $options = [] ) : string Wrap a block of text.

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

Метод Описание
_displayHelp ( string $command ) : integer | boolean Display the help in the correct format
_setOutputLevel ( ) : void Set the output level based on the parameters.
_stop ( integer | string $status ) : void Stop execution of the current script.
_welcome ( ) : void Displays a header for the shell

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

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

Constructs this Shell instance.
public __construct ( ConsoleIo $io = null )
$io ConsoleIo An io instance.

__debugInfo() публичный метод

Returns an array that can be used to describe the internal state of this object.
public __debugInfo ( ) : array
Результат array

__get() публичный метод

Overload get for lazy building of tasks
public __get ( string $name ) : Shell
$name string The task to get.
Результат Shell Object of Task

_displayHelp() защищенный метод

Display the help in the correct format
protected _displayHelp ( string $command ) : integer | boolean
$command string The command to get help for.
Результат integer | boolean The number of bytes returned from writing to stdout.

_setOutputLevel() защищенный метод

This reconfigures both the output level for out() and the configured stdout/stderr logging
protected _setOutputLevel ( ) : void
Результат void

_stop() защищенный метод

Raises a StopException to try and halt the execution.
protected _stop ( integer | string $status ) : void
$status integer | string see http://php.net/exit for values
Результат void

_welcome() защищенный метод

Displays a header for the shell
protected _welcome ( ) : void
Результат void

abort() публичный метод

Displays a formatted error message and exits the application with status code 1
public abort ( string $message, integer $exitCode = self::CODE_ERROR ) : void
$message string The error message
$exitCode integer The exit code for the shell task.
Результат void

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

Clear the console
public clear ( ) : void
Результат void

createFile() публичный метод

Creates a file at given path
public createFile ( string $path, string $contents ) : boolean
$path string Where to put the file.
$contents string Content to put in the file.
Результат boolean Success

dispatchShell() публичный метод

### Usage: With a string command: return $this->dispatchShell('schema create DbAcl'); Avoid using this form if you have string arguments, with spaces in them. The dispatched will be invoked incorrectly. Only use this form for simple command dispatching. With an array command: return $this->dispatchShell('schema', 'create', 'i18n', '--dry'); With an array having two key / value pairs: - command can accept either a string or an array. Represents the command to dispatch - extra can accept an array of extra parameters to pass on to the dispatcher. This parameters will be available in the param property of the called Shell return $this->dispatchShell([ 'command' => 'schema create DbAcl', 'extra' => ['param' => 'value'] ]); or return $this->dispatchShell([ 'command' => ['schema', 'create', 'DbAcl'], 'extra' => ['param' => 'value'] ]);
public dispatchShell ( ) : mixed
Результат mixed The return of the other shell.

err() публичный метод

Outputs a single or multiple error messages to stderr. If no parameters are passed outputs just a newline.
public err ( string | array | null $message = null, integer $newlines = 1 ) : integer | boolean
$message string | array | null A string or an array of strings to output
$newlines integer Number of newlines to append
Результат integer | boolean The number of bytes returned from writing to stderr.

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

Displays a formatted error message and exits the application with status code 1
Устаревший: Since 3.2.0. Use Shell::abort() instead.
public error ( string $title, string | null $message = null, integer $exitCode = self::CODE_ERROR ) : integer
$title string Title of the error
$message string | null An optional error message
$exitCode integer The exit code for the shell task.
Результат integer Error code

getOptionParser() публичный метод

By overriding this method you can configure the ConsoleOptionParser before returning it.
public getOptionParser ( ) : Cake\Console\ConsoleOptionParser
Результат Cake\Console\ConsoleOptionParser

hasMethod() публичный метод

Check to see if this shell has a callable method by the given name.
public hasMethod ( string $name ) : boolean
$name string The method name to check.
Результат boolean

hasTask() публичный метод

Check to see if this shell has a task with the provided name.
public hasTask ( string $task ) : boolean
$task string The task name to check.
Результат boolean Success

helper() публичный метод

Create and render the output for a helper object. If the helper object has not already been loaded, it will be loaded and constructed.
public helper ( string $name, array $settings = [] ) : Cake\Console\Helper
$name string The name of the helper to render
$settings array Configuration data for the helper.
Результат Cake\Console\Helper The created helper instance.

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

Outputs a series of minus characters to the standard output, acts as a visual separator.
public hr ( integer $newlines, integer $width = 63 ) : void
$newlines integer Number of newlines to pre- and append
$width integer Width of the line, defaults to 63
Результат void

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

Prompts the user for input, and returns it.
public in ( string $prompt, string | array | null $options = null, string | null $default = null ) : mixed
$prompt string Prompt text.
$options string | array | null Array or string of options.
$default string | null Default input value.
Результат mixed Either the default value, or the user-provided input.

info() публичный метод

Convenience method for out() that wraps message between tag
См. также: http://book.cakephp.org/3.0/en/console-and-shells.html#Shell::out
public info ( string | array | null $message = null, integer $newlines = 1, integer $level = Shell::NORMAL ) : integer | boolean
$message string | array | null A string or an array of strings to output
$newlines integer Number of newlines to append
$level integer The message's output level, see above.
Результат integer | boolean The number of bytes returned from writing to stdout.

initialize() публичный метод

Initializes the Shell acts as constructor for subclasses allows configuration of tasks prior to shell execution
public initialize ( ) : void
Результат void

io() публичный метод

Get/Set the io object for this shell.
public io ( ConsoleIo $io = null ) : ConsoleIo
$io ConsoleIo The ConsoleIo object to use.
Результат ConsoleIo The current ConsoleIo object.

loadTasks() публичный метод

Loads tasks defined in public $tasks
public loadTasks ( ) : boolean
Результат boolean

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

Returns a single or multiple linefeeds sequences.
public nl ( integer $multiplier = 1 ) : string
$multiplier integer Number of times the linefeed sequence should be repeated
Результат string

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

### Output levels There are 3 built-in output level. Shell::QUIET, Shell::NORMAL, Shell::VERBOSE. The verbose and quiet output levels, map to the verbose and quiet output switches present in most shells. Using Shell::QUIET for a message means it will always display. While using Shell::VERBOSE means it will only display when verbose output is toggled.
public out ( string | array | null $message = null, integer $newlines = 1, integer $level = Shell::NORMAL ) : integer | boolean
$message string | array | null A string or an array of strings to output
$newlines integer Number of newlines to append
$level integer The message's output level, see above.
Результат integer | boolean The number of bytes returned from writing to stdout.

param() публичный метод

Safely access the values in $this->params.
public param ( string $name ) : string | boolean | null
$name string The name of the parameter to get.
Результат string | boolean | null Value. Will return null if it doesn't exist.

parseDispatchArguments() публичный метод

Parses the arguments for the dispatchShell() method.
public parseDispatchArguments ( array $args ) : array
$args array Arguments fetch from the dispatchShell() method with func_get_args()
Результат array First value has to be an array of the command arguments. Second value has to be an array of extra parameter to pass on to the dispatcher

quiet() публичный метод

Output at all levels.
public quiet ( string | array $message, integer $newlines = 1 ) : integer | boolean
$message string | array A string or an array of strings to output
$newlines integer Number of newlines to append
Результат integer | boolean The number of bytes returned from writing to stdout.

runCommand() публичный метод

Delegates calls to Tasks and resolves methods inside the class. Commands are looked up with the following order: - Method on the shell. - Matching task name. - main() method. If a shell implements a main() method, all missing method calls will be sent to main() with the original method name in the argv. For tasks to be invoked they *must* be exposed as subcommands. If you define any subcommands, you must define all the subcommands your shell needs, whether they be methods on this class or methods on tasks.
public runCommand ( array $argv, boolean $autoMethod = false, array $extra = [] ) : integer | boolean | null
$argv array Array of arguments to run the shell with. This array should be missing the shell name.
$autoMethod boolean Set to true to allow any public method to be called even if it was not defined as a subcommand. This is used by ShellDispatcher to make building simple shells easy.
$extra array Extra parameters that you can manually pass to the Shell to be dispatched. Built-in extra parameter is : - `requested` : if used, will prevent the Shell welcome message to be displayed
Результат integer | boolean | null

shortPath() публичный метод

Makes absolute file path easier to read
public shortPath ( string $file ) : string
$file string Absolute file path
Результат string short path

startup() публичный метод

Allows for checking and configuring prior to command or main execution Override this method if you want to remove the welcome information, or otherwise modify the pre-command flow.
public startup ( ) : void
Результат void

success() публичный метод

Convenience method for out() that wraps message between tag
См. также: http://book.cakephp.org/3.0/en/console-and-shells.html#Shell::out
public success ( string | array | null $message = null, integer $newlines = 1, integer $level = Shell::NORMAL ) : integer | boolean
$message string | array | null A string or an array of strings to output
$newlines integer Number of newlines to append
$level integer The message's output level, see above.
Результат integer | boolean The number of bytes returned from writing to stdout.

verbose() публичный метод

Output at the verbose level.
public verbose ( string | array $message, integer $newlines = 1 ) : integer | boolean
$message string | array A string or an array of strings to output
$newlines integer Number of newlines to append
Результат integer | boolean The number of bytes returned from writing to stdout.

warn() публичный метод

Convenience method for err() that wraps message between tag
См. также: http://book.cakephp.org/3.0/en/console-and-shells.html#Shell::err
public warn ( string | array | null $message = null, integer $newlines = 1 ) : integer | boolean
$message string | array | null A string or an array of strings to output
$newlines integer Number of newlines to append
Результат integer | boolean The number of bytes returned from writing to stderr.

wrapText() публичный метод

Allows you to set the width, and indenting on a block of text. ### Options - width The width to wrap to. Defaults to 72 - wordWrap Only wrap on words breaks (spaces) Defaults to true. - indent Indent the text with the string provided. Defaults to null.
См. также: Cake\Utility\Text::wrap()
public wrapText ( string $text, integer | array $options = [] ) : string
$text string Text the text to format.
$options integer | array Array of options to use, or an integer to wrap the text to.
Результат string Wrapped / indented text

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

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

An instance of ConsoleOptionParser that has been configured for this class.
public ConsoleOptionParser,Cake\Console $OptionParser
Результат Cake\Console\ConsoleOptionParser

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

Task Collection for the command, used to create Tasks.
public TaskRegistry,Cake\Console $Tasks
Результат Cake\Console\TaskRegistry

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

ConsoleIo instance.
protected ConsoleIo,Cake\Console $_io
Результат ConsoleIo

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

Normalized map of tasks.
protected array $_taskMap
Результат array

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

Contains arguments parsed from the command line.
public array $args
Результат array

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

The command (method/task) that is being run.
public string $command
Результат string

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

If true, the script will ask for permission to perform actions.
public bool $interactive
Результат boolean

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

The name of the shell in camelized.
public string $name
Результат string

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

Contains command switches parsed from the command line.
public array $params
Результат array

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

Is automatically set by ShellDispatcher when a shell is constructed.
public string $plugin
Результат string

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

Contains the loaded tasks
public array $taskNames
Результат array

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

Contains tasks to load and instantiate
public array $tasks
Результат array