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

AcceptHeader.php

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