Completed
Push — master ( a107f0...697b33 )
by graychen
12:14 queued 03:42
created

Module::init()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 0
1
<?php
2
3
namespace graychen\yii2\jd\deposit;
4
5
use yii;
6
use yii\web\Response;
7
8
/**
9
 * api module definition class
10
 */
11
class Module extends \yii\base\Module
12
{
13
    /**
14
     * @inheritdoc
15
     */
16
    public $controllerNamespace = 'api\modules\jd\controllers';
17
18
    /**
19
     * @inheritdoc
20
     */
21
    public function init()
22
    {
23
        parent::init();
24
        if (YII_DEBUG) {
25
            $tag = Yii::$app->log->targets['debug']->tag;
26
            $url = getenv('APP_HOST') . 'api/debug/default/view?tag=' . $tag . '&panel=api';
27
            Yii::$app->response->headers->add('x-debug-tag', $tag);
28
            Yii::$app->response->headers->add('x-debug-url', $url);
29
        }
30
        Yii::$app->response->format = Response::FORMAT_JSON;
31
        Yii::$app->response->headers->add('x-author', 'lianluo.com');
32
        if (YII_DEBUG) {
33
            Yii::$app->response->headers->add('x-debug-tag', Yii::$app->log->targets['debug']->tag);
34
        }
35
        Yii::$app->user->enableSession = false;
36
        Yii::$app->user->loginUrl = null;
37
        Yii::$app->request->parsers = [
38
            'application/json' => 'yii\web\JsonParser',
39
        ];
40
        //在API接口模块执行严格URL检查
41
        Yii::$app->urlManager->enableStrictParsing = true;
42
    }
43
}
44