Files
Plenario/src/Controller/AppController.php
T
gnilebeinandClaude Opus 5.5 6c0b7ebf3f Use PlenarIO as product name spelling
Display name in layouts, mails, docs and comments is now "PlenarIO".
Technical identifiers (config keys, JS namespace, file names, cookies,
existing migrations) stay unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 16:33:15 +01:00

57 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Controller;
use Cake\Controller\Controller;
use Cake\Event\EventInterface;
use Cake\Http\Response;
/**
* Base controller of PlenarIO.
*/
class AppController extends Controller
{
/**
* @return void
*/
public function initialize(): void
{
parent::initialize();
$this->loadComponent('Flash');
}
/**
* Security headers for every HTML response.
*
* @param \Cake\Event\EventInterface<\Cake\Controller\Controller> $event Event
* @return void
*/
public function beforeRender(EventInterface $event): void
{
parent::beforeRender($event);
$this->response = $this->response
->withHeader('X-Content-Type-Options', 'nosniff')
->withHeader('X-Frame-Options', 'SAMEORIGIN')
->withHeader('Referrer-Policy', 'same-origin');
}
/**
* Returns a JSON response without going through the view layer.
*
* @param array<string, mixed> $data Payload
* @param int $status HTTP status
* @return \Cake\Http\Response
*/
protected function json(array $data, int $status = 200): Response
{
return $this->response
->withStatus($status)
->withType('application/json')
->withHeader('Cache-Control', 'no-store')
->withStringBody((string)json_encode($data, JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR));
}
}