for consistency: alwas return integer exit code

the default implementation of CConsoleCommand now always returns integer
exit code.
If for some reason someone does not want application to exit he could
overide run() method to return null or some other non integer value.
This commit is contained in:
Carsten Brandt
2012-04-27 22:28:01 +02:00
parent e45ee07185
commit a6d8222df1
4 changed files with 11 additions and 10 deletions

View File

@@ -84,7 +84,7 @@ class CConsoleApplication extends CApplication
/**
* Processes the user request.
* This method creates a console command runner to handle the particular user command.
* This method uses a console command runner to handle the particular user command.
* Since version 1.1.11 this method will exit application with an exit code if one is returned by the user command.
*/
public function processRequest()

View File

@@ -112,8 +112,7 @@ abstract class CConsoleCommand extends CComponent
* dispatch the command request to an appropriate action with the corresponding
* option values
* @param array $args command line parameters for this command.
* @return int|null application exit code returned by the action
* will return null when action has been aborted by {@link onBeforeAction} event
* @return integer application exit code returned by the action, 0 if action does not return anything
* (return value is available since version 1.1.11)
*/
public function run($args)
@@ -168,11 +167,13 @@ abstract class CConsoleCommand extends CComponent
if(!empty($options))
$this->usageError("Unknown options: ".implode(', ',array_keys($options)));
$exitCode=0;
if($this->beforeAction($action,$params))
{
$exitCode=$method->invokeArgs($this,$params);
return $this->afterAction($action,$params,$exitCode);
$exitCode=$this->afterAction($action,$params,is_int($exitCode)?$exitCode:0);
}
return $exitCode;
}
/**
@@ -201,10 +202,10 @@ abstract class CConsoleCommand extends CComponent
* You may override this method to do some postprocessing for the action.
* @param string $action the action name
* @param array $params the parameters to be passed to the action method.
* @param int|null $exitCode the application exit code returned by the action method.
* @return int|null application exit code (return value is available since version 1.1.11)
* @param integer $exitCode the application exit code returned by the action method.
* @return integer application exit code (return value is available since version 1.1.11)
*/
protected function afterAction($action,$params,$exitCode=null)
protected function afterAction($action,$params,$exitCode=0)
{
$event=new CConsoleCommandEvent($this,$params,$action,$exitCode);
if($this->hasEventHandler('onAfterAction'))

View File

@@ -31,7 +31,7 @@ class CConsoleCommandEvent extends CEvent
*/
public $stopCommand=false;
/**
* @var int exit code of application.
* @var integer exit code of application.
* This property is available in {@link CConsoleCommand::onAfterAction} event and will be set to the exit code
* returned by the console command action. You can set it to change application exit code.
*/
@@ -42,7 +42,7 @@ class CConsoleCommandEvent extends CEvent
* @param mixed $sender sender of the event
* @param string $params the parameters to be passed to the action method.
* @param string $action the action name
* @param string $exitCode the application exit code
* @param integer $exitCode the application exit code
*/
public function __construct($sender=null,$params=null,$action=null,$exitCode=0){
parent::__construct($sender,$params);

View File

@@ -46,7 +46,7 @@ class CConsoleCommandRunner extends CComponent
/**
* Executes the requested command.
* @param array $args list of user supplied parameters (including the entry script name and the command name).
* @return int|null application exit code returned by the command
* @return integer|null application exit code returned by the command
* (return value is available since version 1.1.11)
*/
public function run($args)