1: <?php
2: /**
3: * This file is part of the Autarky package.
4: *
5: * (c) Andreas Lutro <anlutro@gmail.com>
6: *
7: * For the full copyright and license information, please view the LICENSE
8: * file that was distributed with this source code.
9: */
10:
11: namespace Autarky\TwigTemplating\Extensions;
12:
13: use Twig_Extension;
14: use Symfony\Component\HttpFoundation\Session\Session;
15:
16: /**
17: * Extension that adds session-related functionality.
18: *
19: * Adds the 'flash' global variable containing flash messages.
20: */
21: class SessionExtension extends Twig_Extension
22: {
23: /**
24: * @var Session
25: */
26: protected $session;
27:
28: /**
29: * Constructor.
30: *
31: * @param Session $session
32: */
33: public function __construct(Session $session)
34: {
35: $this->session = $session;
36: }
37:
38: /**
39: * {@inheritdoc}
40: */
41: public function getGlobals()
42: {
43: return [
44: 'flash' => $this->session->getFlashBag()->peek('_messages', []),
45: ];
46: }
47:
48: /**
49: * {@inheritdoc}
50: */
51: public function getName()
52: {
53: return 'session';
54: }
55: }
56: