Fixes #14188: Add constants and function for sysexits(3) to ConsoleHelper

This commit is contained in:
Carsten Brandt
2017-07-15 22:26:15 +02:00
committed by Alexander Makarov
parent 0adae899ce
commit 2f9f15bf92
9 changed files with 218 additions and 38 deletions

View File

@ -267,12 +267,21 @@ public function actionIndex()
}
```
There are some predefined constants you can use:
There are some predefined constants you can use. These are defined in the [[yii\console\ExitCode]] class:
- [[yii\console\Controller::EXIT_CODE_NORMAL|Controller::EXIT_CODE_NORMAL]] with value of `0`;
- [[yii\console\Controller::EXIT_CODE_ERROR|Controller::EXIT_CODE_ERROR]] with value of `1`.
```php
public function actionIndex()
{
if (/* some problem */) {
echo "A problem occurred!\n";
return ExitCode::UNSPECIFIED_ERROR;
}
// do something
return ExitCode::OK;
}
```
It's a good practice to define meaningful constants for your controller in case you have more error code types.
It's a good practice to define meaningful constants for your controller in case you have more specific error code types.
### Formatting and colors