<?php

$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/db.php';

$config = [
    'id' => 'APIMED312',
    'basePath' => dirname(__DIR__), 
    //'basePath' => dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
    //'bootstrap' => ['log'],
    'aliases' => [
        '@bower' => '@vendor/bower-asset',
       // '@npm'   => '@vendor/npm-asset',
    ],
    'components' => [
        'response' => [
            'format' => yii\web\Response::FORMAT_JSON,
            'charset' => 'UTF-8',
        ],
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => 'dnlVPkIBAQYXhGCMchaV0Rl2HciFVIfm',
            'parsers' => [
                'application/json' => 'yii\web\JsonParser',
            ],
            /*'trustedHosts' => [
                '10.0.2.0/24',
            ],*/
        ],
//        'cache' => [
//           'class' => 'yii\caching\FileCache',
//        ],
        'user' => [
            'identityClass' => 'app\models\User',
            'enableAutoLogin' => true,
        ],
        'errorHandler' => [
            'errorAction' => 'rest/error',
        ],
        /*'mailer' => [
            'class' => \yii\symfonymailer\Mailer::class,
            'viewPath' => '@app/mail',
            // send all mails to a file by default.
            'useFileTransport' => true,
        ],*/
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'db' => $db,
        'urlManager' => [
            'enablePrettyUrl' => true,
            'enableStrictParsing' => true,
            'showScriptName' => false,
            //'scriptUrl' => 'site',
            'rules' => [
                '' => 'rest/index',
                'GET,HEAD rest'                     => 'rest/index',
                'GET,HEAD rest/find_mailbox'        => 'rest/find_mailbox',
                'GET,HEAD rest/show_mailboxes'     => 'rest/show_mailboxes',
                'POST,HEAD rest/create_mailbox'      => 'rest/create_mailbox',
//                '<controller:\w+>/<action:\w+>'     => 'rest/<action>',
//                '<controller:\w+>/<action:\w+>/<id:\w+>' => '<controller>/<action>',
//                '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
//                '<controller:[\w-]+>' => '<controller>/index',
                ['class' => 'yii\rest\UrlRule', 'controller' => 'rest'],
            ],
        ],

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

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        //'allowedIPs' => ['127.0.0.1', '::1'],
    ];

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        //'allowedIPs' => ['127.0.0.1', '::1'],
    ];
}

return $config;
