ROAResearch /
yii2-roa
| 1 | <?php |
||
| 2 | |||
| 3 | namespace roaresearch\yii2\roa\controllers; |
||
| 4 | |||
| 5 | use Yii; |
||
| 6 | use yii\{ |
||
| 7 | helpers\ArrayHelper, |
||
| 8 | web\GoneHttpException, |
||
| 9 | web\NotFoundHttpException |
||
| 10 | }; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Lists all the available versions for an api and handles error responses. |
||
| 14 | * |
||
| 15 | * @property \roaresearch\yii2\roa\modules\ApiContainer $module |
||
| 16 | * |
||
| 17 | * @author Angel (Faryshta) Guevara <[email protected]> |
||
| 18 | */ |
||
| 19 | class ApiContainerController extends \yii\rest\Controller |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @inheritdoc |
||
| 23 | */ |
||
| 24 | 1 | public function behaviors() |
|
| 25 | { |
||
| 26 | 1 | return []; |
|
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Lists the available versions and their respective stability for the |
||
| 31 | * parent module. |
||
| 32 | * |
||
| 33 | * @return string[] |
||
| 34 | */ |
||
| 35 | 1 | public function actionIndex(): array |
|
| 36 | { |
||
| 37 | 1 | return ArrayHelper::map( |
|
| 38 | 1 | $this->module->versionModules, |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
The property
versionModules does not exist on roaresearch\yii2\roa\modules\ApiContainer. Since you implemented __get, consider adding a @property annotation.
Loading history...
|
|||
| 39 | 'id', |
||
| 40 | 'factSheet' |
||
| 41 | ); |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Handles the exceptions catched by the system bootstrapping process. |
||
| 46 | * @return \Exception |
||
| 47 | */ |
||
| 48 | public function actionError(): \Exception |
||
| 49 | { |
||
| 50 | if (($exception = Yii::$app->getErrorHandler()->exception) === null) { |
||
| 51 | $exception = new NotFoundHttpException( |
||
| 52 | Yii::t('yii', 'Page not found.') |
||
| 53 | ); |
||
| 54 | } |
||
| 55 | |||
| 56 | Yii::$app->response->statusCode = isset($exception->statusCode) |
||
| 57 | ? $exception->statusCode |
||
| 58 | : 500; |
||
| 59 | |||
| 60 | return $exception; |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Action shown when a resource is no longer available. |
||
| 65 | * |
||
| 66 | * @throws GoneHttpException |
||
| 67 | */ |
||
| 68 | public function actionGone() |
||
| 69 | { |
||
| 70 | throw new GoneHttpException( |
||
| 71 | 'The resource you seek is obsolete, visit ' |
||
| 72 | . $this->module->getSelfLink() |
||
| 73 | . ' to get the fact sheets of all available versions.' |
||
| 74 | ); |
||
| 75 | } |
||
| 76 | } |
||
| 77 |