Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • Net
  • None
  • PHP
  • system
    • base
    • caching
      • dependencies
    • collections
    • console
    • db
      • ar
      • schema
        • cubrid
        • mssql
        • mysql
        • oci
        • pgsql
        • sqlite
    • i18n
      • gettext
    • logging
    • test
    • utils
    • validators
    • web
      • actions
      • auth
      • filters
      • form
      • helpers
      • renderers
      • services
      • widgets
        • captcha
        • pagers
  • Text
    • Highlighter
  • zii
    • behaviors
    • widgets
      • grid
      • jui

Classes

  • CConsoleApplication
  • CConsoleCommand
  • CConsoleCommandBehavior
  • CConsoleCommandEvent
  • CConsoleCommandRunner
  • CHelpCommand
  • ThemeBuildCommand
  • Overview
  • Package
  • Class
  • Tree

Class CConsoleCommand

CConsoleCommand represents an executable console command.

It works like CController by parsing command line options and dispatching the request to a specific action with appropriate option values.

Users call a console command via the following command format:

yiic CommandName ActionName --Option1=Value1 --Option2=Value2 ...

Child classes mainly needs to implement various action methods whose name must be prefixed with "action". The parameters to an action method are considered as options for that specific action. The action specified as CConsoleCommand::$defaultAction will be invoked when a user does not specify the action name in his command.

Options are bound to action parameters via parameter names. For example, the following action method will allow us to run a command with yiic sitemap --type=News:

class SitemapCommand extends CConsoleCommand {
    public function actionIndex($type) {
        ....
    }
}

Since version 1.1.11 the return value of action methods will be used as application exit code if it is an integer value.

CComponent
Extended by CConsoleCommand

Direct known subclasses

AutomaticTranslationCommand, CHelpCommand, UpdateCommand, UpdaterPackageCommand, X2ConsoleCommand, CronCommand, CryptSetupCommand, DummyCommand, ExportFixtureCommand, RepairUserDataCommand, RunMigrationScriptCommand, SampleDataCommand, ThemeBuildCommand

Indirect known subclasses

MigrateCustomCommand
Abstract
Package: system\console
Copyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 1.0
Located at x2engine/framework/console/CConsoleCommand.php
Methods summary
public
# __construct( string $name, CConsoleCommandRunner $runner )

Constructor.

Constructor.

Parameters

$name
string
$name name of the command
$runner
CConsoleCommandRunner
$runner the command runner
public
# init( )

Initializes the command object. This method is invoked after a command object is created and initialized with configurations. You may override this method to further customize the command before it executes.

Initializes the command object. This method is invoked after a command object is created and initialized with configurations. You may override this method to further customize the command before it executes.

Since

1.1.6
public array
# behaviors( )

Returns a list of behaviors that this command should behave as. The return value should be an array of behavior configurations indexed by behavior names. Each behavior configuration can be either a string specifying the behavior class or an array of the following structure:

'behaviorName'=>array(
    'class'=>'path.to.BehaviorClass',
    'property1'=>'value1',
    'property2'=>'value2',
)

Returns a list of behaviors that this command should behave as. The return value should be an array of behavior configurations indexed by behavior names. Each behavior configuration can be either a string specifying the behavior class or an array of the following structure:

'behaviorName'=>array(
    'class'=>'path.to.BehaviorClass',
    'property1'=>'value1',
    'property2'=>'value2',
)

Note, the behavior classes must implement IBehavior or extend from CBehavior. Behaviors declared in this method will be attached to the controller when it is instantiated.

For more details about behaviors, see CComponent.

Returns

array
the behavior configurations (behavior name=>behavior configuration)

Since

1.1.11
public integer
# run( array $args )

Executes the command. The default implementation will parse the input parameters and dispatch the command request to an appropriate action with the corresponding option values

Executes the command. The default implementation will parse the input parameters and dispatch the command request to an appropriate action with the corresponding option values

Parameters

$args
array
$args command line parameters for this command.

Returns

integer
application exit code, which is returned by the invoked action. 0 if the action did not return anything. (return value is available since version 1.1.11)
protected boolean
# beforeAction( string $action, array $params )

This method is invoked right before an action is to be executed. You may override this method to do last-minute preparation for the action.

This method is invoked right before an action is to be executed. You may override this method to do last-minute preparation for the action.

Parameters

$action
string
$action the action name
$params
array
$params the parameters to be passed to the action method.

Returns

boolean
whether the action should be executed.
protected integer
# afterAction( string $action, array $params, integer $exitCode = 0 )

This method is invoked right after an action finishes execution. You may override this method to do some postprocessing for the action.

This method is invoked right after an action finishes execution. You may override this method to do some postprocessing for the action.

Parameters

$action
string
$action the action name
$params
array
$params the parameters to be passed to the action method.
$exitCode
integer
$exitCode the application exit code returned by the action method.

Returns

integer
application exit code (return value is available since version 1.1.11)
protected array
# resolveRequest( array $args )

Parses the command line arguments and determines which action to perform.

Parses the command line arguments and determines which action to perform.

Parameters

$args
array
$args command line arguments

Returns

array
the action name, named options (name=>value), and unnamed options

Since

1.1.5
public string
# getName( )

Returns

string
the command name.
public CConsoleCommandRunner
# getCommandRunner( )

Returns

CConsoleCommandRunner
the command runner instance
public string
# getHelp( )

Provides the command description. This method may be overridden to return the actual command description.

