Skip to content

Commit

Permalink
for consistency: alwas return integer exit code
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cebe committed Apr 27, 2012
1 parent e45ee07 commit a6d8222
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion framework/console/CConsoleApplication.php
Expand Up @@ -84,7 +84,7 @@ protected function init()

/**
* 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()
Expand Down
13 changes: 7 additions & 6 deletions framework/console/CConsoleCommand.php
Expand Up @@ -112,8 +112,7 @@ public function behaviors()
* 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)
Expand Down Expand Up @@ -168,11 +167,13 @@ public function run($args)
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;
}

/**
Expand Down Expand Up @@ -201,10 +202,10 @@ protected function beforeAction($action,$params)
* 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'))
Expand Down
4 changes: 2 additions & 2 deletions framework/console/CConsoleCommandEvent.php
Expand Up @@ -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.
*/
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion framework/console/CConsoleCommandRunner.php
Expand Up @@ -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)
Expand Down

0 comments on commit a6d8222

Please sign in to comment.