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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
StreamedResponse.php
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() function
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 * @param callable|null $callback A valid PHP callback or null to set it later
035 * @param int $status The response status code
036 * @param array $headers An array of response headers
037 */
038 public function __construct(callable $callback = null, $status = 200, $headers = [])
039 {
040 parent::__construct(null, $status, $headers);
041
042 if (null !== $callback) {
043 $this->setCallback($callback);
044 }
045 $this->streamed = false;
046 $this->headersSent = false;
047 }
048
049 /**
050 * Factory method for chainability.
051 *
052 * @param callable|null $callback A valid PHP callback or null to set it later
053 * @param int $status The response status code
054 * @param array $headers An array of response headers
055 *
056 * @return static
057 */
058 public static function create($callback = null, $status = 200, $headers = [])
059 {
060 return new static($callback, $status, $headers);
061 }
062
063 /**
064 * Sets the PHP callback associated with this Response.
065 *
066 * @param callable $callback A valid PHP callback
067 *
068 * @return $this
069 */
070 public function setCallback(callable $callback)
071 {
072 $this->callback = $callback;
073
074 return $this;
075 }
076
077 /**
078 * {@inheritdoc}
079 *
080 * This method only sends the headers once.
081 *
082 * @return $this
083 */
084 public function sendHeaders()
085 {
086 if ($this->headersSent) {
087 return $this;
088 }
089
090 $this->headersSent = true;
091
092 return parent::sendHeaders();
093 }
094
095 /**
096 * {@inheritdoc}
097 *
098 * This method only sends the content once.
099 *
100 * @return $this
101 */
102 public function sendContent()
103 {
104 if ($this->streamed) {
105 return $this;
106 }
107
108 $this->streamed = true;
109
110 if (null === $this->callback) {
111 throw new \LogicException('The Response callback must not be null.');
112 }
113
114 \call_user_func($this->callback);
115
116 return $this;
117 }
118
119 /**
120 * {@inheritdoc}
121 *
122 * @throws \LogicException when the content is not null
123 *
124 * @return $this
125 */
126 public function setContent($content)
127 {
128 if (null !== $content) {
129 throw new \LogicException('The content cannot be set on a StreamedResponse instance.');
130 }
131
132 $this->streamed = true;
133
134 return $this;
135 }
136
137 /**
138 * {@inheritdoc}
139 */
140 public function getContent()
141 {
142 return false;
143 }
144 }
145