package and depencies

This commit is contained in:
RafficMohammed
2023-01-08 02:57:24 +05:30
parent d5332eb421
commit 1d54b8bc7f
4309 changed files with 193331 additions and 172289 deletions

View File

@@ -98,6 +98,8 @@ class Response
'proxy_revalidate' => false,
'max_age' => true,
's_maxage' => true,
'stale_if_error' => true, // RFC5861
'stale_while_revalidate' => true, // RFC5861
'immutable' => false,
'last_modified' => true,
'etag' => true,
@@ -210,6 +212,8 @@ class Response
];
/**
* @param int $status The HTTP status code (200 "OK" by default)
*
* @throws \InvalidArgumentException When the HTTP status code is not valid
*/
public function __construct(?string $content = '', int $status = 200, array $headers = [])
@@ -220,25 +224,6 @@ class Response
$this->setProtocolVersion('1.0');
}
/**
* Factory method for chainability.
*
* Example:
*
* return Response::create($body, 200)
* ->setSharedMaxAge(300);
*
* @return static
*
* @deprecated since Symfony 5.1, use __construct() instead.
*/
public static function create(?string $content = '', 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($content, $status, $headers);
}
/**
* Returns the Response as an HTTP string.
*
@@ -246,11 +231,9 @@ class Response
* one that will be sent to the client only if the prepare() method
* has been called before.
*
* @return string
*
* @see prepare()
*/
public function __toString()
public function __toString(): string
{
return
sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText)."\r\n".
@@ -275,7 +258,7 @@ class Response
*
* @return $this
*/
public function prepare(Request $request)
public function prepare(Request $request): static
{
$headers = $this->headers;
@@ -345,7 +328,7 @@ class Response
*
* @return $this
*/
public function sendHeaders()
public function sendHeaders(): static
{
// headers have already been sent by the developer
if (headers_sent()) {
@@ -376,7 +359,7 @@ class Response
*
* @return $this
*/
public function sendContent()
public function sendContent(): static
{
echo $this->content;
@@ -388,7 +371,7 @@ class Response
*
* @return $this
*/
public function send()
public function send(): static
{
$this->sendHeaders();
$this->sendContent();
@@ -410,7 +393,7 @@ class Response
*
* @return $this
*/
public function setContent(?string $content)
public function setContent(?string $content): static
{
$this->content = $content ?? '';
@@ -419,10 +402,8 @@ class Response
/**
* Gets the current response content.
*
* @return string|false
*/
public function getContent()
public function getContent(): string|false
{
return $this->content;
}
@@ -434,7 +415,7 @@ class Response
*
* @final
*/
public function setProtocolVersion(string $version): object
public function setProtocolVersion(string $version): static
{
$this->version = $version;
@@ -463,7 +444,7 @@ class Response
*
* @final
*/
public function setStatusCode(int $code, string $text = null): object
public function setStatusCode(int $code, string $text = null): static
{
$this->statusCode = $code;
if ($this->isInvalid()) {
@@ -504,7 +485,7 @@ class Response
*
* @final
*/
public function setCharset(string $charset): object
public function setCharset(string $charset): static
{
$this->charset = $charset;
@@ -585,7 +566,7 @@ class Response
*
* @final
*/
public function setPrivate(): object
public function setPrivate(): static
{
$this->headers->removeCacheControlDirective('public');
$this->headers->addCacheControlDirective('private');
@@ -602,7 +583,7 @@ class Response
*
* @final
*/
public function setPublic(): object
public function setPublic(): static
{
$this->headers->addCacheControlDirective('public');
$this->headers->removeCacheControlDirective('private');
@@ -617,7 +598,7 @@ class Response
*
* @final
*/
public function setImmutable(bool $immutable = true): object
public function setImmutable(bool $immutable = true): static
{
if ($immutable) {
$this->headers->addCacheControlDirective('immutable');
@@ -672,7 +653,7 @@ class Response
*
* @final
*/
public function setDate(\DateTimeInterface $date): object
public function setDate(\DateTimeInterface $date): static
{
if ($date instanceof \DateTime) {
$date = \DateTimeImmutable::createFromMutable($date);
@@ -703,7 +684,7 @@ class Response
*
* @return $this
*/
public function expire()
public function expire(): static
{
if ($this->isFresh()) {
$this->headers->set('Age', $this->getMaxAge());
@@ -722,7 +703,7 @@ class Response
{
try {
return $this->headers->getDate('Expires');
} catch (\RuntimeException $e) {
} catch (\RuntimeException) {
// according to RFC 2616 invalid date formats (e.g. "0" and "-1") must be treated as in the past
return \DateTime::createFromFormat('U', time() - 172800);
}
@@ -737,8 +718,11 @@ class Response
*
* @final
*/
public function setExpires(\DateTimeInterface $date = null): object
public function setExpires(\DateTimeInterface $date = null): static
{
if (1 > \func_num_args()) {
trigger_deprecation('symfony/http-foundation', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
}
if (null === $date) {
$this->headers->remove('Expires');
@@ -790,13 +774,45 @@ class Response
*
* @final
*/
public function setMaxAge(int $value): object
public function setMaxAge(int $value): static
{
$this->headers->addCacheControlDirective('max-age', $value);
return $this;
}
/**
* Sets the number of seconds after which the response should no longer be returned by shared caches when backend is down.
*
* This method sets the Cache-Control stale-if-error directive.
*
* @return $this
*
* @final
*/
public function setStaleIfError(int $value): static
{
$this->headers->addCacheControlDirective('stale-if-error', $value);
return $this;
}
/**
* Sets the number of seconds after which the response should no longer return stale content by shared caches.
*
* This method sets the Cache-Control stale-while-revalidate directive.
*
* @return $this
*
* @final
*/
public function setStaleWhileRevalidate(int $value): static
{
$this->headers->addCacheControlDirective('stale-while-revalidate', $value);
return $this;
}
/**
* Sets the number of seconds after which the response should no longer be considered fresh by shared caches.
*
@@ -806,7 +822,7 @@ class Response
*
* @final
*/
public function setSharedMaxAge(int $value): object
public function setSharedMaxAge(int $value): static
{
$this->setPublic();
$this->headers->addCacheControlDirective('s-maxage', $value);
@@ -840,7 +856,7 @@ class Response
*
* @final
*/
public function setTtl(int $seconds): object
public function setTtl(int $seconds): static
{
$this->setSharedMaxAge($this->getAge() + $seconds);
@@ -856,7 +872,7 @@ class Response
*
* @final
*/
public function setClientTtl(int $seconds): object
public function setClientTtl(int $seconds): static
{
$this->setMaxAge($this->getAge() + $seconds);
@@ -884,8 +900,11 @@ class Response
*
* @final
*/
public function setLastModified(\DateTimeInterface $date = null): object
public function setLastModified(\DateTimeInterface $date = null): static
{
if (1 > \func_num_args()) {
trigger_deprecation('symfony/http-foundation', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
}
if (null === $date) {
$this->headers->remove('Last-Modified');
@@ -922,8 +941,11 @@ class Response
*
* @final
*/
public function setEtag(string $etag = null, bool $weak = false): object
public function setEtag(string $etag = null, bool $weak = false): static
{
if (1 > \func_num_args()) {
trigger_deprecation('symfony/http-foundation', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
}
if (null === $etag) {
$this->headers->remove('Etag');
} else {
@@ -948,7 +970,7 @@ class Response
*
* @final
*/
public function setCache(array $options): object
public function setCache(array $options): static
{
if ($diff = array_diff(array_keys($options), array_keys(self::HTTP_RESPONSE_CACHE_CONTROL_DIRECTIVES))) {
throw new \InvalidArgumentException(sprintf('Response does not support the following options: "%s".', implode('", "', $diff)));
@@ -970,6 +992,14 @@ class Response
$this->setSharedMaxAge($options['s_maxage']);
}
if (isset($options['stale_while_revalidate'])) {
$this->setStaleWhileRevalidate($options['stale_while_revalidate']);
}
if (isset($options['stale_if_error'])) {
$this->setStaleIfError($options['stale_if_error']);
}
foreach (self::HTTP_RESPONSE_CACHE_CONTROL_DIRECTIVES as $directive => $hasValue) {
if (!$hasValue && isset($options[$directive])) {
if ($options[$directive]) {
@@ -1011,7 +1041,7 @@ class Response
*
* @final
*/
public function setNotModified(): object
public function setNotModified(): static
{
$this->setStatusCode(304);
$this->setContent(null);
@@ -1056,14 +1086,13 @@ class Response
/**
* Sets the Vary header.
*
* @param string|array $headers
* @param bool $replace Whether to replace the actual value or not (true by default)
* @param bool $replace Whether to replace the actual value or not (true by default)
*
* @return $this
*
* @final
*/
public function setVary($headers, bool $replace = true): object
public function setVary(string|array $headers, bool $replace = true): static
{
$this->headers->set('Vary', $headers, $replace);