80 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			80 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						||
 | 
						||
namespace frontend\modules\api\controllers;
 | 
						||
 | 
						||
use common\behaviors\GsCors;
 | 
						||
use yii\filters\auth\CompositeAuth;
 | 
						||
use yii\filters\auth\HttpBearerAuth;
 | 
						||
use yii\filters\ContentNegotiator;
 | 
						||
use yii\rest\Controller;
 | 
						||
use yii\web\Response;
 | 
						||
 | 
						||
 | 
						||
/**
 | 
						||
 * @OA\Info(
 | 
						||
 *      version="1.0.0",
 | 
						||
 *      title="Документация Сервис для создания чеков",
 | 
						||
 *      description="Документация для работы с API",
 | 
						||
 *
 | 
						||
 * ),
 | 
						||
 * @OA\PathItem(
 | 
						||
 *         path="/api"
 | 
						||
 *  ),
 | 
						||
 * @OA\Server(
 | 
						||
 *   url="https://check.itguild.info/api",
 | 
						||
 *   description="Основной сервер",
 | 
						||
 * ),
 | 
						||
 *
 | 
						||
 * @OA\Server(
 | 
						||
 *   url="http://check-back.loc/api",
 | 
						||
 *   description="Локальный сервер",
 | 
						||
 * ),
 | 
						||
 *
 | 
						||
 * @OA\SecurityScheme(
 | 
						||
 *   securityScheme="bearerAuth",
 | 
						||
 *   in="header",
 | 
						||
 *   name="Authorization",
 | 
						||
 *   type="http",
 | 
						||
 *   scheme="bearer",
 | 
						||
 *   bearerFormat="JWT",
 | 
						||
 * ),
 | 
						||
 */
 | 
						||
class ApiController extends Controller
 | 
						||
{
 | 
						||
 | 
						||
    public function behaviors()
 | 
						||
    {
 | 
						||
        return [
 | 
						||
            'corsFilter' => [
 | 
						||
                'class' => GsCors::class,
 | 
						||
                'cors' => [
 | 
						||
                    'Origin' => ['*'],
 | 
						||
                    //'Access-Control-Allow-Credentials' => true,
 | 
						||
                    'Access-Control-Allow-Headers' => [
 | 
						||
                        'Access-Control-Allow-Origin',
 | 
						||
                        'Access-Control-Allow-Methods',
 | 
						||
                        'Content-Type',
 | 
						||
                        'Access-Control-Allow-Headers',
 | 
						||
                        'Authorization',
 | 
						||
                        'X-Requested-With'
 | 
						||
                    ],
 | 
						||
                    'Access-Control-Allow-Methods' => ['POST', 'GET', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
 | 
						||
                    'Access-Control-Request-Method' => ['POST', 'GET', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
 | 
						||
                ]
 | 
						||
            ],
 | 
						||
            'authenticator' => [
 | 
						||
                'class' => CompositeAuth::class,
 | 
						||
                'authMethods' => [
 | 
						||
                    HttpBearerAuth::class,
 | 
						||
                ],
 | 
						||
            ],
 | 
						||
            [
 | 
						||
                'class' => ContentNegotiator::className(),
 | 
						||
                'formats' => [
 | 
						||
                    'application/json' => Response::FORMAT_JSON,
 | 
						||
                ],
 | 
						||
            ],
 | 
						||
        ];
 | 
						||
    }
 | 
						||
 | 
						||
} |