1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\HttpFoundation\Session;
13
14/**
15 * @author Nicolas Grekas <p@tchwork.com>
16 *
17 * @internal
18 */
19final class SessionBagProxy implements SessionBagInterface
20{
21    private $bag;
22    private $data;
23    private $usageIndex;
24
25    public function __construct(SessionBagInterface $bag, array &$data, &$usageIndex)
26    {
27        $this->bag = $bag;
28        $this->data = &$data;
29        $this->usageIndex = &$usageIndex;
30    }
31
32    /**
33     * @return SessionBagInterface
34     */
35    public function getBag()
36    {
37        ++$this->usageIndex;
38
39        return $this->bag;
40    }
41
42    /**
43     * @return bool
44     */
45    public function isEmpty()
46    {
47        if (!isset($this->data[$this->bag->getStorageKey()])) {
48            return true;
49        }
50        ++$this->usageIndex;
51
52        return empty($this->data[$this->bag->getStorageKey()]);
53    }
54
55    /**
56     * {@inheritdoc}
57     */
58    public function getName()
59    {
60        return $this->bag->getName();
61    }
62
63    /**
64     * {@inheritdoc}
65     */
66    public function initialize(array &$array)
67    {
68        ++$this->usageIndex;
69        $this->data[$this->bag->getStorageKey()] = &$array;
70
71        $this->bag->initialize($array);
72    }
73
74    /**
75     * {@inheritdoc}
76     */
77    public function getStorageKey()
78    {
79        return $this->bag->getStorageKey();
80    }
81
82    /**
83     * {@inheritdoc}
84     */
85    public function clear()
86    {
87        return $this->bag->clear();
88    }
89}
90