comparison vendor/symfony/http-foundation/Session/Session.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 4c8ae668cc8c
children c2387f117808
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
17 use Symfony\Component\HttpFoundation\Session\Flash\FlashBag; 17 use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
18 use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; 18 use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
19 use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage; 19 use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
20 20
21 /** 21 /**
22 * Session.
23 *
24 * @author Fabien Potencier <fabien@symfony.com> 22 * @author Fabien Potencier <fabien@symfony.com>
25 * @author Drak <drak@zikula.org> 23 * @author Drak <drak@zikula.org>
26 */ 24 */
27 class Session implements SessionInterface, \IteratorAggregate, \Countable 25 class Session implements SessionInterface, \IteratorAggregate, \Countable
28 { 26 {
29 /**
30 * Storage driver.
31 *
32 * @var SessionStorageInterface
33 */
34 protected $storage; 27 protected $storage;
35 28
36 /**
37 * @var string
38 */
39 private $flashName; 29 private $flashName;
40
41 /**
42 * @var string
43 */
44 private $attributeName; 30 private $attributeName;
45 31 private $data = array();
46 /** 32 private $hasBeenStarted;
47 * Constructor. 33
48 * 34 /**
49 * @param SessionStorageInterface $storage A SessionStorageInterface instance 35 * @param SessionStorageInterface $storage A SessionStorageInterface instance
50 * @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag) 36 * @param AttributeBagInterface $attributes An AttributeBagInterface instance, (defaults null for default AttributeBag)
51 * @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for default FlashBag) 37 * @param FlashBagInterface $flashes A FlashBagInterface instance (defaults null for default FlashBag)
52 */ 38 */
53 public function __construct(SessionStorageInterface $storage = null, AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null) 39 public function __construct(SessionStorageInterface $storage = null, AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null)
74 /** 60 /**
75 * {@inheritdoc} 61 * {@inheritdoc}
76 */ 62 */
77 public function has($name) 63 public function has($name)
78 { 64 {
79 return $this->storage->getBag($this->attributeName)->has($name); 65 return $this->getAttributeBag()->has($name);
80 } 66 }
81 67
82 /** 68 /**
83 * {@inheritdoc} 69 * {@inheritdoc}
84 */ 70 */
85 public function get($name, $default = null) 71 public function get($name, $default = null)
86 { 72 {
87 return $this->storage->getBag($this->attributeName)->get($name, $default); 73 return $this->getAttributeBag()->get($name, $default);
88 } 74 }
89 75
90 /** 76 /**
91 * {@inheritdoc} 77 * {@inheritdoc}
92 */ 78 */
93 public function set($name, $value) 79 public function set($name, $value)
94 { 80 {
95 $this->storage->getBag($this->attributeName)->set($name, $value); 81 $this->getAttributeBag()->set($name, $value);
96 } 82 }
97 83
98 /** 84 /**
99 * {@inheritdoc} 85 * {@inheritdoc}
100 */ 86 */
101 public function all() 87 public function all()
102 { 88 {
103 return $this->storage->getBag($this->attributeName)->all(); 89 return $this->getAttributeBag()->all();
104 } 90 }
105 91
106 /** 92 /**
107 * {@inheritdoc} 93 * {@inheritdoc}
108 */ 94 */
109 public function replace(array $attributes) 95 public function replace(array $attributes)
110 { 96 {
111 $this->storage->getBag($this->attributeName)->replace($attributes); 97 $this->getAttributeBag()->replace($attributes);
112 } 98 }
113 99
114 /** 100 /**
115 * {@inheritdoc} 101 * {@inheritdoc}
116 */ 102 */
117 public function remove($name) 103 public function remove($name)
118 { 104 {
119 return $this->storage->getBag($this->attributeName)->remove($name); 105 return $this->getAttributeBag()->remove($name);
120 } 106 }
121 107
122 /** 108 /**
123 * {@inheritdoc} 109 * {@inheritdoc}
124 */ 110 */
125 public function clear() 111 public function clear()
126 { 112 {
127 $this->storage->getBag($this->attributeName)->clear(); 113 $this->getAttributeBag()->clear();
128 } 114 }
129 115
130 /** 116 /**
131 * {@inheritdoc} 117 * {@inheritdoc}
132 */ 118 */
140 * 126 *
141 * @return \ArrayIterator An \ArrayIterator instance 127 * @return \ArrayIterator An \ArrayIterator instance
142 */ 128 */
143 public function getIterator() 129 public function getIterator()
144 { 130 {
145 return new \ArrayIterator($this->storage->getBag($this->attributeName)->all()); 131 return new \ArrayIterator($this->getAttributeBag()->all());
146 } 132 }
147 133
148 /** 134 /**
149 * Returns the number of attributes. 135 * Returns the number of attributes.
150 * 136 *
151 * @return int The number of attributes 137 * @return int The number of attributes
152 */ 138 */
153 public function count() 139 public function count()
154 { 140 {
155 return count($this->storage->getBag($this->attributeName)->all()); 141 return count($this->getAttributeBag()->all());
142 }
143
144 /**
145 * @return bool
146 *
147 * @internal
148 */
149 public function hasBeenStarted()
150 {
151 return $this->hasBeenStarted;
152 }
153
154 /**
155 * @return bool
156 *
157 * @internal
158 */
159 public function isEmpty()
160 {
161 foreach ($this->data as &$data) {
162 if (!empty($data)) {
163 return false;
164 }
165 }
166
167 return true;
156 } 168 }
157 169
158 /** 170 /**
159 * {@inheritdoc} 171 * {@inheritdoc}
160 */ 172 */
224 /** 236 /**
225 * {@inheritdoc} 237 * {@inheritdoc}
226 */ 238 */
227 public function registerBag(SessionBagInterface $bag) 239 public function registerBag(SessionBagInterface $bag)
228 { 240 {
229 $this->storage->registerBag($bag); 241 $this->storage->registerBag(new SessionBagProxy($bag, $this->data, $this->hasBeenStarted));
230 } 242 }
231 243
232 /** 244 /**
233 * {@inheritdoc} 245 * {@inheritdoc}
234 */ 246 */
235 public function getBag($name) 247 public function getBag($name)
236 { 248 {
237 return $this->storage->getBag($name); 249 return $this->storage->getBag($name)->getBag();
238 } 250 }
239 251
240 /** 252 /**
241 * Gets the flashbag interface. 253 * Gets the flashbag interface.
242 * 254 *
244 */ 256 */
245 public function getFlashBag() 257 public function getFlashBag()
246 { 258 {
247 return $this->getBag($this->flashName); 259 return $this->getBag($this->flashName);
248 } 260 }
261
262 /**
263 * Gets the attributebag interface.
264 *
265 * Note that this method was added to help with IDE autocompletion.
266 *
267 * @return AttributeBagInterface
268 */
269 private function getAttributeBag()
270 {
271 return $this->getBag($this->attributeName);
272 }
249 } 273 }