| Package | system.console |
|---|---|
| Inheritance | class CConsoleApplication » CApplication » CModule » CComponent |
| Since | 1.0 |
| Version | $Id$ |
| Source Code | framework/console/CConsoleApplication.php |
php path/to/entry_script.php <command name> [param 1] [param 2] ...
php path/to/entry_script.php help <command name>
| Property | Type | Description | Defined By |
|---|---|---|---|
| basePath | string | the root directory of the application. | CApplication |
| behaviors | array | the behaviors that should be attached to the module. | CModule |
| cache | CCache | the cache application component. | CApplication |
| charset | string | the charset currently used for the application. | CApplication |
| commandMap | array | mapping from command name to command configurations. | CConsoleApplication |
| commandPath | string | the directory that contains the command classes. | CConsoleApplication |
| commandRunner | CConsoleCommandRunner | Returns the command runner. | CConsoleApplication |
| components | array | the currently loaded components (indexed by their IDs) | CModule |
| coreMessages | CPhpMessageSource | the core message translations | CApplication |
| dateFormatter | CDateFormatter | the locale-dependent date formatter. | CApplication |
| db | CDbConnection | the database connection | CApplication |
| errorHandler | CErrorHandler | the error handler application component. | CApplication |
| extensionPath | string | Returns the root directory that holds all third-party extensions. | CApplication |
| id | string | a unique identifier for the application. | CApplication |
| language | string | the language that the user is using and the application should be targeted to. | CApplication |
| locale | CLocale | the locale instance | CApplication |
| messages | CMessageSource | the application message translations | CApplication |
| modulePath | string | the directory that contains the application modules. | CModule |
| modules | array | the configuration of the currently installed modules (module ID => configuration) | CModule |
| name | string | the application name. | CApplication |
| numberFormatter | CNumberFormatter | the locale-dependent number formatter. | CApplication |
| params | CAttributeCollection | the list of user-defined parameters | CModule |
| parentModule | CModule | the parent module. | CModule |
| preload | array | the IDs of the application components that should be preloaded. | CModule |
| request | CHttpRequest | the request component | CApplication |
| runtimePath | string | the directory that stores runtime files. | CApplication |
| securityManager | CSecurityManager | the security manager application component. | CApplication |
| sourceLanguage | string | the language that the application is written in. | CApplication |
| statePersister | CStatePersister | the state persister application component. | CApplication |
| timeZone | string | Returns the time zone used by this application. | CApplication |
| urlManager | CUrlManager | the URL manager component | CApplication |
| Method | Description | Defined By |
|---|---|---|
| __call() | Calls the named method which is not a class method. | CComponent |
| __construct() | Constructor. | CApplication |
| __get() | Getter magic method. | CModule |
| __isset() | Checks if a property value is null. | CModule |
| __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 |
| canGetProperty() | Determines whether a property can be read. | CComponent |
| canSetProperty() | Determines whether a property can be set. | CComponent |
| clearGlobalState() | Clears a global value. | CApplication |
| configure() | Configures the module with the specified configuration. | CModule |
| 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 |
| displayError() | Displays the captured PHP error. | CConsoleApplication |
| displayException() | Displays the uncaught PHP exception. | CConsoleApplication |
| enableBehavior() | Enables an attached behavior. | CComponent |
| enableBehaviors() | Enables all behaviors attached to this component. | CComponent |
| end() | Terminates the application. | CApplication |
| findLocalizedFile() | Returns the localized version of a specified file. | CApplication |
| getBasePath() | Returns the root directory of the application. Defaults to 'protected'. | CApplication |
| getCache() | Returns the cache application component. Null if the component is not enabled. | CApplication |
| getCommandPath() | Returns the directory that contains the command classes. Defaults to 'protected/commands'. | CConsoleApplication |
| getCommandRunner() | Returns the command runner. | CConsoleApplication |
| getComponent() | Retrieves the named application component. | CModule |
| getComponents() | Returns the currently loaded components (indexed by their IDs) | CModule |
| getCoreMessages() | Returns the core message translations | CApplication |
| getDateFormatter() | Returns the locale-dependent date formatter. The current application locale will be used. | CApplication |
| getDb() | Returns the database connection | CApplication |
| getErrorHandler() | Returns the error handler application component. | CApplication |
| getEventHandlers() | Returns the list of attached event handlers for an event. | CComponent |
| getExtensionPath() | Returns the root directory that holds all third-party extensions. | CApplication |
| getGlobalState() | Returns a global value. | CApplication |
| getId() | Returns a unique identifier for the application. | CApplication |
| getLanguage() | Returns the language that the user is using and the application should be targeted to. Defaults to the source language. | CApplication |
| getLocale() | Returns the locale instance | CApplication |
| getMessages() | Returns the application message translations | CApplication |
| getModule() | Retrieves the named application module. | CModule |
| getModulePath() | Returns the directory that contains the application modules. Defaults to the 'modules' subdirectory of basePath. | CModule |
| getModules() | Returns the configuration of the currently installed modules (module ID => configuration) | CModule |
| getNumberFormatter() | Returns the locale-dependent number formatter. The current application locale will be used. | CApplication |
| getParams() | Returns the list of user-defined parameters | CModule |
| getParentModule() | Returns the parent module. Null if this module does not have a parent. | CModule |
| getRequest() | Returns the request component | CApplication |
| getRuntimePath() | Returns the directory that stores runtime files. Defaults to 'protected/runtime'. | CApplication |
| getSecurityManager() | Returns the security manager application component. | CApplication |
| getStatePersister() | Returns the state persister application component. | CApplication |
| getTimeZone() | Returns the time zone used by this application. | CApplication |
| getUrlManager() | Returns the URL manager component | CApplication |
| handleError() | Handles PHP execution errors such as warnings, notices. | CApplication |
| handleException() | Handles uncaught PHP exceptions. | CApplication |
| hasComponent() | Determines whether the named application component exists (including both loaded and disabled.) | CModule |
| 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 |
| onBeginRequest() | Raised right BEFORE the application processes the request. | CApplication |
| onEndRequest() | Raised right AFTER the application processes the request. | CApplication |
| onError() | Raised when a PHP execution error occurs. | CApplication |
| onException() | Raised when an uncaught PHP exception occurs. | CApplication |
| processRequest() | Processes the user request. | CConsoleApplication |
| raiseEvent() | Raises an event. | CComponent |
| run() | Runs the application. | CApplication |
| setAliases() | Defines the root aliases. | CModule |
| setBasePath() | Sets the root directory of the application. | CApplication |
| setCommandPath() | Sets the directory that contains the command classes. | CConsoleApplication |
| setComponent() | Puts a component under the management of the module. | CModule |
| setComponents() | Sets the application components. | CModule |
| setExtensionPath() | Sets the directory that contains all third-party extensions. | CApplication |
| setGlobalState() | Sets a global value. | CApplication |
| setId() | Sets a unique identifier for the application. | CApplication |
| setImport() | Sets the aliases that are used in the module. | CModule |
| setLanguage() | Specifies which language the application is targeted to. | CApplication |
| setModulePath() | Sets the directory that contains the application modules. | CModule |
| setModules() | Configures the sub-modules of this module. | CModule |
| setParams() | Sets user-defined parameters. This should be in name-value pairs. | CModule |
| setRuntimePath() | Sets the directory that stores runtime files. | CApplication |
| setTimeZone() | Sets the time zone used by this application. | CApplication |
| Method | Description | Defined By |
|---|---|---|
| createCommandRunner() | Creates the command runner instance. | CConsoleApplication |
| init() | Initializes the application by creating the command runner. | CConsoleApplication |
| initSystemHandlers() | Initializes the class autoloader and error handlers. | CApplication |
| loadGlobalState() | Loads the global state data from persistent storage. | CApplication |
| preinit() | Preinitializes the module. | CModule |
| preloadComponents() | Loads static application components. | CModule |
| registerCoreComponents() | Registers the core application components. | CApplication |
| saveGlobalState() | Saves the global state data into persistent storage. | CApplication |
| Event | Description | Defined By |
|---|---|---|
| onBeginRequest | Raised right BEFORE the application processes the request. | CApplication |
| onEndRequest | Raised right AFTER the application processes the request. | CApplication |
| onException | Raised when an uncaught PHP exception occurs. | CApplication |
| onError | Raised when a PHP execution error occurs. | CApplication |
mapping from command name to command configurations. Each command configuration can be either a string or an array. If the former, the string should be the file path of the command class. If the latter, the array must contain a 'class' element which specifies the command's class name or class path alias. The rest name-value pairs in the array are used to initialize the corresponding command properties. For example,
array(
'email'=>array(
'class'=>'path.to.Mailer',
'interval'=>3600,
),
'log'=>'path/to/LoggerCommand.php',
)
the directory that contains the command classes. Defaults to 'protected/commands'.
Returns the command runner.
|
protected CConsoleCommandRunner createCommandRunner()
| ||
| {return} | CConsoleCommandRunner | the command runner |
protected function createCommandRunner()
{
return new CConsoleCommandRunner;
}
Creates the command runner instance.
|
public void displayError(integer $code, string $message, string $file, string $line)
| ||
| $code | integer | error code |
| $message | string | error message |
| $file | string | error file |
| $line | string | error line |
public function displayError($code,$message,$file,$line)
{
echo "PHP Error[$code]: $message\n";
echo "in file $file at line $line\n";
debug_print_backtrace();
}
Displays the captured PHP error. This method displays the error in console mode when there is no active error handler.
|
public void displayException(Exception $exception)
| ||
| $exception | Exception | the uncaught exception |
public function displayException($exception)
{
echo $exception;
}
Displays the uncaught PHP exception. This method displays the exception in console mode when there is no active error handler.
|
public string getCommandPath()
| ||
| {return} | string | the directory that contains the command classes. Defaults to 'protected/commands'. |
public function getCommandPath()
{
if($this->_commandPath===null)
$this->setCommandPath($this->getBasePath().DIRECTORY_SEPARATOR.'commands');
return $this->_commandPath;
}
|
public CConsoleCommandRunner getCommandRunner()
| ||
| {return} | CConsoleCommandRunner | the command runner. |
public function getCommandRunner()
{
return $this->_runner;
}
Returns the command runner.
|
protected void init()
|
protected function init()
{
parent::init();
if(!isset($_SERVER['argv'])) // || strncasecmp(php_sapi_name(),'cli',3))
die('This script must be run from the command line.');
$this->_runner=$this->createCommandRunner();
$this->_runner->commands=$this->commandMap;
$this->_runner->addCommands($this->getCommandPath());
}
Initializes the application by creating the command runner.
|
public void processRequest()
|
public function processRequest()
{
$this->_runner->run($_SERVER['argv']);
}
Processes the user request. This method creates a console command runner to handle the particular user command.
|
public void setCommandPath(string $value)
| ||
| $value | string | the directory that contains the command classes. |
public function setCommandPath($value)
{
if(($this->_commandPath=realpath($value))===false || !is_dir($this->_commandPath))
throw new CException(Yii::t('yii','The command path "{path}" is not a valid directory.',
array('{path}'=>$value)));
}
Signup or Login in order to comment.