Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

74 righe
2.6 KiB

<?php
declare(strict_types=1);
/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
* @link https://cakephp.org CakePHP(tm) Project
* @since 0.2.9
* @license https://opensource.org/licenses/mit-license.php MIT License
*/
namespace App\Controller\Api;
use Cake\Controller\Controller;
use Cake\Http\Response;
use App\Model\Entity\User;
/**
* Application Controller
*
* Add your application-wide methods in the class below, your controllers
* will inherit them.
*
* @link https://book.cakephp.org/4/en/controllers.html#the-app-controller
*/
class AppController extends Controller
{
protected $nopaginate;
public ?User $logged_user = null;
/**
* Initialization hook method.
*
* Use this method to add common initialization code like loading components.
*
* e.g. `$this->loadComponent('FormProtection');`
*
* @return void
*/
public function initialize(): void
{
parent::initialize();
$this->loadComponent('Authentication.Authentication');
$this->logged_user = $this->Authentication->getIdentity();
$this->nopaginate = $this->request->getQuery('nopaginate') !== null && $this->request->getQuery('nopaginate');
}
/**
* respond
*
* @param Int $code
* @param null|Object|Array|String $bodyResponse
* @param String $content
* @return Response
*/
public function respond(Int $code = 200, null|Object|Array|String $bodyResponse = null, String $content = "application/json") : Response
{
$bodyResponse = is_object($bodyResponse) || is_array($bodyResponse) ? $bodyResponse : ['result' => $bodyResponse];
$response = $this->getResponse();
$response = $response->withHeader('Access-Control-Allow-Origin', '*');
$response = $response->withHeader('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, DELETE, PUT');
$response = $response->withHeader('Access-Control-Max-Age', '60');
$response = $response->withHeader('Access-Control-Allow-Headers', 'x-requested-with, Content-Type, origin, authorization, accept, client-security-token');
return $response->withStringBody(json_encode($bodyResponse))->withStatus($code)->withType($content);
}
}