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
파일 보기 프로젝트 열기: cakephp/cakephp 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$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

보호된 프로퍼티들

프로퍼티 타입 설명
$_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