system system.base system.caching system.caching.dependencies system.collections system.console system.db system.db.ar system.db.schema system.db.schema.mssql system.db.schema.mysql system.db.schema.oci system.db.schema.pgsql system.db.schema.sqlite system.i18n system.i18n.gettext system.logging system.utils system.validators system.web system.web.actions system.web.auth system.web.filters system.web.helpers system.web.renderers system.web.services system.web.widgets system.web.widgets.captcha system.web.widgets.pagers

CConsoleCommand

system.console
继承 abstract class CConsoleCommand » CComponent
子类 CHelpCommand
可用自 1.0
版本 $Id$
CConsoleCommand represents an executable user command.

The run method must be implemented with the actual command execution logic. You may override getHelp to provide more detailed description of the command.

公共属性

隐藏继承的属性

属性类型描述被定义在
commandRunner CConsoleCommandRunner the command runner instance CConsoleCommand
help string Provides the command description. CConsoleCommand
name string the command name. CConsoleCommand

公共方法

隐藏继承的方法

方法描述被定义在
__call() Calls the named method which is not a class method. CComponent
__construct() Constructor. CConsoleCommand
__get() Returns a property value, an event handler list or a behavior based on its name. CComponent
__isset() Checks if a property value is null. CComponent
__set() Sets value of a component property. CComponent
__unset() Sets a component property to be null. CComponent
asa() Returns the named behavior object. CComponent
attachBehavior() Attaches a behavior to this component. CComponent
attachBehaviors() Attaches a list of behaviors to the component. CComponent
attachEventHandler() Attaches an event handler to an event. CComponent
buildFileList() Builds the file list of a directory. CConsoleCommand
canGetProperty() Determines whether a property can be read. CComponent
canSetProperty() Determines whether a property can be set. CComponent
copyFiles() Copies a list of files from one place to another. CConsoleCommand
detachBehavior() Detaches a behavior from the component. CComponent
detachBehaviors() Detaches all behaviors from the component. CComponent
detachEventHandler() Detaches an existing event handler. CComponent
disableBehavior() Disables an attached behavior. CComponent
disableBehaviors() Disables all behaviors attached to this component. CComponent
enableBehavior() Enables an attached behavior. CComponent
enableBehaviors() Enables all behaviors attached to this component. CComponent
ensureDirectory() Creates all parent directories if they do not exist. CConsoleCommand
getCommandRunner() CConsoleCommand
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
getHelp() Provides the command description. CConsoleCommand
getName() CConsoleCommand
hasEvent() Determines whether an event is defined. CComponent
hasEventHandler() Checks whether the named event has attached handlers. CComponent
hasProperty() Determines whether a property is defined. CComponent
pluralize() Converts a word to its plural form. CConsoleCommand
raiseEvent() Raises an event. CComponent
renderFile() Renders a view file. CConsoleCommand
run() Executes the command. CConsoleCommand
usageError() Displays a usage error. CConsoleCommand

属性详情

commandRunner 属性 只读

the command runner instance

help 属性 只读
public string getHelp()

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

name 属性 只读
public string getName()

the command name.

方法详情

__construct() 方法
public void __construct(string $name, CConsoleCommandRunner $runner)
$name string name of the command
$runner CConsoleCommandRunner the command runner

Constructor.

buildFileList() 方法
public array buildFileList(string $sourceDir, string $targetDir, string $baseDir='')
$sourceDir string the source directory
$targetDir string the target directory
$baseDir string base directory
{return} array the file list (see 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 copyFiles.

copyFiles() 方法
public void copyFiles(array $fileList)
$fileList array 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:
      function foo($source,$params)
      
    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

Copies a list of files from one place to another.

参见

ensureDirectory() 方法
public void ensureDirectory(string $directory)
$directory string the directory to be checked

Creates all parent directories if they do not exist.

getCommandRunner() 方法
public CConsoleCommandRunner getCommandRunner()
{return} CConsoleCommandRunner the command runner instance

getHelp() 方法
public string getHelp()
{return} string the command description. Defaults to 'Usage: php entry-script.php command-name'.

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

getName() 方法
public string getName()
{return} string the command name.

pluralize() 方法
public string pluralize(string $name)
$name string the word to be pluralized
{return} string the pluralized word

Converts a word to its plural form.

renderFile() 方法
public mixed renderFile(string $_viewFile_, array $_data_=NULL, boolean $_return_=false)
$_viewFile_ string view file path
$_data_ array optional data to be extracted as local view variables
$_return_ boolean whether to return the rendering result instead of displaying it
{return} mixed the rendering result if required. Null otherwise.

Renders a view file.

run() 方法
abstract public void run(array $args)
$args array command line parameters for this command.

Executes the command.

usageError() 方法
public void usageError(string $message)
$message string the error message

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