composer package updates
[openemr.git] / vendor / symfony / http-foundation / Session / Attribute / AttributeBag.php
blobea1fda290fdfe94d2d16006ef3d31f56f5b60805
1 <?php
3 /*
4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpFoundation\Session\Attribute;
14 /**
15 * This class relates to session attribute storage.
17 class AttributeBag implements AttributeBagInterface, \IteratorAggregate, \Countable
19 private $name = 'attributes';
20 private $storageKey;
22 protected $attributes = array();
24 /**
25 * @param string $storageKey The key used to store attributes in the session
27 public function __construct($storageKey = '_sf2_attributes')
29 $this->storageKey = $storageKey;
32 /**
33 * {@inheritdoc}
35 public function getName()
37 return $this->name;
40 public function setName($name)
42 $this->name = $name;
45 /**
46 * {@inheritdoc}
48 public function initialize(array &$attributes)
50 $this->attributes = &$attributes;
53 /**
54 * {@inheritdoc}
56 public function getStorageKey()
58 return $this->storageKey;
61 /**
62 * {@inheritdoc}
64 public function has($name)
66 return array_key_exists($name, $this->attributes);
69 /**
70 * {@inheritdoc}
72 public function get($name, $default = null)
74 return array_key_exists($name, $this->attributes) ? $this->attributes[$name] : $default;
77 /**
78 * {@inheritdoc}
80 public function set($name, $value)
82 $this->attributes[$name] = $value;
85 /**
86 * {@inheritdoc}
88 public function all()
90 return $this->attributes;
93 /**
94 * {@inheritdoc}
96 public function replace(array $attributes)
98 $this->attributes = array();
99 foreach ($attributes as $key => $value) {
100 $this->set($key, $value);
105 * {@inheritdoc}
107 public function remove($name)
109 $retval = null;
110 if (array_key_exists($name, $this->attributes)) {
111 $retval = $this->attributes[$name];
112 unset($this->attributes[$name]);
115 return $retval;
119 * {@inheritdoc}
121 public function clear()
123 $return = $this->attributes;
124 $this->attributes = array();
126 return $return;
130 * Returns an iterator for attributes.
132 * @return \ArrayIterator An \ArrayIterator instance
134 public function getIterator()
136 return new \ArrayIterator($this->attributes);
140 * Returns the number of attributes.
142 * @return int The number of attributes
144 public function count()
146 return count($this->attributes);