built-in Server Shell
string
'localhost'
integer
80
$_documentRoot
protected string
$_host
protected string
$_port
protected string
OptionParser
, Tasks
, _helpers
, _lastWritten
, _taskMap
, args
, command
, interactive
, modelClass
, name
, params
, plugin
, stderr
, stdin
, stdout
, taskNames
, tasks
, uses
Starts up the Shell and displays the welcome message. Allows for checking and configuring prior to command or main execution
getOptionParser( )
Gets the option parser instance and configures it.
ConsoleOptionParser
Shell::getOptionParser()
initialize( )
Override initialize of the Shell
Shell::initialize()
startup( )
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.
Shell::startup()
__construct( ConsoleOutput $stdout null , ConsoleOutput $stderr null , ConsoleInput $stdin null )
Constructs this Shell instance.
ConsoleOutput
$stdout
optional null ConsoleOutput
$stderr
optional null ConsoleInput
$stdin
optional null Object::__construct()
__get( string $name )
Overload get for lazy building of tasks
$name
Shell
__isset( string $name )
Lazy loads models using the loadModel() method if declared in $uses
$name
_checkUnitTest( )
Action to create a Unit Test
_controllerName( string $name )
Creates the proper controller plural name for the specified controller class name
$name
_controllerPath( string $name )
Creates the proper controller path for the specified controller class name
$name
_displayHelp( string $command )
Display the help in the correct format
$command
_getInput( string $prompt , string|array $options , string $default )
Prompts the user for input, and returns it.
$prompt
$options
$default
_loadModels( )
If $uses is an array load each of the models in the array
_modelKey( string $name )
Creates the proper underscored model key for associations
$name
_modelName( string $name )
Creates the proper model camelized name (singularized) for the specified name
$name
_modelNameFromKey( string $key )
Creates the proper model name from a foreign key
$key
_pluginPath( string $pluginName )
Find the correct path for a plugin. Scans $pluginPaths for the plugin you want.
$pluginName
_pluralHumanName( string $name )
Creates the plural human name used in views
$name
_pluralName( string $name )
Creates the plural name for views
$name
_singularHumanName( string $name )
Creates the singular human name used in views
$name
_singularName( string $name )
creates the singular name for use in views.
$name
_useLogger( boolean $enable true )
Used to enable or disable logging stream output to stdout and stderr If you don't wish to see in your stdout or stderr everything that is logged through CakeLog, call this function with first param as false
$enable
optional true clear( )
Clear the console
createFile( string $path , string $contents )
Creates a file at given path
$path
$contents
dispatchShell( )
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');
err( string|array $message null , integer $newlines 1 )
Outputs a single or multiple error messages to stderr. If no parameters are passed outputs just a newline.
$message
optional null $newlines
optional 1 error( string $title , string $message null )
Displays a formatted error message and exits the application with status code 1
$title
$message
optional null hasMethod( string $name )
Check to see if this shell has a callable method by the given name.
$name
hasTask( string $task )
Check to see if this shell has a task with the provided name.
$task
helper( string $name )
Load given shell helper class
$name
BaseShellHelper
hr( integer $newlines 0 , integer $width 63 )
Outputs a series of minus characters to the standard output, acts as a visual separator.
$newlines
optional 0 $width
optional 63 in( string $prompt , string|array $options null , string $default null )
Prompts the user for input, and returns it.
$prompt
$options
optional null $default
optional null loadModel( string $modelClass null , mixed $id null )
Loads and instantiates models required by this shell.
$modelClass
optional null $id
optional null MissingModelException
nl( integer $multiplier 1 )
Returns a single or multiple linefeeds sequences.
$multiplier
optional 1 out( string|array $message null , integer $newlines 1 , integer $level Shell::NORMAL )
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.
$message
optional null $newlines
optional 1 $level
optional Shell::NORMAL overwrite( array|string $message , integer $newlines 1 , integer $size null )
Overwrite some already output text.
Useful for building progress bars, or when you want to replace text already output to the screen with new text.
Warning You cannot overwrite text that contains newlines.
$message
$newlines
optional 1 $size
optional null param( string $name )
Safely access the values in $this->params.
$name
runCommand( string $command , array $argv )
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.
$command
The command name to run on this shell. If this argument is empty, and the shell has a main()
method, that will be called instead.
$argv
shortPath( string $file )
Makes absolute file path easier to read
$file
wrapText( string $text , string|integer|array $options array() )
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.$text
$options
optional array() _mergeVars( array $properties , string $class , boolean $normalize true )
Merges this objects $property with the property in $class' definition. This classes value for the property will be merged on top of $class'
This provides some of the DRY magic CakePHP provides. If you want to shut it off, redefine this method as an empty function.
$properties
$class
$normalize
optional true _set( array $properties array() )
Allows setting of multiple properties of the object in a single line of code. Will only set properties that are part of a class declaration.
$properties
optional array() _stop( integer|string $status 0 )
Stop execution of the current script. Wraps exit() making testing easier.
$status
optional 0 dispatchMethod( string $method , array $params array() )
Calls a method on this object with the given parameters. Provides an OO wrapper for call_user_func_array
$method
$params
optional array() log( string $msg , integer $type LOG_ERR , null|string|array $scope null )
Convenience method to write a message to CakeLog. See CakeLog::write() for more information on writing to logs.
$msg
$type
optional LOG_ERR $scope
optional null The scope(s) a log message is being created in. See CakeLog::config() for more information on logging scopes.
requestAction( string|array $url , array $extra array() )
Calls a controller's method from any location. Can be used to connect controllers together or tie plugins into a main application. requestAction can be used to return rendered views or fetch the return value from controller actions.
Under the hood this method uses Router::reverse() to convert the $url parameter into a string URL. You should use URL formats that are compatible with Router::reverse()
POST and GET data can be simulated in requestAction. Use $extra['url']
for GET data. The $extra['data']
parameter allows POST data simulation.
$url
String or array-based URL. Unlike other URL arrays in CakePHP, this URL will not automatically handle passed and named arguments in the $url parameter.
$extra
optional array() if array includes the key "return" it sets the AutoRender to true. Can also be used to submit GET/POST data, and named/passed arguments.
Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.
toString( )
Object-to-string conversion. Each class can override this method as necessary.
© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
http://api.cakephp.org/2.8/class-ServerShell.html