Open Journal Systems  3.3.0
vendor/symfony/http-foundation/StreamedResponse.php
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
13 
27 class StreamedResponse extends Response
28 {
29  protected $callback;
30  protected $streamed;
31  private $headersSent;
32 
38  public function __construct(callable $callback = null, int $status = 200, array $headers = [])
39  {
40  parent::__construct(null, $status, $headers);
41 
42  if (null !== $callback) {
43  $this->setCallback($callback);
44  }
45  $this->streamed = false;
46  $this->headersSent = false;
47  }
48 
58  public static function create($callback = null, $status = 200, $headers = [])
59  {
60  return new static($callback, $status, $headers);
61  }
62 
68  public function setCallback(callable $callback)
69  {
70  $this->callback = $callback;
71 
72  return $this;
73  }
74 
82  public function sendHeaders()
83  {
84  if ($this->headersSent) {
85  return $this;
86  }
87 
88  $this->headersSent = true;
89 
90  return parent::sendHeaders();
91  }
92 
100  public function sendContent()
101  {
102  if ($this->streamed) {
103  return $this;
104  }
105 
106  $this->streamed = true;
107 
108  if (null === $this->callback) {
109  throw new \LogicException('The Response callback must not be null.');
110  }
111 
112  ($this->callback)();
113 
114  return $this;
115  }
116 
124  public function setContent($content)
125  {
126  if (null !== $content) {
127  throw new \LogicException('The content cannot be set on a StreamedResponse instance.');
128  }
129 
130  $this->streamed = true;
131 
132  return $this;
133  }
134 
138  public function getContent()
139  {
140  return false;
141  }
142 }
Symfony\Component\HttpFoundation\StreamedResponse\sendContent
sendContent()
Definition: vendor/symfony/http-foundation/StreamedResponse.php:100
Symfony\Component\HttpFoundation\StreamedResponse\sendHeaders
sendHeaders()
Definition: vendor/symfony/http-foundation/StreamedResponse.php:82
Symfony\Component\HttpFoundation\StreamedResponse\setCallback
setCallback(callable $callback)
Definition: lib/vendor/symfony/http-foundation/StreamedResponse.php:70
Symfony\Component\HttpFoundation\StreamedResponse\__construct
__construct(callable $callback=null, int $status=200, array $headers=[])
Definition: vendor/symfony/http-foundation/StreamedResponse.php:38
Symfony\Component\HttpFoundation\StreamedResponse\create
static create($callback=null, $status=200, $headers=[])
Definition: vendor/symfony/http-foundation/StreamedResponse.php:58
Symfony\Component\HttpFoundation\StreamedResponse\setContent
setContent($content)
Definition: vendor/symfony/http-foundation/StreamedResponse.php:124
Symfony\Component\HttpFoundation\Response\$content
$content
Definition: lib/vendor/symfony/http-foundation/Response.php:98
Symfony\Component\HttpFoundation\Response\$headers
$headers
Definition: lib/vendor/symfony/http-foundation/Response.php:90
Symfony\Component\HttpFoundation\StreamedResponse\$callback
$callback
Definition: lib/vendor/symfony/http-foundation/StreamedResponse.php:29
Symfony\Component\HttpFoundation\StreamedResponse\$streamed
$streamed
Definition: lib/vendor/symfony/http-foundation/StreamedResponse.php:30
Symfony\Component\HttpFoundation\StreamedResponse\getContent
getContent()
Definition: vendor/symfony/http-foundation/StreamedResponse.php:138
Symfony\Component\HttpFoundation
Definition: lib/vendor/symfony/http-foundation/AcceptHeader.php:12