Open Journal Systems  3.3.0
lib/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 
28 {
29  protected $callback;
30  protected $streamed;
31  private $headersSent;
32 
40  public function __construct(callable $callback = null, $status = 200, $headers = array())
41  {
42  parent::__construct(null, $status, $headers);
43 
44  if (null !== $callback) {
45  $this->setCallback($callback);
46  }
47  $this->streamed = false;
48  $this->headersSent = false;
49  }
50 
60  public static function create($callback = null, $status = 200, $headers = array())
61  {
62  return new static($callback, $status, $headers);
63  }
64 
70  public function setCallback(callable $callback)
71  {
72  $this->callback = $callback;
73  }
74 
80  public function sendHeaders()
81  {
82  if ($this->headersSent) {
83  return;
84  }
85 
86  $this->headersSent = true;
87 
88  parent::sendHeaders();
89  }
90 
96  public function sendContent()
97  {
98  if ($this->streamed) {
99  return;
100  }
101 
102  $this->streamed = true;
103 
104  if (null === $this->callback) {
105  throw new \LogicException('The Response callback must not be null.');
106  }
107 
108  call_user_func($this->callback);
109  }
110 
116  public function setContent($content)
117  {
118  if (null !== $content) {
119  throw new \LogicException('The content cannot be set on a StreamedResponse instance.');
120  }
121  }
122 
128  public function getContent()
129  {
130  return false;
131  }
132 }
Symfony\Component\HttpFoundation\StreamedResponse\sendContent
sendContent()
Definition: lib/vendor/symfony/http-foundation/StreamedResponse.php:96
Symfony\Component\HttpFoundation\Response
Definition: lib/vendor/symfony/http-foundation/Response.php:19
Symfony\Component\HttpFoundation\StreamedResponse\sendHeaders
sendHeaders()
Definition: lib/vendor/symfony/http-foundation/StreamedResponse.php:80
Symfony\Component\HttpFoundation\StreamedResponse\setCallback
setCallback(callable $callback)
Definition: lib/vendor/symfony/http-foundation/StreamedResponse.php:70
Symfony\Component\HttpFoundation\StreamedResponse\setContent
setContent($content)
Definition: lib/vendor/symfony/http-foundation/StreamedResponse.php:116
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: lib/vendor/symfony/http-foundation/StreamedResponse.php:128
Symfony\Component\HttpFoundation\StreamedResponse
Definition: lib/vendor/symfony/http-foundation/StreamedResponse.php:27
Symfony\Component\HttpFoundation\StreamedResponse\__construct
__construct(callable $callback=null, $status=200, $headers=array())
Definition: lib/vendor/symfony/http-foundation/StreamedResponse.php:40
Symfony\Component\HttpFoundation
Definition: lib/vendor/symfony/http-foundation/AcceptHeader.php:12
Symfony\Component\HttpFoundation\StreamedResponse\create
static create($callback=null, $status=200, $headers=array())
Definition: lib/vendor/symfony/http-foundation/StreamedResponse.php:60