Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
NamespacedAttributeBag.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\HttpFoundation\Session\Attribute;
013
014 /**
015 * This class provides structured storage of session attributes using
016 * a name spacing character in the key.
017 *
018 * @author Drak <drak@zikula.org>
019 */
020 class NamespacedAttributeBag extends AttributeBag
021 {
022 private $namespaceCharacter;
023
024 /**
025 * @param string $storageKey Session storage key
026 * @param string $namespaceCharacter Namespace character to use in keys
027 */
028 public function __construct($storageKey = '_sf2_attributes', $namespaceCharacter = '/')
029 {
030 $this->namespaceCharacter = $namespaceCharacter;
031 parent::__construct($storageKey);
032 }
033
034 /**
035 * {@inheritdoc}
036 */
037 public function has($name)
038 {
039 // reference mismatch: if fixed, re-introduced in array_key_exists; keep as it is
040 $attributes = $this->resolveAttributePath($name);
041 $name = $this->resolveKey($name);
042
043 if (null === $attributes) {
044 return false;
045 }
046
047 return \array_key_exists($name, $attributes);
048 }
049
050 /**
051 * {@inheritdoc}
052 */
053 public function get($name, $default = null)
054 {
055 // reference mismatch: if fixed, re-introduced in array_key_exists; keep as it is
056 $attributes = $this->resolveAttributePath($name);
057 $name = $this->resolveKey($name);
058
059 if (null === $attributes) {
060 return $default;
061 }
062
063 return \array_key_exists($name, $attributes) ? $attributes[$name] : $default;
064 }
065
066 /**
067 * {@inheritdoc}
068 */
069 public function set($name, $value)
070 {
071 $attributes = &$this->resolveAttributePath($name, true);
072 $name = $this->resolveKey($name);
073 $attributes[$name] = $value;
074 }
075
076 /**
077 * {@inheritdoc}
078 */
079 public function remove($name)
080 {
081 $retval = null;
082 $attributes = &$this->resolveAttributePath($name);
083 $name = $this->resolveKey($name);
084 if (null !== $attributes && \array_key_exists($name, $attributes)) {
085 $retval = $attributes[$name];
086 unset($attributes[$name]);
087 }
088
089 return $retval;
090 }
091
092 /**
093 * Resolves a path in attributes property and returns it as a reference.
094 *
095 * This method allows structured namespacing of session attributes.
096 *
097 * @param string $name Key name
098 * @param bool $writeContext Write context, default false
099 *
100 * @return array|null
101 */
102 protected function &resolveAttributePath($name, $writeContext = false)
103 {
104 $array = &$this->attributes;
105 $name = (0 === strpos($name, $this->namespaceCharacter)) ? substr($name, 1) : $name;
106
107 // Check if there is anything to do, else return
108 if (!$name) {
109 return $array;
110 }
111
112 $parts = explode($this->namespaceCharacter, $name);
113 if (\count($parts) < 2) {
114 if (!$writeContext) {
115 return $array;
116 }
117
118 $array[$parts[0]] = [];
119
120 return $array;
121 }
122
123 unset($parts[\count($parts) - 1]);
124
125 foreach ($parts as $part) {
126 if (null !== $array && !\array_key_exists($part, $array)) {
127 if (!$writeContext) {
128 $null = null;
129
130 return $null;
131 }
132
133 $array[$part] = [];
134 }
135
136 $array = &$array[$part];
137 }
138
139 return $array;
140 }
141
142 /**
143 * Resolves the key from the name.
144 *
145 * This is the last part in a dot separated string.
146 *
147 * @param string $name
148 *
149 * @return string
150 */
151 protected function resolveKey($name)
152 {
153 if (false !== $pos = strrpos($name, $this->namespaceCharacter)) {
154 $name = substr($name, $pos + 1);
155 }
156
157 return $name;
158 }
159 }
160