1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-05 19:42:38 +02:00
Daniel Neto 2024-03-05 19:22:51 -03:00
parent 7673eda07e
commit 330cdbe615
9054 changed files with 480487 additions and 41800 deletions

View file

@ -28,9 +28,12 @@ class StreamedResponse extends Response
{
protected $callback;
protected $streamed;
private $headersSent;
private bool $headersSent;
public function __construct(callable $callback = null, int $status = 200, array $headers = [])
/**
* @param int $status The HTTP status code (200 "OK" by default)
*/
public function __construct(?callable $callback = null, int $status = 200, array $headers = [])
{
parent::__construct(null, $status, $headers);
@ -41,60 +44,54 @@ class StreamedResponse extends Response
$this->headersSent = false;
}
/**
* Factory method for chainability.
*
* @param callable|null $callback A valid PHP callback or null to set it later
*
* @return static
*
* @deprecated since Symfony 5.1, use __construct() instead.
*/
public static function create($callback = null, int $status = 200, array $headers = [])
{
trigger_deprecation('symfony/http-foundation', '5.1', 'The "%s()" method is deprecated, use "new %s()" instead.', __METHOD__, static::class);
return new static($callback, $status, $headers);
}
/**
* Sets the PHP callback associated with this Response.
*
* @return $this
*/
public function setCallback(callable $callback)
public function setCallback(callable $callback): static
{
$this->callback = $callback;
$this->callback = $callback(...);
return $this;
}
public function getCallback(): ?\Closure
{
if (!isset($this->callback)) {
return null;
}
return ($this->callback)(...);
}
/**
* {@inheritdoc}
*
* This method only sends the headers once.
*
* @param positive-int|null $statusCode The status code to use, override the statusCode property if set and not null
*
* @return $this
*/
public function sendHeaders()
public function sendHeaders(/* int $statusCode = null */): static
{
if ($this->headersSent) {
return $this;
}
$this->headersSent = true;
$statusCode = \func_num_args() > 0 ? func_get_arg(0) : null;
if ($statusCode < 100 || $statusCode >= 200) {
$this->headersSent = true;
}
return parent::sendHeaders();
return parent::sendHeaders($statusCode);
}
/**
* {@inheritdoc}
*
* This method only sends the content once.
*
* @return $this
*/
public function sendContent()
public function sendContent(): static
{
if ($this->streamed) {
return $this;
@ -102,8 +99,8 @@ class StreamedResponse extends Response
$this->streamed = true;
if (null === $this->callback) {
throw new \LogicException('The Response callback must not be null.');
if (!isset($this->callback)) {
throw new \LogicException('The Response callback must be set.');
}
($this->callback)();
@ -112,13 +109,11 @@ class StreamedResponse extends Response
}
/**
* {@inheritdoc}
* @return $this
*
* @throws \LogicException when the content is not null
*
* @return $this
*/
public function setContent(?string $content)
public function setContent(?string $content): static
{
if (null !== $content) {
throw new \LogicException('The content cannot be set on a StreamedResponse instance.');
@ -129,10 +124,7 @@ class StreamedResponse extends Response
return $this;
}
/**
* {@inheritdoc}
*/
public function getContent()
public function getContent(): string|false
{
return false;
}