CODE_ERROR
CODE_ERROR = 1 : integer
Default error code
Shell for I18N management.
Is the equivalent of Cake\Controller\Controller on the command line.
$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.
$modelClass : string
This object's primary model class name. Should be a plural form.
CakePHP will not inflect the name.
Example: For an object named 'Comments', the modelClass would be 'Comments'.
Plugin classes should use Plugin.Comments
style names to correctly load
models from the correct plugin.
$_io : \Cake\Console\ConsoleIo
ConsoleIo instance.
$_tableLocator : \Cake\ORM\Locator\LocatorInterface
Table locator instance
__construct(\Cake\Console\ConsoleIo|null $io = null, \Cake\ORM\Locator\LocatorInterface|null $locator = null)
Constructs this Shell instance.
\Cake\Console\ConsoleIo|null | $io | An io instance. |
\Cake\ORM\Locator\LocatorInterface|null | $locator | Table locator instance. |
getIo() : \Cake\Console\ConsoleIo
Get the io object for this shell.
The current ConsoleIo object.
setIo(\Cake\Console\ConsoleIo $io) : void
Set the io object for this shell.
\Cake\Console\ConsoleIo | $io | The ConsoleIo object to use. |
io(\Cake\Console\ConsoleIo|null $io = null) : \Cake\Console\ConsoleIo
Get/Set the io object for this shell.
\Cake\Console\ConsoleIo|null | $io | The ConsoleIo object to use. |
The current ConsoleIo object.
initialize() : void
Initializes the Shell acts as constructor for subclasses allows configuration of tasks prior to shell execution
None found |
startup() : void
Starts up the Shell and displays the welcome message.
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.
None found |
None found |
hasTask(string $task) : boolean
Check to see if this shell has a task with the provided name.
string | $task | The task name to check. |
Success
None found |
hasMethod(string $name) : boolean
Check to see if this shell has a callable method by the given name.
string | $name | The method name to check. |
None found |
dispatchShell() : integer
Dispatch a command to another Shell. Similar to Object::requestAction() but intended for running shells from other shells.
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 dispatchextra
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'] ]);
The cli command exit code. 0 is success.
None found |
parseDispatchArguments(array $args) : array
Parses the arguments for the dispatchShell() method.
array | $args | Arguments fetch from the dispatchShell() method with func_get_args() |
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
None found |
runCommand(array $argv, boolean $autoMethod = false, array $extra = array()) : integer|boolean|null
Runs the Shell with the provided argv.
Delegates calls to Tasks and resolves methods inside the class. Commands are looked up with the following order:
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.
array | $argv | Array of arguments to run the shell with. This array should be missing the shell name. |
boolean | $autoMethod | 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. |
array | $extra | Extra parameters that you can manually pass to the Shell to be dispatched. Built-in extra parameter is :
|
None found |
getOptionParser() : \Cake\Console\ConsoleOptionParser
Gets the option parser instance and configures it.
By overriding this method you can configure the ConsoleOptionParser before returning it.
None found |
__get(string $name) : \Cake\Console\Shell
Overload get for lazy building of tasks
string | $name | The task to get. |
Object of Task
None found |
param(string $name) : string|boolean|null
Safely access the values in $this->params.
string | $name | The name of the parameter to get. |
Value. Will return null if it doesn't exist.
None found |
in(string $prompt, string|array|null $options = null, string|null $default = null) : mixed
Prompts the user for input, and returns it.
string | $prompt | Prompt text. |
string|array|null | $options | Array or string of options. |
string|null | $default | Default input value. |
Either the default value, or the user-provided input.
None found |
wrapText(string $text, integer|array $options = array()) : string
Wrap a block of text.
Allows you to set the width, and indenting on a block of text.
width
The width to wrap to. Defaults to 72wordWrap
Only wrap on words breaks (spaces) Defaults to true.indent
Indent the text with the string provided. Defaults to null.string | $text | Text the text to format. |
integer|array | $options | Array of options to use, or an integer to wrap the text to. |
Wrapped / indented text
None found |
verbose(string|array $message, integer $newlines = 1) : integer|boolean
Output at the verbose level.
string|array | $message | A string or an array of strings to output |
integer | $newlines | Number of newlines to append |
The number of bytes returned from writing to stdout.
None found |
quiet(string|array $message, integer $newlines = 1) : integer|boolean
Output at all levels.
string|array | $message | A string or an array of strings to output |
integer | $newlines | Number of newlines to append |
The number of bytes returned from writing to stdout.
None found |
out(string|array|null $message = null, integer $newlines = 1, integer $level = \Cake\Console\Shell::NORMAL) : integer|boolean
Outputs a single or multiple messages to stdout. If no parameters are passed outputs just a newline.
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.
string|array|null | $message | A string or an array of strings to output |
integer | $newlines | Number of newlines to append |
integer | $level | The message's output level, see above. |
The number of bytes returned from writing to stdout.
None found |
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.
string|array|null | $message | A string or an array of strings to output |
integer | $newlines | Number of newlines to append |
The number of bytes returned from writing to stderr.
None found |
info(string|array|null $message = null, integer $newlines = 1, integer $level = \Cake\Console\Shell::NORMAL) : integer|boolean
Convenience method for out() that wraps message between <info /> tag
string|array|null | $message | A string or an array of strings to output |
integer | $newlines | Number of newlines to append |
integer | $level | The message's output level, see above. |
The number of bytes returned from writing to stdout.
None found |
warn(string|array|null $message = null, integer $newlines = 1) : integer|boolean
Convenience method for err() that wraps message between <warning /> tag
string|array|null | $message | A string or an array of strings to output |
integer | $newlines | Number of newlines to append |
The number of bytes returned from writing to stderr.
None found |
success(string|array|null $message = null, integer $newlines = 1, integer $level = \Cake\Console\Shell::NORMAL) : integer|boolean
Convenience method for out() that wraps message between <success /> tag
string|array|null | $message | A string or an array of strings to output |
integer | $newlines | Number of newlines to append |
integer | $level | The message's output level, see above. |
The number of bytes returned from writing to stdout.
None found |
nl(integer $multiplier = 1) : string
Returns a single or multiple linefeeds sequences.
integer | $multiplier | Number of times the linefeed sequence should be repeated |
None found |
hr(integer $newlines, integer $width = 63) : void
Outputs a series of minus characters to the standard output, acts as a visual separator.
integer | $newlines | Number of newlines to pre- and append |
integer | $width | Width of the line, defaults to 63 |
None found |
abort(string $message, integer $exitCode = self::CODE_ERROR) : void
Displays a formatted error message and exits the application with status code 1
string | $message | The error message |
integer | $exitCode | The exit code for the shell task. |
None found |
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
string | $title | Title of the error |
string|null | $message | An optional error message |
integer | $exitCode | The exit code for the shell task. |
Error code
None found |
None found |
createFile(string $path, string $contents) : boolean
Creates a file at given path
string | $path | Where to put the file. |
string | $contents | Content to put in the file. |
Success
None found |
shortPath(string $file) : string
Makes absolute file path easier to read
string | $file | Absolute file path |
short path
None found |
helper(string $name, array $settings = array()) : \Cake\Console\Helper
Render a Console 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.
string | $name | The name of the helper to render |
array | $settings | Configuration data for the helper. |
The created helper instance.
None found |
__debugInfo() : array
Returns an array that can be used to describe the internal state of this object.
None found |
tableLocator(\Cake\ORM\Locator\LocatorInterface|null $tableLocator = null) : \Cake\ORM\Locator\LocatorInterface
Sets the table locator.
If no parameters are passed, it will return the currently used locator.
\Cake\ORM\Locator\LocatorInterface|null | $tableLocator | LocatorInterface instance. |
None found |
setTableLocator(\Cake\ORM\Locator\LocatorInterface $tableLocator) : $this
Sets the table locator.
\Cake\ORM\Locator\LocatorInterface | $tableLocator | LocatorInterface instance. |
None found |
getTableLocator() : \Cake\ORM\Locator\LocatorInterface
Gets the table locator.
None found |
log(mixed $msg, integer|string $level = \Psr\Log\LogLevel::ERROR, string|array $context = array()) : boolean
Convenience method to write a message to Log. See Log::write() for more information on writing to logs.
mixed | $msg | Log message. |
integer|string | $level | Error level. |
string|array | $context | Additional log data relevant to this message. |
Success of log write.
None found |
loadModel(string|null $modelClass = null, string|null $modelType = null) : \Cake\Datasource\RepositoryInterface
Loads and constructs repository objects required by this object
Typically used to load ORM Table objects as required. Can also be used to load other types of repository objects your application uses.
If a repository provider does not return an object a MissingModelException will be thrown.
string|null | $modelClass | Name of model class to load. Defaults to $this->modelClass |
string|null | $modelType | The type of repository to load. Defaults to the modelType() value. |
If the model class cannot be found.
When using a type that has not been registered.
If no model type has been defined
The model instance created.
None found |
modelFactory(string $type, callable $factory) : void
Override a existing callable to generate repositories of a given type.
string | $type | The name of the repository type the factory function is for. |
callable | $factory | The factory function used to create instances. |
None found |
None found |
setModelType(string $modelType) : $this
Set the model type to be used by this class
string | $modelType | The model type |
None found |
modelType(string|null $modelType = null) : string|$this
Set or get the model type to be used by this class
string|null | $modelType | The model type or null to retrieve the current |
None found |
main() : void
Override main() for help message hook
None found |
init(string|null $language = null) : void
Inits PO file from POT file.
string|null | $language | Language code to use. |
None found |
main(mixed $...$args) : integer|boolean|null
mixed | $...$args |
None found |
None found |
_validateTasks() : void
Checks that the tasks in the task map are actually available
None found |
_setOutputLevel() : void
Set the output level based on the parameters.
This reconfigures both the output level for out() and the configured stdout/stderr logging
None found |
_displayHelp(string $command) : integer|boolean
Display the help in the correct format
string | $command | The command to get help for. |
The number of bytes returned from writing to stdout.
None found |
wrapMessageWithType(string $messageType, string|array $message) : array|string
Wraps a message with a given message type, e.g. <warning>
string | $messageType | The message type, e.g. "warning". |
string|array | $message | The message to wrap. |
The message wrapped with the given message type.
None found |
_stop(integer|string $status = self::CODE_SUCCESS) : void
Stop execution of the current script.
Raises a StopException to try and halt the execution.
integer|string | $status | see https://secure.php.net/exit for values |
None found |
_mergeVars(array $properties, array $options = array()) : void
Merge the list of $properties with all parent classes of the current class.
associative
- A list of properties that should be treated as associative arrays.
Properties in this list will be passed through Hash::normalize() before merging.array | $properties | An array of properties and the merge strategy for them. |
array | $options | The options to use when merging properties. |
None found |
_mergeProperty(string $property, array $parentClasses, array $options) : void
Merge a single property with the values declared in all parent classes.
string | $property | The name of the property being merged. |
array | $parentClasses | An array of classes you want to merge with. |
array | $options | Options for merging the property, see _mergeVars() |
None found |
_mergePropertyData(array $current, array $parent, boolean $isAssoc) : mixed
Merge each of the keys in a property together.
array | $current | The current merged value. |
array | $parent | The parent class' value. |
boolean | $isAssoc | Whether or not the merging should be done in associative mode. |
The updated value.
None found |
_setModelClass(string $name) : void
Set the modelClass and modelKey properties based on conventions.
If the properties are already set they will not be overwritten
string | $name | Class name. |
None found |