ConsoleShell Class Info:

Class Declaration:

class ConsoleShell extends AppShell

File name:
Cake/Console/Command/ConsoleShell.php
Description:

Provides a very basic 'interactive' console for CakePHP apps.

Class Inheritance

AppShell Shell Object

Properties:

Show/Hide parent properties
  • args array

    Contains arguments parsed from the command line.

  • associations array

    Available binding types

  • badCommandChars array

    Chars that describe invalid commands

  • command string

    The command (method/task) that is being run.

  • interactive boolean

    If true, the script will ask for permission to perform actions.

  • models array

    Available models

  • name string

    The name of the shell in camelized.

  • OptionParser ConsoleOptionParser

    An instance of ConsoleOptionParser that has been configured for this class.

  • params array

    Contains command switches parsed from the command line.

  • plugin string

    The name of the plugin the shell belongs to. Is automatically set by ShellDispatcher when a shell is constructed.

  • stderr ConsoleOutput

    stderr object.

  • stdin ConsoleInput

    stdin object

  • stdout ConsoleOutput

    stdout object.

  • _taskMap string

    Normalized map of tasks.

  • taskNames array

    Contains the loaded tasks

  • tasks array

    Contains tasks to load and instantiate

  • Tasks TaskCollection

    Task Collection for the command, used to create Tasks.

  • uses array

    Contains models to load and instantiate

_checkUnitTest

top

Action to create a Unit Test

Method defined in:
Cake/Console/Shell.php on line 682
Return

boolean Success

clear

top

Clear the console

Method defined in:
Cake/Console/Shell.php on line 627

__construct

top

Constructs this Shell instance.

Parameters:
  • ConsoleOutput $stdout optional NULL

    A ConsoleOutput object for stdout.

  • ConsoleOutput $stderr optional NULL

    A ConsoleOutput object for stderr.

  • ConsoleInput $stdin optional NULL

    A ConsoleInput object for stdin.

Method defined in:
Cake/Console/Shell.php on line 156

_controllerName

top

Creates the proper controller plural name for the specified controller class name

Parameters:
  • string $name required

    Controller class name

Method defined in:
Cake/Console/Shell.php on line 729
Return

string Controller plural name

_controllerPath

top

Creates the proper controller path for the specified controller class name

Parameters:
  • string $name required

    Controller class name

Method defined in:
Cake/Console/Shell.php on line 719
Return

string Path to controller

createFile

top

Creates a file at given path

Parameters:
  • string $path required

    Where to put the file.

  • string $contents required

    Content to put in the file.

Method defined in:
Cake/Console/Shell.php on line 645

dispatchMethod

top

Calls a method on this object with the given parameters. Provides an OO wrapper for call_user_func_array

Parameters:
  • string $method required

    Name of the method to call

  • array $params optional array ( )

    Parameter list to use when calling $method

Method defined in:
Cake/Core/Object.php on line 110
Return

mixed Returns the result of the method call

dispatchShell

top

Dispatch a command to another Shell. Similar to Object::requestAction() but intended for running shells from other shells.

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');

Method defined in:
Cake/Console/Shell.php on line 326
Return

mixed The return of the other shell.

Link
http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::dispatchShell

_displayHelp

top

Display the help in the correct format

Parameters:
  • string $command required

Method defined in:
Cake/Console/Shell.php on line 401
Return

void

err

top

Outputs a single or multiple error messages to stderr. If no parameters are passed outputs just a newline.

Parameters:
  • mixed $message optional NULL

    A string or a an array of strings to output

  • integer $newlines optional 1

    Number of newlines to append

Method defined in:
Cake/Console/Shell.php on line 574

error

top

Displays a formatted error message and exits the application with status code 1

Parameters:
  • string $title required

    Title of the error

  • string $message optional NULL

    An optional error message

Method defined in:
Cake/Console/Shell.php on line 612

__get

top

Overload get for lazy building of tasks

Parameters:
  • string $name required

Method defined in:
Cake/Console/Shell.php on line 431
Return

Shell Object of Task

_getInput

top

Prompts the user for input, and returns it.

Parameters:
  • string $prompt required

    Prompt text.

  • mixed $options required

    Array or string of options.

  • string $default required

    Default input value.

Method defined in:
Cake/Console/Shell.php on line 489
Return

Either the default value, or the user-provided input.

getOptionParser

top

Gets the option parser instance and configures it. By overriding this method you can configure the ConsoleOptionParser before returning it.

Method defined in:
Cake/Console/Shell.php on line 419

hasMethod

top

Check to see if this shell has a callable method by the given name.

Parameters:
  • string $name required

    The method name to check.

Method defined in:
Cake/Console/Shell.php on line 290

hasTask

top

Check to see if this shell has a task with the provided name.

Parameters:
  • string $task required

    The task name to check.

Method defined in:
Cake/Console/Shell.php on line 279

help

top

Prints the help message

Method defined in:
Cake/Console/Command/ConsoleShell.php on line 75
Return

void

hr

top

Outputs a series of minus characters to the standard output, acts as a visual separator.

Parameters:
  • integer $newlines optional 0

    Number of newlines to pre- and append

  • integer $width optional 63

    Width of the line, defaults to 63

Method defined in:
Cake/Console/Shell.php on line 597

in

top

Prompts the user for input, and returns it.

Parameters:
  • string $prompt required

    Prompt text.

  • mixed $options optional NULL

    Array or string of options.

  • string $default optional NULL

    Default input value.

Method defined in:
Cake/Console/Shell.php on line 452
Return

mixed Either the default value, or the user-provided input.

Link
http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::in

initialize

top

Initializes the Shell acts as constructor for subclasses allows configuration of tasks prior to shell execution

