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. |
|
(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() method
021 * can also be used if needed.
022 *
023 * @see flush()
024 *
025 * @author Fabien Potencier <fabien@symfony.com>
026 *
027 * @api
028 */
029 class StreamedResponse extends Response
030 {
031 protected $callback;
032 protected $streamed;
033
034 /**
035 * Constructor.
036 *
037 * @param mixed $callback A valid PHP callback
038 * @param int $status The response status code
039 * @param array $headers An array of response headers
040 *
041 * @api
042 */
043 public function __construct($callback = null, $status = 200, $headers = array())
044 {
045 parent::__construct(null, $status, $headers);
046
047 if (null !== $callback) {
048 $this->setCallback($callback);
049 }
050 $this->streamed = false;
051 }
052
053 /**
054 * {@inheritdoc}
055 */
056 public static function create($callback = null, $status = 200, $headers = array())
057 {
058 return new static($callback, $status, $headers);
059 }
060
061 /**
062 * Sets the PHP callback associated with this Response.
063 *
064 * @param mixed $callback A valid PHP callback
065 *
066 * @throws \LogicException
067 */
068 public function setCallback($callback)
069 {
070 if (!is_callable($callback)) {
071 throw new \LogicException('The Response callback must be a valid PHP callable.');
072 }
073 $this->callback = $callback;
074 }
075
076 /**
077 * {@inheritdoc}
078 */
079 public function prepare(Request $request)
080 {
081 $this->headers->set('Cache-Control', 'no-cache');
082
083 return parent::prepare($request);
084 }
085
086 /**
087 * {@inheritdoc}
088 *
089 * This method only sends the content once.
090 */
091 public function sendContent()
092 {
093 if ($this->streamed) {
094 return;
095 }
096
097 $this->streamed = true;
098
099 if (null === $this->callback) {
100 throw new \LogicException('The Response callback must not be null.');
101 }
102
103 call_user_func($this->callback);
104 }
105
106 /**
107 * {@inheritdoc}
108 *
109 * @throws \LogicException when the content is not null
110 */
111 public function setContent($content)
112 {
113 if (null !== $content) {
114 throw new \LogicException('The content cannot be set on a StreamedResponse instance.');
115 }
116 }
117
118 /**
119 * {@inheritdoc}
120 *
121 * @return false
122 */
123 public function getContent()
124 {
125 return false;
126 }
127 }
128