Verzeichnisstruktur phpBB-3.1.0
- Veröffentlicht
- 27.10.2014
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 /**
023 * Namespace character.
024 *
025 * @var string
026 */
027 private $namespaceCharacter;
028
029 /**
030 * Constructor.
031 *
032 * @param string $storageKey Session storage key.
033 * @param string $namespaceCharacter Namespace character to use in keys.
034 */
035 public function __construct($storageKey = '_sf2_attributes', $namespaceCharacter = '/')
036 {
037 $this->namespaceCharacter = $namespaceCharacter;
038 parent::__construct($storageKey);
039 }
040
041 /**
042 * {@inheritdoc}
043 */
044 public function has($name)
045 {
046 $attributes = $this->resolveAttributePath($name);
047 $name = $this->resolveKey($name);
048
049 if (null === $attributes) {
050 return false;
051 }
052
053 return array_key_exists($name, $attributes);
054 }
055
056 /**
057 * {@inheritdoc}
058 */
059 public function get($name, $default = null)
060 {
061 $attributes = $this->resolveAttributePath($name);
062 $name = $this->resolveKey($name);
063
064 if (null === $attributes) {
065 return $default;
066 }
067
068 return array_key_exists($name, $attributes) ? $attributes[$name] : $default;
069 }
070
071 /**
072 * {@inheritdoc}
073 */
074 public function set($name, $value)
075 {
076 $attributes = & $this->resolveAttributePath($name, true);
077 $name = $this->resolveKey($name);
078 $attributes[$name] = $value;
079 }
080
081 /**
082 * {@inheritdoc}
083 */
084 public function remove($name)
085 {
086 $retval = null;
087 $attributes = & $this->resolveAttributePath($name);
088 $name = $this->resolveKey($name);
089 if (null !== $attributes && array_key_exists($name, $attributes)) {
090 $retval = $attributes[$name];
091 unset($attributes[$name]);
092 }
093
094 return $retval;
095 }
096
097 /**
098 * Resolves a path in attributes property and returns it as a reference.
099 *
100 * This method allows structured namespacing of session attributes.
101 *
102 * @param string $name Key name
103 * @param bool $writeContext Write context, default false
104 *
105 * @return array
106 */
107 protected function &resolveAttributePath($name, $writeContext = false)
108 {
109 $array = & $this->attributes;
110 $name = (strpos($name, $this->namespaceCharacter) === 0) ? substr($name, 1) : $name;
111
112 // Check if there is anything to do, else return
113 if (!$name) {
114 return $array;
115 }
116
117 $parts = explode($this->namespaceCharacter, $name);
118 if (count($parts) < 2) {
119 if (!$writeContext) {
120 return $array;
121 }
122
123 $array[$parts[0]] = array();
124
125 return $array;
126 }
127
128 unset($parts[count($parts)-1]);
129
130 foreach ($parts as $part) {
131 if (null !== $array && !array_key_exists($part, $array)) {
132 $array[$part] = $writeContext ? array() : null;
133 }
134
135 $array = & $array[$part];
136 }
137
138 return $array;
139 }
140
141 /**
142 * Resolves the key from the name.
143 *
144 * This is the last part in a dot separated string.
145 *
146 * @param string $name
147 *
148 * @return string
149 */
150 protected function resolveKey($name)
151 {
152 if (strpos($name, $this->namespaceCharacter) !== false) {
153 $name = substr($name, strrpos($name, $this->namespaceCharacter)+1, strlen($name));
154 }
155
156 return $name;
157 }
158 }
159