Completed
Push — master ( 62ede7...735413 )
by Nate
03:44
created

AbstractController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 49
ccs 0
cts 34
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 11 1
A behaviors() 0 20 1
A verbs() 0 4 1
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipbox/spark/blob/master/LICENSE
6
 * @link       https://github.com/flipbox/spark
7
 */
8
9
namespace flipbox\spark\controllers;
10
11
use Craft;
12
use craft\helpers\ArrayHelper;
13
use craft\web\Controller;
14
use yii\filters\ContentNegotiator;
15
use yii\filters\VerbFilter;
16
use yii\web\JsonParser;
17
use yii\web\Response;
18
19
/**
20
 * @author Flipbox Factory <[email protected]>
21
 * @since 1.0.0
22
 */
23
abstract class AbstractController extends Controller
24
{
25
    /**
26
     * @inheritdoc
27
     */
28
    public function init()
29
    {
30
        parent::init();
31
32
        Craft::$app->getRequest()->parsers = array_merge(
33
            Craft::$app->getRequest()->parsers,
34
            [
35
                'application/json' => JsonParser::class
36
            ]
37
        );
38
    }
39
40
    /**
41
     * @return array
42
     */
43
    public function behaviors()
44
    {
45
        return ArrayHelper::merge(
46
            parent::behaviors(),
47
            [
48
                'verbFilter' => [
49
                    'class' => VerbFilter::class,
50
                    'actions' => $this->verbs(),
51
                ],
52
                'contentNegotiator' => [
53
                    'class' => ContentNegotiator::class,
54
                    'formats' => [
55
                        'application/json' => Response::FORMAT_JSON,
56
                        'application/xml' => Response::FORMAT_XML,
57
                        'text/html' => Response::FORMAT_RAW
58
                    ]
59
                ]
60
            ]
61
        );
62
    }
63
64
    /**
65
     * @return array
66
     */
67
    protected function verbs(): array
68
    {
69
        return [];
70
    }
71
}
72