all-in-one/php/src/Twig/CsrfExtension.php
Jean-Yves 496ec9ba17
update constructor
Signed-off-by: Jean-Yves <7360784+docjyJ@users.noreply.github.com>
2024-10-07 10:12:43 +02:00

34 lines
865 B
PHP

<?php
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
) {
}
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
]
];
}
}