2021-11-29 18:21:50 +03:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace frontend\modules\api\controllers;
|
|
|
|
|
|
|
|
|
|
use common\behaviors\GsCors;
|
2022-01-14 17:05:29 +03:00
|
|
|
|
use yii\filters\auth\CompositeAuth;
|
|
|
|
|
use yii\filters\auth\HttpBearerAuth;
|
|
|
|
|
use yii\filters\ContentNegotiator;
|
2021-11-29 18:21:50 +03:00
|
|
|
|
use yii\rest\Controller;
|
2022-01-14 17:05:29 +03:00
|
|
|
|
use yii\web\Response;
|
2021-11-29 18:21:50 +03:00
|
|
|
|
|
2023-04-12 13:14:37 +03:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @OA\Info(
|
|
|
|
|
* version="1.0.0",
|
|
|
|
|
* title="Документация Гильдия",
|
|
|
|
|
* description="Документация для работы с API",
|
|
|
|
|
*
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\PathItem(
|
|
|
|
|
* path="/api"
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Server(
|
|
|
|
|
* url="https://itguild.info/api",
|
|
|
|
|
* description="Основной сервер",
|
|
|
|
|
* ),
|
|
|
|
|
*
|
|
|
|
|
* @OA\Server(
|
2023-04-19 23:44:52 +03:00
|
|
|
|
* url="http://guild.loc/api",
|
2023-04-12 13:14:37 +03:00
|
|
|
|
* description="Локальный сервер",
|
|
|
|
|
* ),
|
|
|
|
|
*
|
|
|
|
|
* @OA\SecurityScheme(
|
|
|
|
|
* securityScheme="bearerAuth",
|
|
|
|
|
* in="header",
|
|
|
|
|
* name="Authorization",
|
|
|
|
|
* type="http",
|
|
|
|
|
* scheme="bearer",
|
|
|
|
|
* bearerFormat="JWT",
|
|
|
|
|
* ),
|
|
|
|
|
*/
|
2021-11-29 18:21:50 +03:00
|
|
|
|
class ApiController extends Controller
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public function behaviors()
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'corsFilter' => [
|
|
|
|
|
'class' => GsCors::class,
|
|
|
|
|
'cors' => [
|
|
|
|
|
'Origin' => ['*'],
|
|
|
|
|
//'Access-Control-Allow-Credentials' => true,
|
|
|
|
|
'Access-Control-Allow-Headers' => [
|
2023-01-13 15:46:15 +03:00
|
|
|
|
'Access-Control-Allow-Origin',
|
2023-04-20 00:06:23 +03:00
|
|
|
|
'Access-Control-Allow-Methods',
|
2021-11-29 18:21:50 +03:00
|
|
|
|
'Content-Type',
|
2023-01-12 16:12:48 +03:00
|
|
|
|
'Access-Control-Allow-Headers',
|
2021-11-29 18:21:50 +03:00
|
|
|
|
'Authorization',
|
|
|
|
|
'X-Requested-With'
|
|
|
|
|
],
|
2023-04-20 00:20:34 +03:00
|
|
|
|
'Access-Control-Allow-Methods' => ['POST', 'GET', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
|
|
|
|
|
'Access-Control-Request-Method' => ['POST', 'GET', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
|
2021-11-29 18:21:50 +03:00
|
|
|
|
]
|
|
|
|
|
],
|
2022-01-14 17:05:29 +03:00
|
|
|
|
'authenticator' => [
|
|
|
|
|
'class' => CompositeAuth::class,
|
|
|
|
|
'authMethods' => [
|
|
|
|
|
HttpBearerAuth::class,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'class' => ContentNegotiator::className(),
|
|
|
|
|
'formats' => [
|
|
|
|
|
'application/json' => Response::FORMAT_JSON,
|
|
|
|
|
],
|
|
|
|
|
],
|
2021-11-29 18:21:50 +03:00
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|