Provides the command description. This method may be overridden to return the actual command description.

Returns

string
the command description. Defaults to 'Usage: php entry-script.php command-name'.
public array
# getOptionHelp( )

Provides the command option help information. The default implementation will return all available actions together with their corresponding option information.

Provides the command option help information. The default implementation will return all available actions together with their corresponding option information.

Returns

array
the command option help information. Each array element describes the help information for a single action.

Since

1.1.5
public
# usageError( string $message )

Displays a usage error. This method will then terminate the execution of the current application.

Displays a usage error. This method will then terminate the execution of the current application.

Parameters

$message
string
$message the error message
public
# copyFiles( array $fileList )

Copies a list of files from one place to another.

Copies a list of files from one place to another.

Parameters

$fileList
array
$fileList the list of files to be copied (name=>spec). The array keys are names displayed during the copy process, and array values are specifications for files to be copied. Each array value must be an array of the following structure:
  • source: required, the full path of the file/directory to be copied from
  • target: required, the full path of the file/directory to be copied to
  • callback: optional, the callback to be invoked when copying a file. The callback function should be declared as follows: <pre> function foo($source,$params) </pre> where $source parameter is the source file path, and the content returned by the function will be saved into the target file.
  • params: optional, the parameters to be passed to the callback

See

CConsoleCommand::buildFileList()
public array
# buildFileList( string $sourceDir, string $targetDir, string $baseDir = '', array $ignoreFiles = array(), array $renameMap = array() )

Builds the file list of a directory. This method traverses through the specified directory and builds a list of files and subdirectories that the directory contains. The result of this function can be passed to CConsoleCommand::copyFiles().

Builds the file list of a directory. This method traverses through the specified directory and builds a list of files and subdirectories that the directory contains. The result of this function can be passed to CConsoleCommand::copyFiles().

Parameters

$sourceDir
string
$sourceDir the source directory
$targetDir
string
$targetDir the target directory
$baseDir
string
$baseDir base directory
$ignoreFiles
array
$ignoreFiles list of the names of files that should be ignored in list building process. Argument available since 1.1.11.
$renameMap
array
$renameMap hash array of file names that should be renamed. Example value: array('1.old.txt'=>'2.new.txt'). Argument available since 1.1.11.

Returns

array
the file list (see CConsoleCommand::copyFiles())
public
# ensureDirectory( string $directory )

Creates all parent directories if they do not exist.

Creates all parent directories if they do not exist.

Parameters

$directory
string
$directory the directory to be checked
public mixed
# renderFile( string $_viewFile_, array $_data_ = null, boolean $_return_ = false )

Renders a view file.

Renders a view file.

Parameters

$_viewFile_
string
$_viewFile_ view file path
$_data_
array
$_data_ optional data to be extracted as local view variables
$_return_
boolean
$_return_ whether to return the rendering result instead of displaying it

Returns

mixed
the rendering result if required. Null otherwise.
public string
# pluralize( string $name )

Converts a word to its plural form.

Converts a word to its plural form.

Parameters

$name
string
$name the word to be pluralized

Returns

string
the pluralized word
public mixed
# prompt( string $message, string $default = null )

Reads input via the readline PHP extension if that's available, or fgets() if readline is not installed.

Reads input via the readline PHP extension if that's available, or fgets() if readline is not installed.

Parameters

$message
string
$message to echo out before waiting for user input
$default
string
$default the default string to be returned when user does not write anything. Defaults to null, means that default string is disabled. This parameter is available since version 1.1.11.

Returns

mixed
line read as a string, or false if input has been closed

Since

1.1.9
public boolean
# confirm( string $message, boolean $default = false )

Asks user to confirm by typing y or n.

Asks user to confirm by typing y or n.

Parameters

$message
string
$message to echo out before waiting for user input
$default
boolean
$default this value is returned if no selection is made. This parameter has been available since version 1.1.11.

Returns

boolean
whether user confirmed

Since

1.1.9
public
# onBeforeAction( CConsoleCommandEvent $event )

This event is raised before an action is to be executed.

This event is raised before an action is to be executed.

Parameters

$event
CConsoleCommandEvent
$event the event parameter

Since

1.1.11
public
# onAfterAction( CConsoleCommandEvent $event )

This event is raised after an action finishes execution.

This event is raised after an action finishes execution.

Parameters

$event
CConsoleCommandEvent
$event the event parameter

Since

1.1.11
Methods inherited from CComponent
__call(), __get(), __isset(), __set(), __unset(), asa(), attachBehavior(), attachBehaviors(), attachEventHandler(), canGetProperty(), canSetProperty(), detachBehavior(), detachBehaviors(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), getEventHandlers(), hasEvent(), hasEventHandler(), hasProperty(), raiseEvent()
Properties summary
public string $defaultAction 'index'
#

the name of the default action. Defaults to 'index'.

the name of the default action. Defaults to 'index'.

Since

1.1.5
Magic properties summary
public string $name
#

The command name.

The command name.

public CConsoleCommandRunner $commandRunner
#

The command runner instance.

The command runner instance.

public string $help
#

The command description. Defaults to 'Usage: php entry-script.php command-name'.

The command description. Defaults to 'Usage: php entry-script.php command-name'.

public array $optionHelp
#

The command option help information. Each array element describes the help information for a single action.

The command option help information. Each array element describes the help information for a single action.

API documentation generated by ApiGen 2.8.0