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

StreamedResponse.php

Zuletzt modifiziert: 09.10.2024, 12:54 - Dateigröße: 3.24 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   * StreamedResponse represents a streamed HTTP response.
 016   *
 017   * A StreamedResponse uses a callback for its content.
 018   *
 019   * The callback should use the standard PHP functions like echo
 020   * to stream the response back to the client. The flush() method
 021   * can also be used if needed.
 022   *
 023   * @see flush()
 024   *
 025   * @author Fabien Potencier <fabien@symfony.com>
 026   */
 027  class StreamedResponse extends Response
 028  {
 029      protected $callback;
 030      protected $streamed;
 031      private $headersSent;
 032   
 033      /**
 034       * Constructor.
 035       *
 036       * @param callable|null $callback A valid PHP callback or null to set it later
 037       * @param int           $status   The response status code
 038       * @param array         $headers  An array of response headers
 039       */
 040      public function __construct($callback = null, $status = 200, $headers = array())
 041      {
 042          parent::__construct(null, $status, $headers);
 043   
 044          if (null !== $callback) {
 045              $this->setCallback($callback);
 046          }
 047          $this->streamed = false;
 048          $this->headersSent = false;
 049      }
 050   
 051      /**
 052       * Factory method for chainability.
 053       *
 054       * @param callable|null $callback A valid PHP callback or null to set it later
 055       * @param int           $status   The response status code
 056       * @param array         $headers  An array of response headers
 057       *
 058       * @return StreamedResponse
 059       */
 060      public static function create($callback = null, $status = 200, $headers = array())
 061      {
 062          return new static($callback, $status, $headers);
 063      }
 064   
 065      /**
 066       * Sets the PHP callback associated with this Response.
 067       *
 068       * @param callable $callback A valid PHP callback
 069       *
 070       * @throws \LogicException
 071       */
 072      public function setCallback($callback)
 073      {
 074          if (!is_callable($callback)) {
 075              throw new \LogicException('The Response callback must be a valid PHP callable.');
 076          }
 077          $this->callback = $callback;
 078      }
 079   
 080      /**
 081       * {@inheritdoc}
 082       *
 083       * This method only sends the headers once.
 084       */
 085      public function sendHeaders()
 086      {
 087          if ($this->headersSent) {
 088              return;
 089          }
 090   
 091          $this->headersSent = true;
 092   
 093          parent::sendHeaders();
 094      }
 095   
 096      /**
 097       * {@inheritdoc}
 098       *
 099       * This method only sends the content once.
 100       */
 101      public function sendContent()
 102      {
 103          if ($this->streamed) {
 104              return;
 105          }
 106   
 107          $this->streamed = true;
 108   
 109          if (null === $this->callback) {
 110              throw new \LogicException('The Response callback must not be null.');
 111          }
 112   
 113          call_user_func($this->callback);
 114      }
 115   
 116      /**
 117       * {@inheritdoc}
 118       *
 119       * @throws \LogicException when the content is not null
 120       */
 121      public function setContent($content)
 122      {
 123          if (null !== $content) {
 124              throw new \LogicException('The content cannot be set on a StreamedResponse instance.');
 125          }
 126      }
 127   
 128      /**
 129       * {@inheritdoc}
 130       *
 131       * @return false
 132       */
 133      public function getContent()
 134      {
 135          return false;
 136      }
 137  }
 138