CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.0 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.0
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Cake
    • Auth
    • Cache
      • Engine
    • Collection
      • Iterator
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
    • Event
    • Filesystem
    • Form
    • I18n
      • Formatter
      • Parser
    • Log
      • Engine
    • Network
      • Email
      • Exception
      • Http
        • Adapter
        • Auth
        • FormData
      • Session
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Rule
    • Routing
      • Exception
      • Filter
      • Route
    • Shell
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • AssetsTask
  • CommandTask
  • ExtractTask
  • LoadTask
  • UnloadTask

Class CommandTask

Base class for Shell Command reflection.

Cake\Console\Shell uses Cake\Log\LogTrait , Cake\Utility\MergeVariablesTrait , Cake\Datasource\ModelAwareTrait
Extended by Cake\Shell\Task\CommandTask
Namespace: Cake\Shell\Task
Location: Shell/Task/CommandTask.php

Inherited Constants

  • NORMAL, QUIET, VERBOSE

Inherited Properties

  • OptionParser, Tasks, _io, _taskMap, args, command, interactive, name, params, plugin, taskNames, tasks _modelFactories, modelClass

Method Summary

  • _appendShells() protected
    Scan the provided paths for shells, and append them into $shellList
  • _scanDir() protected

    Scan a directory for .php files and return the class names that should be within them.

  • commands() public
    Return a list of all commands
  • getShell() public
    Get Shell instance for the given command
  • getShellList() public
    Gets the shell command listing.
  • options() public
    Get Shell instance for the given command
  • subCommands() public
    Return a list of subcommands for a given command

Method Detail

_appendShells() protected ¶

_appendShells( string $type , array $shells , array $shellList )

Scan the provided paths for shells, and append them into $shellList

Parameters
string $type
The type of object.
array $shells
The shell name.
array $shellList
List of shells.
Returns
array
The updated $shellList

_scanDir() protected ¶

_scanDir( string $dir )

Scan a directory for .php files and return the class names that should be within them.

Parameters
string $dir
The directory to read.
Returns
array
The list of shell classnames based on conventions.

commands() public ¶

commands( )

Return a list of all commands

Returns
array

getShell() public ¶

getShell( mixed $commandName )

Get Shell instance for the given command

Parameters
mixed $commandName
The command you want.
Returns
mixed

getShellList() public ¶

getShellList( )

Gets the shell command listing.

Returns
array

options() public ¶

options( mixed $commandName )

Get Shell instance for the given command

Parameters
mixed $commandName
The command to get options for.
Returns
array

subCommands() public ¶

subCommands( string $commandName )

Return a list of subcommands for a given command

Parameters
string $commandName
The command you want subcommands from.
Returns
array

Methods inherited from Cake\Console\Shell

__construct() public ¶

__construct( Cake\Console\ConsoleIo $io null )

Constructs this Shell instance.

Parameters
Cake\Console\ConsoleIo $io optional null
An io instance.
Link
http://book.cakephp.org/3.0/en/console-and-shells.html#Shell

__debugInfo() public ¶

__debugInfo( )

Returns an array that can be used to describe the internal state of this object.

Returns
array

__get() public ¶

__get( string $name )

Overload get for lazy building of tasks

Parameters
string $name
The task to get.
Returns
Cake\Console\Shell
Object of Task

_displayHelp() protected ¶

_displayHelp( string $command )

Display the help in the correct format

Parameters
string $command
The command to get help for.
Returns
integer|boolean

_stop() protected ¶

_stop( integer|string $status 0 )

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

Parameters
integer|string $status optional 0
see http://php.net/exit for values

_welcome() protected ¶

_welcome( )

Displays a header for the shell

clear() public ¶

clear( )

Clear the console

Link
http://book.cakephp.org/3.0/en/console-and-shells.html#console-output

createFile() public ¶

createFile( string $path , string $contents )

Creates a file at given path

Parameters
string $path
Where to put the file.
string $contents
Content to put in the file.
Returns
boolean
Success
Link
http://book.cakephp.org/3.0/en/console-and-shells.html#creating-files

dispatchShell() public ¶

dispatchShell( )

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');
Returns
mixed
The return of the other shell.
Link
http://book.cakephp.org/3.0/en/console-and-shells.html#invoking-other-shells-from-your-shell

err() public ¶

err( string|array|null $message null , integer $newlines 1 )

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

Parameters
string|array|null $message optional null
A string or an array of strings to output
integer $newlines optional 1
Number of newlines to append

error() public ¶

error( string $title , string|null $message null )

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

Parameters
string $title
Title of the error
string|null $message optional null
An optional error message
Link
http://book.cakephp.org/3.0/en/console-and-shells.html#styling-output

getOptionParser() public ¶

getOptionParser( )

Gets the option parser instance and configures it.

By overriding this method you can configure the ConsoleOptionParser before returning it.

Returns
Cake\Console\ConsoleOptionParser
Link
http://book.cakephp.org/3.0/en/console-and-shells.html#configuring-options-and-generating-help

hasMethod() public ¶

hasMethod( string $name )

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

Parameters
string $name
The method name to check.
Returns
boolean
Link
http://book.cakephp.org/3.0/en/console-and-shells.html#shell-tasks

hasTask() public ¶

hasTask( string $task )

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

Parameters
string $task
The task name to check.
Returns
boolean
Success
Link
http://book.cakephp.org/3.0/en/console-and-shells.html#shell-tasks

hr() public ¶

hr( integer $newlines 0 , integer $width 63 )

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
Link
http://book.cakephp.org/3.0/en/console-and-shells.html#Shell::hr

in() public ¶