Method defined in:
Cake/Console/Shell.php on line 192

_isValidModel

top

Tells if the specified model is included in the list of available models

Parameters:
  • string $modelToCheck required

Method defined in:
Cake/Console/Command/ConsoleShell.php on line 328
Return

boolean true if is an available model, false otherwise

_loadModels

top

If $uses = true Loads AppModel file and constructs AppModel class makes $this->AppModel available to subclasses If public $uses is an array of models will load those models

Method defined in:
Cake/Console/Shell.php on line 232
Return

boolean

_loadRoutes

top

Reloads the routes configuration from app/Config/routes.php, and compiles all routes found

Method defined in:
Cake/Console/Command/ConsoleShell.php on line 338
Return

boolean True if config reload was a success, otherwise false

loadTasks

top

Loads tasks defined in public $tasks

Method defined in:
Cake/Console/Shell.php on line 261
Return

boolean

log

top

Convenience method to write a message to CakeLog. See CakeLog::write() for more information on writing to logs.

Parameters:
  • string $msg required

    Log message

  • integer $type optional 2

    Error type constant. Defined in app/Config/core.php.

Method defined in:
Cake/Core/Object.php on line 149
Return

boolean Success of log write

main

top

Override main() to handle action

Parameters:
  • string $command optional NULL

Method defined in:
Cake/Console/Command/ConsoleShell.php on line 139
Return

void

_mergeVars

top

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.

Parameters:
  • array $properties required

    The name of the properties to merge.

  • string $class required

    The class to merge the property with.

  • boolean $normalize optional true

    Set to true to run the properties through Set::normalize() before merging.

Method defined in:
Cake/Core/Object.php on line 187
Return

void

_modelKey

top

Creates the proper underscored model key for associations

Parameters:
  • string $name required

    Model class name

Method defined in:
Cake/Console/Shell.php on line 749
Return

string Singular model key

_modelName

top

Creates the proper model camelized name (singularized) for the specified name

Parameters:
  • string $name required

    Name

Method defined in:
Cake/Console/Shell.php on line 739
Return

string Camelized and singularized model name

_modelNameFromKey

top

Creates the proper model name from a foreign key

Parameters:
  • string $key required

    Foreign key

Method defined in:
Cake/Console/Shell.php on line 759
Return

string Model name

nl

top

Returns a single or multiple linefeeds sequences.

Parameters:
  • integer $multiplier optional 1

    Number of times the linefeed sequence should be repeated

Method defined in:
Cake/Console/Shell.php on line 585

out

top

Outputs a single or multiple messages to stdout. If no parameters are passed outputs just a newline.

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.

Parameters:
  • mixed $message optional NULL

    A string or a an array of strings to output

  • integer $newlines optional 1

    Number of newlines to append

  • integer $level optional 1

    The message's output level, see above.

Method defined in:
Cake/Console/Shell.php on line 551
Return

integer|boolean Returns the number of bytes returned from writing to stdout.

Link
http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::out

_pluginPath

top

Find the correct path for a plugin. Scans $pluginPaths for the plugin you want.

Parameters:
  • string $pluginName required

    Name of the plugin you want ie. DebugKit

Method defined in:
Cake/Console/Shell.php on line 809
Return

string $path path to the correct plugin.

_pluralHumanName

top

Creates the plural human name used in views

Parameters:
  • string $name required

    Controller name

Method defined in:
Cake/Console/Shell.php on line 799
Return

string Plural human name

_pluralName

top

Creates the plural name for views

Parameters:
  • string $name required

    Name to use

Method defined in:
Cake/Console/Shell.php on line 779
Return

string Plural name for views

requestAction

top

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()

Passing POST and GET data

POST and GET data can be simulated in requestAction. Use $extra['url'] for GET data. The $extra['data'] parameter allows POST data simulation.

Parameters:
  • mixed $url required

    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.

  • array $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.

Method defined in:
Cake/Core/Object.php on line 66
Return

mixed Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.

runCommand

top

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:

  • 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.

Parameters:
  • string $command required

    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.

  • array $argv required

    Array of arguments to run the shell with. This array should be missing the shell name.

Method defined in:
Cake/Console/Shell.php on line 355

_set

top

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.

Parameters:
  • array $properties optional array ( )

    An associative array containing properties and corresponding values.

Method defined in:
Cake/Core/Object.php on line 164
Return

void

shortPath

top

Makes absolute file path easier to read

Parameters:
  • string $file required

    Absolute file path

Method defined in:
Cake/Console/Shell.php on line 707

_singularHumanName

top

Creates the singular human name used in views

Parameters:
  • string $name required

    Controller name

Method defined in:
Cake/Console/Shell.php on line 789
Return

string Singular human name

_singularName

top

creates the singular name for use in views.

Parameters:
  • string $name required

Method defined in:
Cake/Console/Shell.php on line 769
Return

string $name

startup

top

Override startup of the Shell

Method defined in:
Cake/Console/Command/ConsoleShell.php on line 50
Return

void

_stop

top

Stop execution of the current script. Wraps exit() making testing easier.

Parameters:
Method defined in:
Cake/Core/Object.php on line 137
Return

void

toString

top

Object-to-string conversion. Each class can override this method as necessary.

Method defined in:
Cake/Core/Object.php on line 41
Return

string The name of this class

_welcome

top

Displays a header for the shell

Method defined in:
Cake/Console/Shell.php on line 215
Return

void

wrapText

top

Wrap a block of text. 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.

Parameters:
  • string $text required

    Text the text to format.

  • mixed $options optional array ( )

    Array of options to use, or an integer to wrap the text to.

Method defined in:
Cake/Console/Shell.php on line 530