gmarche/src/Framework/Twig/VariableExtension.php

49 lines
1.1 KiB
PHP

<?php
namespace App\Framework\Twig;
use Framework\Session\SessionInterface;
class VariableExtension extends \Twig_Extension
{
/**
* @var SessionInterface
*/
private $session;
/**
* @var string
*/
//private $url;
public function __construct(SessionInterface $session)
{
$this->session = $session;
}
public function getFunctions()
{
return [
new \Twig_SimpleFunction('affiche_username', [$this, 'affich_usrname']),
new \Twig_SimpleFunction('affiche_role', [$this, 'affich_role']),
new \Twig_SimpleFunction('affiche_mail', [$this, 'affich_mail'])
];
}
public function affich_role(): ?string
{
$retour_aff = $this->session->get('role') ?: '';
return $retour_aff;
}
public function affich_usrname(): ?string
{
$retour_aff = $this->session->get('username') ?: '';
return $retour_aff;
}
public function affich_mail(): ?string
{
$retour_aff = $this->session->get('email') ?: '';
return $retour_aff;
}
}