<?php
$params = array_merge(
    require(__DIR__ . '/../../common/config/params.php'),
    require(__DIR__ . '/params.php'),
    require(__DIR__ . '/params-local.php')
);
return [
    'id' => 'api',
    'basePath' => dirname(__DIR__),
    'controllerNamespace' => 'api\common\controllers',
    'components' => [
        'user' => [
            'identityClass' => 'api\common\models\User',
        ],
        'urlManager' => [
            'enablePrettyUrl' => true,
            'enableStrictParsing' => true,//严格url管理，增强接口安全性
            'showScriptName' => false,
            'rules' => [
                [
                    'class' => 'yii\rest\UrlRule',
                    'pluralize' => false,//关闭路由自动复数，减少开发成本
                    'controller' => [
                        'v1/carousel',
                        'v1/category',
                        'v1/tag',
                        'v1/comment',
                        'v1/suggest',
                    ]
                ],
                [
                    'class' => 'yii\rest\UrlRule',
                    'pluralize' => false,
                    'controller' => 'v1/article',
                    'extraPatterns' => [
                        'GET count' => 'count',
                        'GET footprint' => 'footprint',
                        'GET module' => 'module',
                        'GET history-search' => 'history-search',
                        'POST clear-search' => 'clear-search',
                    ],
                ],
                [
                    'class' => 'yii\rest\UrlRule',
                    'pluralize' => false,
                    'controller' => 'v1/auth',
                    'extraPatterns' => [
                        'POST login' => 'login',
                        'POST login-by-id' => 'login-by-id',
                        'POST logout' => 'logout',
                        'POST bind-tel' => 'bind-tel',
                    ],
                ],
                [
                    'class' => 'yii\rest\UrlRule',
                    'pluralize' => false,
                    'controller' => 'v1/user',
                    'extraPatterns' => [
                        'GET refresh' => 'refresh',
                    ],
                ],
                [
                    'class' => 'yii\rest\UrlRule',
                    'pluralize' => false,
                    'controller' => 'v1/common',
                    'extraPatterns' => [
                        'GET page' => 'page',
                        'GET config' => 'config',
                        'POST upload' => 'upload',
                        'GET version' => 'version',
                    ],
                ],
                [
                    'class' => 'yii\rest\UrlRule',
                    'pluralize' => false,
                    'controller' => 'v1/survey',
                    'extraPatterns' => [
                        'GET survey' => 'survey',
                        'GET captcha' => 'captcha',
                        'POST submit' => 'submit',
                        'POST enterprise' => 'enterprise',
                    ],
                ],
                [
                    'class' => 'yii\rest\UrlRule',
                    'pluralize' => false,
                    'controller' => 'v1/policy',
                    'extraPatterns' => [
                        'GET policy' => 'policy',
                        'GET category' => 'category',
                        'GET details' => 'details',
                    ],
                ]
            ],
        ],
        'request' => [
            'enableCookieValidation' => false,
            'parsers' => [
                'application/json' => 'yii\web\JsonParser',//解析json请求
            ]
        ],
    ],
    'modules' => [
        'v1' => [
            'class' => '\api\modules\v1\Module'
        ]
    ],
    'params' => $params
];
