Mercurial > hg > isophonics-drupal-site
diff vendor/symfony/http-foundation/Response.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children | c2387f117808 |
line wrap: on
line diff
--- a/vendor/symfony/http-foundation/Response.php Mon Apr 23 09:33:26 2018 +0100 +++ b/vendor/symfony/http-foundation/Response.php Mon Apr 23 09:46:53 2018 +0100 @@ -126,6 +126,7 @@ 100 => 'Continue', 101 => 'Switching Protocols', 102 => 'Processing', // RFC2518 + 103 => 'Early Hints', 200 => 'OK', 201 => 'Created', 202 => 'Accepted', @@ -186,33 +187,7 @@ 511 => 'Network Authentication Required', // RFC6585 ); - private static $deprecatedMethods = array( - 'setDate', 'getDate', - 'setExpires', 'getExpires', - 'setLastModified', 'getLastModified', - 'setProtocolVersion', 'getProtocolVersion', - 'setStatusCode', 'getStatusCode', - 'setCharset', 'getCharset', - 'setPrivate', 'setPublic', - 'getAge', 'getMaxAge', 'setMaxAge', 'setSharedMaxAge', - 'getTtl', 'setTtl', 'setClientTtl', - 'getEtag', 'setEtag', - 'hasVary', 'getVary', 'setVary', - 'isInvalid', 'isSuccessful', 'isRedirection', - 'isClientError', 'isOk', 'isForbidden', - 'isNotFound', 'isRedirect', 'isEmpty', - ); - private static $deprecationsTriggered = array( - __CLASS__ => true, - BinaryFileResponse::class => true, - JsonResponse::class => true, - RedirectResponse::class => true, - StreamedResponse::class => true, - ); - /** - * Constructor. - * * @param mixed $content The response content, see setContent() * @param int $status The response status code * @param array $headers An array of response headers @@ -225,28 +200,6 @@ $this->setContent($content); $this->setStatusCode($status); $this->setProtocolVersion('1.0'); - - /* RFC2616 - 14.18 says all Responses need to have a Date */ - if (!$this->headers->has('Date')) { - $this->setDate(\DateTime::createFromFormat('U', time())); - } - - // Deprecations - $class = get_class($this); - if ($this instanceof \PHPUnit_Framework_MockObject_MockObject || $this instanceof \Prophecy\Doubler\DoubleInterface) { - $class = get_parent_class($class); - } - if (isset(self::$deprecationsTriggered[$class])) { - return; - } - - self::$deprecationsTriggered[$class] = true; - foreach (self::$deprecatedMethods as $method) { - $r = new \ReflectionMethod($class, $method); - if (__CLASS__ !== $r->getDeclaringClass()->getName()) { - @trigger_error(sprintf('Extending %s::%s() in %s is deprecated since version 3.2 and won\'t be supported anymore in 4.0 as it will be final.', __CLASS__, $method, $class), E_USER_DEPRECATED); - } - } } /** @@ -302,8 +255,6 @@ * compliant with RFC 2616. Most of the changes are based on * the Request that is "associated" with this Response. * - * @param Request $request A Request instance - * * @return $this */ public function prepare(Request $request) @@ -375,13 +326,8 @@ return $this; } - /* RFC2616 - 14.18 says all Responses need to have a Date */ - if (!$this->headers->has('Date')) { - $this->setDate(\DateTime::createFromFormat('U', time())); - } - // headers - foreach ($this->headers->allPreserveCase() as $name => $values) { + foreach ($this->headers->allPreserveCaseWithoutCookies() as $name => $values) { foreach ($values as $value) { header($name.': '.$value, false, $this->statusCode); } @@ -426,7 +372,7 @@ if (function_exists('fastcgi_finish_request')) { fastcgi_finish_request(); - } elseif ('cli' !== PHP_SAPI) { + } elseif (!\in_array(PHP_SAPI, array('cli', 'phpdbg'), true)) { static::closeOutputBuffers(0, true); } @@ -471,6 +417,8 @@ * @param string $version The HTTP protocol version * * @return $this + * + * @final since version 3.2 */ public function setProtocolVersion($version) { @@ -483,6 +431,8 @@ * Gets the HTTP protocol version. * * @return string The HTTP protocol version + * + * @final since version 3.2 */ public function getProtocolVersion() { @@ -492,15 +442,17 @@ /** * Sets the response status code. * + * If the status text is null it will be automatically populated for the known + * status codes and left empty otherwise. + * * @param int $code HTTP status code * @param mixed $text HTTP status text * - * If the status text is null it will be automatically populated for the known - * status codes and left empty otherwise. - * * @return $this * * @throws \InvalidArgumentException When the HTTP status code is not valid + * + * @final since version 3.2 */ public function setStatusCode($code, $text = null) { @@ -530,6 +482,8 @@ * Retrieves the status code for the current web response. * * @return int Status code + * + * @final since version 3.2 */ public function getStatusCode() { @@ -542,6 +496,8 @@ * @param string $charset Character set * * @return $this + * + * @final since version 3.2 */ public function setCharset($charset) { @@ -554,6 +510,8 @@ * Retrieves the response charset. * * @return string Character set + * + * @final since version 3.2 */ public function getCharset() { @@ -570,6 +528,8 @@ * validator (Last-Modified, ETag) are considered uncacheable. * * @return bool true if the response is worth caching, false otherwise + * + * @final since version 3.3 */ public function isCacheable() { @@ -592,6 +552,8 @@ * indicator or Expires header and the calculated age is less than the freshness lifetime. * * @return bool true if the response is fresh, false otherwise + * + * @final since version 3.3 */ public function isFresh() { @@ -603,6 +565,8 @@ * the response with the origin server using a conditional GET request. * * @return bool true if the response is validateable, false otherwise + * + * @final since version 3.3 */ public function isValidateable() { @@ -615,6 +579,8 @@ * It makes the response ineligible for serving other clients. * * @return $this + * + * @final since version 3.2 */ public function setPrivate() { @@ -630,6 +596,8 @@ * It makes the response eligible for serving other clients. * * @return $this + * + * @final since version 3.2 */ public function setPublic() { @@ -640,6 +608,38 @@ } /** + * Marks the response as "immutable". + * + * @param bool $immutable enables or disables the immutable directive + * + * @return $this + * + * @final + */ + public function setImmutable($immutable = true) + { + if ($immutable) { + $this->headers->addCacheControlDirective('immutable'); + } else { + $this->headers->removeCacheControlDirective('immutable'); + } + + return $this; + } + + /** + * Returns true if the response is marked as "immutable". + * + * @return bool returns true if the response is marked as "immutable"; otherwise false + * + * @final + */ + public function isImmutable() + { + return $this->headers->hasCacheControlDirective('immutable'); + } + + /** * Returns true if the response must be revalidated by caches. * * This method indicates that the response must not be served stale by a @@ -648,6 +648,8 @@ * greater than the value provided by the origin. * * @return bool true if the response must be revalidated by a cache, false otherwise + * + * @final since version 3.3 */ public function mustRevalidate() { @@ -660,27 +662,20 @@ * @return \DateTime A \DateTime instance * * @throws \RuntimeException When the header is not parseable + * + * @final since version 3.2 */ public function getDate() { - /* - RFC2616 - 14.18 says all Responses need to have a Date. - Make sure we provide one even if it the header - has been removed in the meantime. - */ - if (!$this->headers->has('Date')) { - $this->setDate(\DateTime::createFromFormat('U', time())); - } - return $this->headers->getDate('Date'); } /** * Sets the Date header. * - * @param \DateTime $date A \DateTime instance + * @return $this * - * @return $this + * @final since version 3.2 */ public function setDate(\DateTime $date) { @@ -694,6 +689,8 @@ * Returns the age of the response. * * @return int The age of the response in seconds + * + * @final since version 3.2 */ public function getAge() { @@ -722,6 +719,8 @@ * Returns the value of the Expires header as a DateTime instance. * * @return \DateTime|null A DateTime instance or null if the header does not exist + * + * @final since version 3.2 */ public function getExpires() { @@ -741,6 +740,8 @@ * @param \DateTime|null $date A \DateTime instance or null to remove the header * * @return $this + * + * @final since version 3.2 */ public function setExpires(\DateTime $date = null) { @@ -763,6 +764,8 @@ * back on an expires header. It returns null when no maximum age can be established. * * @return int|null Number of seconds + * + * @final since version 3.2 */ public function getMaxAge() { @@ -787,6 +790,8 @@ * @param int $value Number of seconds * * @return $this + * + * @final since version 3.2 */ public function setMaxAge($value) { @@ -803,6 +808,8 @@ * @param int $value Number of seconds * * @return $this + * + * @final since version 3.2 */ public function setSharedMaxAge($value) { @@ -821,6 +828,8 @@ * revalidating with the origin. * * @return int|null The TTL in seconds + * + * @final since version 3.2 */ public function getTtl() { @@ -837,6 +846,8 @@ * @param int $seconds Number of seconds * * @return $this + * + * @final since version 3.2 */ public function setTtl($seconds) { @@ -853,6 +864,8 @@ * @param int $seconds Number of seconds * * @return $this + * + * @final since version 3.2 */ public function setClientTtl($seconds) { @@ -867,6 +880,8 @@ * @return \DateTime|null A DateTime instance or null if the header does not exist * * @throws \RuntimeException When the HTTP header is not parseable + * + * @final since version 3.2 */ public function getLastModified() { @@ -881,6 +896,8 @@ * @param \DateTime|null $date A \DateTime instance or null to remove the header * * @return $this + * + * @final since version 3.2 */ public function setLastModified(\DateTime $date = null) { @@ -899,6 +916,8 @@ * Returns the literal value of the ETag HTTP header. * * @return string|null The ETag HTTP header or null if it does not exist + * + * @final since version 3.2 */ public function getEtag() { @@ -912,6 +931,8 @@ * @param bool $weak Whether you want a weak ETag or not * * @return $this + * + * @final since version 3.2 */ public function setEtag($etag = null, $weak = false) { @@ -931,17 +952,19 @@ /** * Sets the response's cache headers (validation and/or expiration). * - * Available options are: etag, last_modified, max_age, s_maxage, private, and public. + * Available options are: etag, last_modified, max_age, s_maxage, private, public and immutable. * * @param array $options An array of cache options * * @return $this * * @throws \InvalidArgumentException + * + * @final since version 3.3 */ public function setCache(array $options) { - if ($diff = array_diff(array_keys($options), array('etag', 'last_modified', 'max_age', 's_maxage', 'private', 'public'))) { + if ($diff = array_diff(array_keys($options), array('etag', 'last_modified', 'max_age', 's_maxage', 'private', 'public', 'immutable'))) { throw new \InvalidArgumentException(sprintf('Response does not support the following options: "%s".', implode('", "', array_values($diff)))); } @@ -977,6 +1000,10 @@ } } + if (isset($options['immutable'])) { + $this->setImmutable((bool) $options['immutable']); + } + return $this; } @@ -989,6 +1016,8 @@ * @return $this * * @see http://tools.ietf.org/html/rfc2616#section-10.3.5 + * + * @final since version 3.3 */ public function setNotModified() { @@ -1007,6 +1036,8 @@ * Returns true if the response includes a Vary header. * * @return bool true if the response includes a Vary header, false otherwise + * + * @final since version 3.2 */ public function hasVary() { @@ -1017,6 +1048,8 @@ * Returns an array of header names given in the Vary header. * * @return array An array of Vary names + * + * @final since version 3.2 */ public function getVary() { @@ -1039,6 +1072,8 @@ * @param bool $replace Whether to replace the actual value or not (true by default) * * @return $this + * + * @final since version 3.2 */ public function setVary($headers, $replace = true) { @@ -1054,9 +1089,9 @@ * If the Response is not modified, it sets the status code to 304 and * removes the actual content by calling the setNotModified() method. * - * @param Request $request A Request instance + * @return bool true if the Response validators match the Request, false otherwise * - * @return bool true if the Response validators match the Request, false otherwise + * @final since version 3.3 */ public function isNotModified(Request $request) { @@ -1089,6 +1124,8 @@ * @return bool * * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html + * + * @final since version 3.2 */ public function isInvalid() { @@ -1099,6 +1136,8 @@ * Is response informative? * * @return bool + * + * @final since version 3.3 */ public function isInformational() { @@ -1109,6 +1148,8 @@ * Is response successful? * * @return bool + * + * @final since version 3.2 */ public function isSuccessful() { @@ -1119,6 +1160,8 @@ * Is the response a redirect? * * @return bool + * + * @final since version 3.2 */ public function isRedirection() { @@ -1129,6 +1172,8 @@ * Is there a client error? * * @return bool + * + * @final since version 3.2 */ public function isClientError() { @@ -1139,6 +1184,8 @@ * Was there a server side error? * * @return bool + * + * @final since version 3.3 */ public function isServerError() { @@ -1149,6 +1196,8 @@ * Is the response OK? * * @return bool + * + * @final since version 3.2 */ public function isOk() { @@ -1159,6 +1208,8 @@ * Is the response forbidden? * * @return bool + * + * @final since version 3.2 */ public function isForbidden() { @@ -1169,6 +1220,8 @@ * Is the response a not found error? * * @return bool + * + * @final since version 3.2 */ public function isNotFound() { @@ -1181,6 +1234,8 @@ * @param string $location * * @return bool + * + * @final since version 3.2 */ public function isRedirect($location = null) { @@ -1191,6 +1246,8 @@ * Is the response empty? * * @return bool + * + * @final since version 3.2 */ public function isEmpty() { @@ -1204,6 +1261,8 @@ * * @param int $targetLevel The target output buffering level * @param bool $flush Whether to flush or clean the buffers + * + * @final since version 3.3 */ public static function closeOutputBuffers($targetLevel, $flush) { @@ -1212,7 +1271,7 @@ // PHP_OUTPUT_HANDLER_* are not defined on HHVM 3.3 $flags = defined('PHP_OUTPUT_HANDLER_REMOVABLE') ? PHP_OUTPUT_HANDLER_REMOVABLE | ($flush ? PHP_OUTPUT_HANDLER_FLUSHABLE : PHP_OUTPUT_HANDLER_CLEANABLE) : -1; - while ($level-- > $targetLevel && ($s = $status[$level]) && (!isset($s['del']) ? !isset($s['flags']) || $flags === ($s['flags'] & $flags) : $s['del'])) { + while ($level-- > $targetLevel && ($s = $status[$level]) && (!isset($s['del']) ? !isset($s['flags']) || ($s['flags'] & $flags) === $flags : $s['del'])) { if ($flush) { ob_end_flush(); } else { @@ -1225,10 +1284,12 @@ * Checks if we need to remove Cache-Control for SSL encrypted downloads when using IE < 9. * * @see http://support.microsoft.com/kb/323308 + * + * @final since version 3.3 */ protected function ensureIEOverSSLCompatibility(Request $request) { - if (false !== stripos($this->headers->get('Content-Disposition'), 'attachment') && preg_match('/MSIE (.*?);/i', $request->server->get('HTTP_USER_AGENT'), $match) == 1 && true === $request->isSecure()) { + if (false !== stripos($this->headers->get('Content-Disposition'), 'attachment') && 1 == preg_match('/MSIE (.*?);/i', $request->server->get('HTTP_USER_AGENT'), $match) && true === $request->isSecure()) { if ((int) preg_replace('/(MSIE )(.*?);/', '$2', $match[0]) < 9) { $this->headers->remove('Cache-Control'); }