in( string $prompt , string|array|null $options null , string|null $default null )

Prompts the user for input, and returns it.

Parameters
string $prompt
Prompt text.
string|array|null $options optional null
Array or string of options.
string|null $default optional null
Default input value.
Returns
mixed
Either the default value, or the user-provided input.
Link
http://book.cakephp.org/3.0/en/console-and-shells.html#Shell::in

initialize() public ¶

initialize( )

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

Link
http://book.cakephp.org/3.0/en/console-and-shells.html#Cake\Console\ConsoleOptionParser::initialize

io() public ¶

io( Cake\Console\ConsoleIo $io null )

Get/Set the io object for this shell.

Parameters
Cake\Console\ConsoleIo $io optional null
The ConsoleIo object to use.
Returns
Cake\Console\ConsoleIo
The current ConsoleIo object.

loadTasks() public ¶

loadTasks( )

Loads tasks defined in public $tasks

Returns
boolean

nl() public ¶

nl( integer $multiplier 1 )

Returns a single or multiple linefeeds sequences.

Parameters
integer $multiplier optional 1
Number of times the linefeed sequence should be repeated
Returns
string
Link
http://book.cakephp.org/3.0/en/console-and-shells.html#Shell::nl

out() public ¶

out( string|array|null $message null , integer $newlines 1 , integer $level Cake\Shell\Task\Shell::NORMAL )

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
string|array|null $message optional null
A string or an array of strings to output
integer $newlines optional 1
Number of newlines to append
integer $level optional Cake\Shell\Task\Shell::NORMAL
The message's output level, see above.
Returns
integer|boolean
Returns the number of bytes returned from writing to stdout.
Link
http://book.cakephp.org/3.0/en/console-and-shells.html#Shell::out

param() public ¶

param( string $name )

Safely access the values in $this->params.

Parameters
string $name
The name of the parameter to get.
Returns
string|boolean|null
Value. Will return null if it doesn't exist.

quiet() public ¶

quiet( string|array $message , integer $newlines 1 )

Output at all levels.

Parameters
string|array $message
A string or an array of strings to output
integer $newlines optional 1
Number of newlines to append
Returns
integer|boolean
Returns the number of bytes returned from writing to stdout.

runCommand() public ¶

runCommand( array $argv , boolean $autoMethod false )

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.

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.

Parameters
array $argv
Array of arguments to run the shell with. This array should be missing the shell name.
boolean $autoMethod optional false

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.

Returns
mixed
Link
http://book.cakephp.org/3.0/en/console-and-shells.html#the-cakephp-console

shortPath() public ¶

shortPath( string $file )

Makes absolute file path easier to read

Parameters
string $file
Absolute file path
Returns
string
short path
Link
http://book.cakephp.org/3.0/en/console-and-shells.html#Shell::shortPath

startup() public ¶

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.

Link
http://book.cakephp.org/3.0/en/console-and-shells.html#Cake\Console\ConsoleOptionParser::startup

verbose() public ¶

verbose( string|array $message , integer $newlines 1 )

Output at the verbose level.

Parameters
string|array $message
A string or an array of strings to output
integer $newlines optional 1
Number of newlines to append
Returns
integer|boolean
Returns the number of bytes returned from writing to stdout.

wrapText() public ¶

wrapText( string $text , integer|array $options [] )

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
Text the text to format.
integer|array $options optional []
Array of options to use, or an integer to wrap the text to.
Returns
string
Wrapped / indented text
See
\Cake\Utility\Text::wrap()
Link
http://book.cakephp.org/3.0/en/console-and-shells.html#Shell::wrapText

Methods used from Cake\Log\LogTrait

log() public ¶

log( mixed $msg , integer|string $level LogLevel::ERROR , string|array $context [] )

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

Parameters
mixed $msg
Log message.
integer|string $level optional LogLevel::ERROR
Error level.
string|array $context optional []
Additional log data relevant to this message.
Returns
boolean
Success of log write.

Methods used from Cake\Utility\MergeVariablesTrait

_mergeProperty() protected ¶

_mergeProperty( string $property , array $parentClasses , array $options )

Merge a single property with the values declared in all parent classes.

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

_mergePropertyData() protected ¶

_mergePropertyData( array $current , array $parent , boolean $isAssoc )

Merge each of the keys in a property together.

Parameters
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.
Returns
mixed
The updated value.

_mergeVars() protected ¶

_mergeVars( array $properties , array $options [] )

Merge the list of $properties with all parent classes of the current class.

Options:

  • associative - A list of properties that should be treated as associative arrays. Properties in this list will be passed through Hash::normalize() before merging.
Parameters
array $properties
An array of properties and the merge strategy for them.
array $options optional []
The options to use when merging properties.

Methods used from Cake\Datasource\ModelAwareTrait

_setModelClass() protected ¶

_setModelClass( string $name )

Set the modelClass and modelKey properties based on conventions.

If the properties are already set they will not be overwritten

Parameters
string $name
Class name.

loadModel() public ¶

loadModel( string|null $modelClass null , string $type 'Table' )

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.

Parameters
string|null $modelClass optional null
Name of model class to load. Defaults to $this->modelClass
string $type optional 'Table'

The type of repository to load. Defaults to 'Table' which delegates to Cake\ORM\TableRegistry.

Returns
object
The model instance created.
Throws
Cake\Datasource\Exception\MissingModelException
If the model class cannot be found.
InvalidArgumentException
When using a type that has not been registered.

modelFactory() public ¶

modelFactory( string $type , callable $factory )

Register a callable to generate repositories of a given type.

Parameters
string $type
The name of the repository type the factory function is for.
callable $factory
The factory function used to create instances.
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs