Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

NamespacedAttributeBag.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 3.97 KiB


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          // reference mismatch: if fixed, re-introduced in array_key_exists; keep as it is
047          $attributes = $this->resolveAttributePath($name);
048          $name = $this->resolveKey($name);
049   
050          if (null === $attributes) {
051              return false;
052          }
053   
054          return array_key_exists($name, $attributes);
055      }
056   
057      /**
058       * {@inheritdoc}
059       */
060      public function get($name, $default = null)
061      {
062          // reference mismatch: if fixed, re-introduced in array_key_exists; keep as it is
063          $attributes = $this->resolveAttributePath($name);
064          $name = $this->resolveKey($name);
065   
066          if (null === $attributes) {
067              return $default;
068          }
069   
070          return array_key_exists($name, $attributes) ? $attributes[$name] : $default;
071      }
072   
073      /**
074       * {@inheritdoc}
075       */
076      public function set($name, $value)
077      {
078          $attributes = &$this->resolveAttributePath($name, true);
079          $name = $this->resolveKey($name);
080          $attributes[$name] = $value;
081      }
082   
083      /**
084       * {@inheritdoc}
085       */
086      public function remove($name)
087      {
088          $retval = null;
089          $attributes = &$this->resolveAttributePath($name);
090          $name = $this->resolveKey($name);
091          if (null !== $attributes && array_key_exists($name, $attributes)) {
092              $retval = $attributes[$name];
093              unset($attributes[$name]);
094          }
095   
096          return $retval;
097      }
098   
099      /**
100       * Resolves a path in attributes property and returns it as a reference.
101       *
102       * This method allows structured namespacing of session attributes.
103       *
104       * @param string $name         Key name
105       * @param bool   $writeContext Write context, default false
106       *
107       * @return array
108       */
109      protected function &resolveAttributePath($name, $writeContext = false)
110      {
111          $array = &$this->attributes;
112          $name = (strpos($name, $this->namespaceCharacter) === 0) ? substr($name, 1) : $name;
113   
114          // Check if there is anything to do, else return
115          if (!$name) {
116              return $array;
117          }
118   
119          $parts = explode($this->namespaceCharacter, $name);
120          if (count($parts) < 2) {
121              if (!$writeContext) {
122                  return $array;
123              }
124   
125              $array[$parts[0]] = array();
126   
127              return $array;
128          }
129   
130          unset($parts[count($parts) - 1]);
131   
132          foreach ($parts as $part) {
133              if (null !== $array && !array_key_exists($part, $array)) {
134                  $array[$part] = $writeContext ? array() : null;
135              }
136   
137              $array = &$array[$part];
138          }
139   
140          return $array;
141      }
142   
143      /**
144       * Resolves the key from the name.
145       *
146       * This is the last part in a dot separated string.
147       *
148       * @param string $name
149       *
150       * @return string
151       */
152      protected function resolveKey($name)
153      {
154          if (false !== $pos = strrpos($name, $this->namespaceCharacter)) {
155              $name = substr($name, $pos + 1);
156          }
157   
158          return $name;
159      }
160  }
161