Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
Session
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFunctions
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 sessionPop
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Engelsystem\Renderer\Twig\Extensions;
6
7use Symfony\Component\HttpFoundation\Session\Session as SymfonySession;
8use Twig\Extension\AbstractExtension as TwigExtension;
9use Twig\TwigFunction;
10
11class Session extends TwigExtension
12{
13    public function __construct(protected SymfonySession $session)
14    {
15    }
16
17    /**
18     * @return TwigFunction[]
19     */
20    public function getFunctions(): array
21    {
22        return [
23            new TwigFunction('session_get', [$this->session, 'get']),
24            new TwigFunction('session_set', [$this->session, 'set']),
25            new TwigFunction('session_pop', [$this, 'sessionPop']),
26        ];
27    }
28
29    /**
30     * Returns the requested attribute and removes it from the session
31     */
32    public function sessionPop(string $name, mixed $default = null): mixed
33    {
34        $value = $this->session->get($name, $default);
35        $this->session->remove($name);
36
37        return $value;
38    }
39}