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

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

AcceptHeaderItem.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 4.80 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 item.
 016   *
 017   * @author Jean-François Simon <contact@jfsimon.fr>
 018   */
 019  class AcceptHeaderItem
 020  {
 021      /**
 022       * @var string
 023       */
 024      private $value;
 025   
 026      /**
 027       * @var float
 028       */
 029      private $quality = 1.0;
 030   
 031      /**
 032       * @var int
 033       */
 034      private $index = 0;
 035   
 036      /**
 037       * @var array
 038       */
 039      private $attributes = array();
 040   
 041      /**
 042       * Constructor.
 043       *
 044       * @param string $value
 045       * @param array  $attributes
 046       */
 047      public function __construct($value, array $attributes = array())
 048      {
 049          $this->value = $value;
 050          foreach ($attributes as $name => $value) {
 051              $this->setAttribute($name, $value);
 052          }
 053      }
 054   
 055      /**
 056       * Builds an AcceptHeaderInstance instance from a string.
 057       *
 058       * @param string $itemValue
 059       *
 060       * @return AcceptHeaderItem
 061       */
 062      public static function fromString($itemValue)
 063      {
 064          $bits = preg_split('/\s*(?:;*("[^"]+");*|;*(\'[^\']+\');*|;+)\s*/', $itemValue, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
 065          $value = array_shift($bits);
 066          $attributes = array();
 067   
 068          $lastNullAttribute = null;
 069          foreach ($bits as $bit) {
 070              if (($start = substr($bit, 0, 1)) === ($end = substr($bit, -1)) && ($start === '"' || $start === '\'')) {
 071                  $attributes[$lastNullAttribute] = substr($bit, 1, -1);
 072              } elseif ('=' === $end) {
 073                  $lastNullAttribute = $bit = substr($bit, 0, -1);
 074                  $attributes[$bit] = null;
 075              } else {
 076                  $parts = explode('=', $bit);
 077                  $attributes[$parts[0]] = isset($parts[1]) && strlen($parts[1]) > 0 ? $parts[1] : '';
 078              }
 079          }
 080   
 081          return new self(($start = substr($value, 0, 1)) === ($end = substr($value, -1)) && ($start === '"' || $start === '\'') ? substr($value, 1, -1) : $value, $attributes);
 082      }
 083   
 084      /**
 085       * Returns header  value's string representation.
 086       *
 087       * @return string
 088       */
 089      public function __toString()
 090      {
 091          $string = $this->value.($this->quality < 1 ? ';q='.$this->quality : '');
 092          if (count($this->attributes) > 0) {
 093              $string .= ';'.implode(';', array_map(function ($name, $value) {
 094                  return sprintf(preg_match('/[,;=]/', $value) ? '%s="%s"' : '%s=%s', $name, $value);
 095              }, array_keys($this->attributes), $this->attributes));
 096          }
 097   
 098          return $string;
 099      }
 100   
 101      /**
 102       * Set the item value.
 103       *
 104       * @param string $value
 105       *
 106       * @return AcceptHeaderItem
 107       */
 108      public function setValue($value)
 109      {
 110          $this->value = $value;
 111   
 112          return $this;
 113      }
 114   
 115      /**
 116       * Returns the item value.
 117       *
 118       * @return string
 119       */
 120      public function getValue()
 121      {
 122          return $this->value;
 123      }
 124   
 125      /**
 126       * Set the item quality.
 127       *
 128       * @param float $quality
 129       *
 130       * @return AcceptHeaderItem
 131       */
 132      public function setQuality($quality)
 133      {
 134          $this->quality = $quality;
 135   
 136          return $this;
 137      }
 138   
 139      /**
 140       * Returns the item quality.
 141       *
 142       * @return float
 143       */
 144      public function getQuality()
 145      {
 146          return $this->quality;
 147      }
 148   
 149      /**
 150       * Set the item index.
 151       *
 152       * @param int $index
 153       *
 154       * @return AcceptHeaderItem
 155       */
 156      public function setIndex($index)
 157      {
 158          $this->index = $index;
 159   
 160          return $this;
 161      }
 162   
 163      /**
 164       * Returns the item index.
 165       *
 166       * @return int
 167       */
 168      public function getIndex()
 169      {
 170          return $this->index;
 171      }
 172   
 173      /**
 174       * Tests if an attribute exists.
 175       *
 176       * @param string $name
 177       *
 178       * @return bool
 179       */
 180      public function hasAttribute($name)
 181      {
 182          return isset($this->attributes[$name]);
 183      }
 184   
 185      /**
 186       * Returns an attribute by its name.
 187       *
 188       * @param string $name
 189       * @param mixed  $default
 190       *
 191       * @return mixed
 192       */
 193      public function getAttribute($name, $default = null)
 194      {
 195          return isset($this->attributes[$name]) ? $this->attributes[$name] : $default;
 196      }
 197   
 198      /**
 199       * Returns all attributes.
 200       *
 201       * @return array
 202       */
 203      public function getAttributes()
 204      {
 205          return $this->attributes;
 206      }
 207   
 208      /**
 209       * Set an attribute.
 210       *
 211       * @param string $name
 212       * @param string $value
 213       *
 214       * @return AcceptHeaderItem
 215       */
 216      public function setAttribute($name, $value)
 217      {
 218          if ('q' === $name) {
 219              $this->quality = (float) $value;
 220          } else {
 221              $this->attributes[$name] = (string) $value;
 222          }
 223   
 224          return $this;
 225      }
 226  }
 227