all-in-one/php/src/Twig/CsrfExtension.php
Simon L. eba86c3ad1 add declare(strict_types=1); to all php files
Signed-off-by: Simon L. <szaimen@e.mail.de>
2026-02-03 13:25:53 +01:00

36 lines
907 B
PHP

<?php
declare(strict_types=1);
namespace AIO\Twig;
use Slim\Csrf\Guard;
use Twig\Extension\AbstractExtension;
use Twig\Extension\GlobalsInterface;
class CsrfExtension extends AbstractExtension implements GlobalsInterface {
public function __construct(
protected Guard $csrf
) {
}
#[\Override]
public function getGlobals() : array
{
// CSRF token name and value
$csrfNameKey = $this->csrf->getTokenNameKey();
$csrfValueKey = $this->csrf->getTokenValueKey();
$csrfName = $this->csrf->getTokenName();
$csrfValue = $this->csrf->getTokenValue();
return [
'csrf' => [
'keys' => [
'name' => $csrfNameKey,
'value' => $csrfValueKey
],
'name' => $csrfName,
'value' => $csrfValue
]
];
}
}