<?php
$params = array_merge(
    require __DIR__ . '/../../common/config/params.php',
    require __DIR__ . '/../../common/config/params-swoole.php',
    require __DIR__ . '/params.php'
);
$urlManagerRules = require __DIR__ . '/urlManagerRules.php';
return [
    'id' => 'app-backendApi',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'modules' => [
        'v1' => [
            'basePath' => '@backendApi/modules/v1',
            'class' => 'backendApi\modules\v1\Module'
        ],
    ],
    'components' => [
        'request' => [
            'class' => \common\components\Request::class,
            'parsers' => [
                'application/json' => 'yii\web\JsonParser',
                'text/json' => 'yii\web\JsonParser',
            ]
        ],
        'response' => [
            'class' => 'yii\web\Response',
            'format' => 'json',
            'on beforeSend' => function ($event) {
                $response = $event->sender;
                if ($response->data !== null &&  Yii::$app->request->getSuppressResponseCode()) {
                    $response->data = [
                        'success' => $response->isSuccessful,
                        'data' => $response->data,
                    ];
                    $response->statusCode = 200;
                }
            },
        ],
        'user' => [
            'class' => 'backendApi\modules\v1\components\UserAuth',
            'identityClass' => 'backendApi\modules\v1\models\User',
            'enableAutoLogin' => false,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'urlManager' => [
            'enablePrettyUrl' => true,
            'enableStrictParsing' => true,
            'showScriptName' => false,
            'rules' => $urlManagerRules,
        ],

    ],
    'params' => $params,
];
