Completed
Push — master ( 6db6da...5370d9 )
by Angel
03:42
created

ApiContainerController::actionIndex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
    public function behaviors()
25
    {
26
        return [];
27
    }
28
29
    /**
30
     * Lists the available versions and their respective stability for the
31
     * parent module.
32
     *
33
     * @return string[]
34
     */
35
    public function actionIndex()
36
    {
37
        return ArrayHelper::map(
38
            $this->module->versionModules,
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()
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