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

ResponseHeaderBag.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 8.64 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   * ResponseHeaderBag is a container for Response HTTP headers.
016   *
017   * @author Fabien Potencier <fabien@symfony.com>
018   *
019   * @api
020   */
021  class ResponseHeaderBag extends HeaderBag
022  {
023      const COOKIES_FLAT           = 'flat';
024      const COOKIES_ARRAY          = 'array';
025   
026      const DISPOSITION_ATTACHMENT = 'attachment';
027      const DISPOSITION_INLINE     = 'inline';
028   
029      /**
030       * @var array
031       */
032      protected $computedCacheControl = array();
033   
034      /**
035       * @var array
036       */
037      protected $cookies              = array();
038   
039      /**
040       * @var array
041       */
042      protected $headerNames          = array();
043   
044      /**
045       * Constructor.
046       *
047       * @param array $headers An array of HTTP headers
048       *
049       * @api
050       */
051      public function __construct(array $headers = array())
052      {
053          parent::__construct($headers);
054   
055          if (!isset($this->headers['cache-control'])) {
056              $this->set('Cache-Control', '');
057          }
058      }
059   
060      /**
061       * {@inheritdoc}
062       */
063      public function __toString()
064      {
065          $cookies = '';
066          foreach ($this->getCookies() as $cookie) {
067              $cookies .= 'Set-Cookie: '.$cookie."\r\n";
068          }
069   
070          ksort($this->headerNames);
071   
072          return parent::__toString().$cookies;
073      }
074   
075      /**
076       * Returns the headers, with original capitalizations.
077       *
078       * @return array An array of headers
079       */
080      public function allPreserveCase()
081      {
082          return array_combine($this->headerNames, $this->headers);
083      }
084   
085      /**
086       * {@inheritdoc}
087       *
088       * @api
089       */
090      public function replace(array $headers = array())
091      {
092          $this->headerNames = array();
093   
094          parent::replace($headers);
095   
096          if (!isset($this->headers['cache-control'])) {
097              $this->set('Cache-Control', '');
098          }
099      }
100   
101      /**
102       * {@inheritdoc}
103       *
104       * @api
105       */
106      public function set($key, $values, $replace = true)
107      {
108          parent::set($key, $values, $replace);
109   
110          $uniqueKey = strtr(strtolower($key), '_', '-');
111          $this->headerNames[$uniqueKey] = $key;
112   
113          // ensure the cache-control header has sensible defaults
114          if (in_array($uniqueKey, array('cache-control', 'etag', 'last-modified', 'expires'))) {
115              $computed = $this->computeCacheControlValue();
116              $this->headers['cache-control'] = array($computed);
117              $this->headerNames['cache-control'] = 'Cache-Control';
118              $this->computedCacheControl = $this->parseCacheControl($computed);
119          }
120      }
121   
122      /**
123       * {@inheritdoc}
124       *
125       * @api
126       */
127      public function remove($key)
128      {
129          parent::remove($key);
130   
131          $uniqueKey = strtr(strtolower($key), '_', '-');
132          unset($this->headerNames[$uniqueKey]);
133   
134          if ('cache-control' === $uniqueKey) {
135              $this->computedCacheControl = array();
136          }
137      }
138   
139      /**
140       * {@inheritdoc}
141       */
142      public function hasCacheControlDirective($key)
143      {
144          return array_key_exists($key, $this->computedCacheControl);
145      }
146   
147      /**
148       * {@inheritdoc}
149       */
150      public function getCacheControlDirective($key)
151      {
152          return array_key_exists($key, $this->computedCacheControl) ? $this->computedCacheControl[$key] : null;
153      }
154   
155      /**
156       * Sets a cookie.
157       *
158       * @param Cookie $cookie
159       *
160       * @api
161       */
162      public function setCookie(Cookie $cookie)
163      {
164          $this->cookies[$cookie->getDomain()][$cookie->getPath()][$cookie->getName()] = $cookie;
165      }
166   
167      /**
168       * Removes a cookie from the array, but does not unset it in the browser
169       *
170       * @param string $name
171       * @param string $path
172       * @param string $domain
173       *
174       * @api
175       */
176      public function removeCookie($name, $path = '/', $domain = null)
177      {
178          if (null === $path) {
179              $path = '/';
180          }
181   
182          unset($this->cookies[$domain][$path][$name]);
183   
184          if (empty($this->cookies[$domain][$path])) {
185              unset($this->cookies[$domain][$path]);
186   
187              if (empty($this->cookies[$domain])) {
188                  unset($this->cookies[$domain]);
189              }
190          }
191      }
192   
193      /**
194       * Returns an array with all cookies
195       *
196       * @param string $format
197       *
198       * @throws \InvalidArgumentException When the $format is invalid
199       *
200       * @return array
201       *
202       * @api
203       */
204      public function getCookies($format = self::COOKIES_FLAT)
205      {
206          if (!in_array($format, array(self::COOKIES_FLAT, self::COOKIES_ARRAY))) {
207              throw new \InvalidArgumentException(sprintf('Format "%s" invalid (%s).', $format, implode(', ', array(self::COOKIES_FLAT, self::COOKIES_ARRAY))));
208          }
209   
210          if (self::COOKIES_ARRAY === $format) {
211              return $this->cookies;
212          }
213   
214          $flattenedCookies = array();
215          foreach ($this->cookies as $path) {
216              foreach ($path as $cookies) {
217                  foreach ($cookies as $cookie) {
218                      $flattenedCookies[] = $cookie;
219                  }
220              }
221          }
222   
223          return $flattenedCookies;
224      }
225   
226      /**
227       * Clears a cookie in the browser
228       *
229       * @param string $name
230       * @param string $path
231       * @param string $domain
232       *
233       * @api
234       */
235      public function clearCookie($name, $path = '/', $domain = null)
236      {
237          $this->setCookie(new Cookie($name, null, 1, $path, $domain));
238      }
239   
240      /**
241       * Generates a HTTP Content-Disposition field-value.
242       *
243       * @param string $disposition      One of "inline" or "attachment"
244       * @param string $filename         A unicode string
245       * @param string $filenameFallback A string containing only ASCII characters that
246       *                                 is semantically equivalent to $filename. If the filename is already ASCII,
247       *                                 it can be omitted, or just copied from $filename
248       *
249       * @return string A string suitable for use as a Content-Disposition field-value.
250       *
251       * @throws \InvalidArgumentException
252       * @see RFC 6266
253       */
254      public function makeDisposition($disposition, $filename, $filenameFallback = '')
255      {
256          if (!in_array($disposition, array(self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE))) {
257              throw new \InvalidArgumentException(sprintf('The disposition must be either "%s" or "%s".', self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE));
258          }
259   
260          if ('' == $filenameFallback) {
261              $filenameFallback = $filename;
262          }
263   
264          // filenameFallback is not ASCII.
265          if (!preg_match('/^[\x20-\x7e]*$/', $filenameFallback)) {
266              throw new \InvalidArgumentException('The filename fallback must only contain ASCII characters.');
267          }
268   
269          // percent characters aren't safe in fallback.
270          if (false !== strpos($filenameFallback, '%')) {
271              throw new \InvalidArgumentException('The filename fallback cannot contain the "%" character.');
272          }
273   
274          // path separators aren't allowed in either.
275          if (false !== strpos($filename, '/') || false !== strpos($filename, '\\') || false !== strpos($filenameFallback, '/') || false !== strpos($filenameFallback, '\\')) {
276              throw new \InvalidArgumentException('The filename and the fallback cannot contain the "/" and "\\" characters.');
277          }
278   
279          $output = sprintf('%s; filename="%s"', $disposition, str_replace('"', '\\"', $filenameFallback));
280   
281          if ($filename !== $filenameFallback) {
282              $output .= sprintf("; filename*=utf-8''%s", rawurlencode($filename));
283          }
284   
285          return $output;
286      }
287   
288      /**
289       * Returns the calculated value of the cache-control header.
290       *
291       * This considers several other headers and calculates or modifies the
292       * cache-control header to a sensible, conservative value.
293       *
294       * @return string
295       */
296      protected function computeCacheControlValue()
297      {
298          if (!$this->cacheControl && !$this->has('ETag') && !$this->has('Last-Modified') && !$this->has('Expires')) {
299              return 'no-cache';
300          }
301   
302          if (!$this->cacheControl) {
303              // conservative by default
304              return 'private, must-revalidate';
305          }
306   
307          $header = $this->getCacheControlHeader();
308          if (isset($this->cacheControl['public']) || isset($this->cacheControl['private'])) {
309              return $header;
310          }
311   
312          // public if s-maxage is defined, private otherwise
313          if (!isset($this->cacheControl['s-maxage'])) {
314              return $header.', private';
315          }
316   
317          return $header;
318      }
319  }
320