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

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

AcceptHeader.php

Zuletzt modifiziert: 02.04.2025, 15:02 - Dateigröße: 3.46 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;
013   
014  /**
015   * Represents an Accept-* header.
016   *
017   * An accept header is compound with a list of items,
018   * sorted by descending quality.
019   *
020   * @author Jean-François Simon <contact@jfsimon.fr>
021   */
022  class AcceptHeader
023  {
024      /**
025       * @var AcceptHeaderItem[]
026       */
027      private $items = [];
028   
029      /**
030       * @var bool
031       */
032      private $sorted = true;
033   
034      /**
035       * @param AcceptHeaderItem[] $items
036       */
037      public function __construct(array $items)
038      {
039          foreach ($items as $item) {
040              $this->add($item);
041          }
042      }
043   
044      /**
045       * Builds an AcceptHeader instance from a string.
046       *
047       * @param string $headerValue
048       *
049       * @return self
050       */
051      public static function fromString($headerValue)
052      {
053          $index = 0;
054   
055          return new self(array_map(function ($itemValue) use (&$index) {
056              $item = AcceptHeaderItem::fromString($itemValue);
057              $item->setIndex($index++);
058   
059              return $item;
060          }, preg_split('/\s*(?:,*("[^"]+"),*|,*(\'[^\']+\'),*|,+)\s*/', $headerValue, 0, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE)));
061      }
062   
063      /**
064       * Returns header value's string representation.
065       *
066       * @return string
067       */
068      public function __toString()
069      {
070          return implode(',', $this->items);
071      }
072   
073      /**
074       * Tests if header has given value.
075       *
076       * @param string $value
077       *
078       * @return bool
079       */
080      public function has($value)
081      {
082          return isset($this->items[$value]);
083      }
084   
085      /**
086       * Returns given value's item, if exists.
087       *
088       * @param string $value
089       *
090       * @return AcceptHeaderItem|null
091       */
092      public function get($value)
093      {
094          return isset($this->items[$value]) ? $this->items[$value] : null;
095      }
096   
097      /**
098       * Adds an item.
099       *
100       * @return $this
101       */
102      public function add(AcceptHeaderItem $item)
103      {
104          $this->items[$item->getValue()] = $item;
105          $this->sorted = false;
106   
107          return $this;
108      }
109   
110      /**
111       * Returns all items.
112       *
113       * @return AcceptHeaderItem[]
114       */
115      public function all()
116      {
117          $this->sort();
118   
119          return $this->items;
120      }
121   
122      /**
123       * Filters items on their value using given regex.
124       *
125       * @param string $pattern
126       *
127       * @return self
128       */
129      public function filter($pattern)
130      {
131          return new self(array_filter($this->items, function (AcceptHeaderItem $item) use ($pattern) {
132              return preg_match($pattern, $item->getValue());
133          }));
134      }
135   
136      /**
137       * Returns first item.
138       *
139       * @return AcceptHeaderItem|null
140       */
141      public function first()
142      {
143          $this->sort();
144   
145          return !empty($this->items) ? reset($this->items) : null;
146      }
147   
148      /**
149       * Sorts items by descending quality.
150       */
151      private function sort()
152      {
153          if (!$this->sorted) {
154              uasort($this->items, function (AcceptHeaderItem $a, AcceptHeaderItem $b) {
155                  $qA = $a->getQuality();
156                  $qB = $b->getQuality();
157   
158                  if ($qA === $qB) {
159                      return $a->getIndex() > $b->getIndex() ? 1 : -1;
160                  }
161   
162                  return $qA > $qB ? -1 : 1;
163              });
164   
165              $this->sorted = true;
166          }
167      }
168  }
169