Open Journal Systems  3.3.0
vendor/symfony/http-foundation/Session/Attribute/AttributeBag.php
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 
13 
17 class AttributeBag implements AttributeBagInterface, \IteratorAggregate, \Countable
18 {
19  private $name = 'attributes';
20  private $storageKey;
21 
22  protected $attributes = [];
23 
27  public function __construct(string $storageKey = '_sf2_attributes')
28  {
29  $this->storageKey = $storageKey;
30  }
31 
35  public function getName()
36  {
37  return $this->name;
38  }
39 
40  public function setName($name)
41  {
42  $this->name = $name;
43  }
44 
48  public function initialize(array &$attributes)
49  {
50  $this->attributes = &$attributes;
51  }
52 
56  public function getStorageKey()
57  {
58  return $this->storageKey;
59  }
60 
64  public function has($name)
65  {
66  return \array_key_exists($name, $this->attributes);
67  }
68 
72  public function get($name, $default = null)
73  {
74  return \array_key_exists($name, $this->attributes) ? $this->attributes[$name] : $default;
75  }
76 
80  public function set($name, $value)
81  {
82  $this->attributes[$name] = $value;
83  }
84 
88  public function all()
89  {
90  return $this->attributes;
91  }
92 
96  public function replace(array $attributes)
97  {
98  $this->attributes = [];
99  foreach ($attributes as $key => $value) {
100  $this->set($key, $value);
101  }
102  }
103 
107  public function remove($name)
108  {
109  $retval = null;
110  if (\array_key_exists($name, $this->attributes)) {
111  $retval = $this->attributes[$name];
112  unset($this->attributes[$name]);
113  }
114 
115  return $retval;
116  }
117 
121  public function clear()
122  {
123  $return = $this->attributes;
124  $this->attributes = [];
125 
126  return $return;
127  }
128 
134  public function getIterator()
135  {
136  return new \ArrayIterator($this->attributes);
137  }
138 
144  public function count()
145  {
146  return \count($this->attributes);
147  }
148 }
Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag\count
count()
Definition: vendor/symfony/http-foundation/Session/Attribute/AttributeBag.php:144
Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag\getStorageKey
getStorageKey()
Definition: vendor/symfony/http-foundation/Session/Attribute/AttributeBag.php:56
Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag\has
has($name)
Definition: vendor/symfony/http-foundation/Session/Attribute/AttributeBag.php:64
Symfony\Component\HttpFoundation\Session\Attribute
Definition: lib/vendor/symfony/http-foundation/Session/Attribute/AttributeBag.php:12
Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag\all
all()
Definition: vendor/symfony/http-foundation/Session/Attribute/AttributeBag.php:88
Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag\replace
replace(array $attributes)
Definition: vendor/symfony/http-foundation/Session/Attribute/AttributeBag.php:96
Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag\__construct
__construct(string $storageKey='_sf2_attributes')
Definition: vendor/symfony/http-foundation/Session/Attribute/AttributeBag.php:27
Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag\setName
setName($name)
Definition: vendor/symfony/http-foundation/Session/Attribute/AttributeBag.php:40
Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag\$attributes
$attributes
Definition: lib/vendor/symfony/http-foundation/Session/Attribute/AttributeBag.php:35
Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag\clear
clear()
Definition: vendor/symfony/http-foundation/Session/Attribute/AttributeBag.php:121
Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag\initialize
initialize(array &$attributes)
Definition: vendor/symfony/http-foundation/Session/Attribute/AttributeBag.php:48
Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag\getIterator
getIterator()
Definition: vendor/symfony/http-foundation/Session/Attribute/AttributeBag.php:134
Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag\getName
getName()
Definition: vendor/symfony/http-foundation/Session/Attribute/AttributeBag.php:35