Browse Source

Adding deprecation warning for the Http package

Florian Krämer 8 years ago
parent
commit
9adee92813

+ 5 - 0
src/Http/ActionDispatcher.php

@@ -149,6 +149,11 @@ class ActionDispatcher
      */
     public function addFilter(EventListenerInterface $filter)
     {
+        deprecationWarning(
+            'ActionDispatcher::addFilter() is deprecated. ' .
+            'This is only available for backwards compatibility with DispatchFilters'
+        );
+
         $this->filters[] = $filter;
         $this->getEventManager()->on($filter);
     }

+ 10 - 0
src/Http/Client/CookieCollection.php

@@ -28,6 +28,16 @@ class CookieCollection extends BaseCollection
 {
 
     /**
+     * {@inheritDoc}
+     */
+    public function __construct(array $cookies = [])
+    {
+        parent::__construct($cookies);
+
+        deprecationWarning('Use Cake\Http\Cookie\CookieCollection instead.');
+    }
+
+    /**
      * Store the cookies from a response.
      *
      * Store the cookies that haven't expired. If a cookie has been expired

+ 5 - 0
src/Http/Client/Message.php

@@ -151,6 +151,11 @@ class Message
      */
     public function headers()
     {
+        deprecationWarning(
+            'Message::headers() is deprecated. ' .
+            'Use getHeaders() instead.'
+        );
+
         return $this->headers;
     }
 

+ 27 - 0
src/Http/Client/Request.php

@@ -64,6 +64,11 @@ class Request extends Message implements RequestInterface
      */
     public function method($method = null)
     {
+        deprecationWarning(
+            'Request::method() is deprecated. ' .
+            'Use getMethod() and withMethod() instead.'
+        );
+
         if ($method === null) {
             return $this->method;
         }
@@ -88,6 +93,11 @@ class Request extends Message implements RequestInterface
      */
     public function url($url = null)
     {
+        deprecationWarning(
+            'Request::url() is deprecated. ' .
+            'Use getUri() and withUri() instead.'
+        );
+
         if ($url === null) {
             return '' . $this->getUri();
         }
@@ -130,6 +140,11 @@ class Request extends Message implements RequestInterface
      */
     public function header($name = null, $value = null)
     {
+        deprecationWarning(
+            'Request::header() is deprecated. ' .
+            'Use withHeader() and getHeaderLine() instead.'
+        );
+
         if ($value === null && is_string($name)) {
             $val = $this->getHeaderLine($name);
             if ($val === '') {
@@ -192,6 +207,13 @@ class Request extends Message implements RequestInterface
      */
     public function cookie($name, $value = null)
     {
+        deprecationWarning(
+            'Request::header() is deprecated. ' .
+            'No longer used. CookieCollections now add `Cookie` header to the ' .
+            'request before sending. Use Cake\Http\Cookie\CookieCollection::addToRequest() ' .
+            'to make adding cookies to a request easier.'
+        );
+
         if ($value === null && is_string($name)) {
             return isset($this->_cookies[$name]) ? $this->_cookies[$name] : null;
         }
@@ -217,6 +239,11 @@ class Request extends Message implements RequestInterface
      */
     public function version($version = null)
     {
+        deprecationWarning(
+            'Request::version() is deprecated. ' .
+            'Use getProtocolVersion() and withProtocolVersion() instead.'
+        );
+
         if ($version === null) {
             return $this->protocol;
         }

+ 25 - 0
src/Http/Client/Response.php

@@ -270,6 +270,11 @@ class Response extends Message implements ResponseInterface
      */
     public function statusCode()
     {
+        deprecationWarning(
+            'Response::statusCode() is deprecated. ' .
+            'Use Response::getStatusCode() instead.'
+        );
+
         return $this->code;
     }
 
@@ -317,6 +322,11 @@ class Response extends Message implements ResponseInterface
      */
     public function encoding()
     {
+        deprecationWarning(
+            'Response::encoding() is deprecated. ' .
+            'Use Response::getEncoding() instead.'
+        );
+
         return $this->getEncoding();
     }
 
@@ -352,6 +362,11 @@ class Response extends Message implements ResponseInterface
      */
     public function header($name = null)
     {
+        deprecationWarning(
+            'Response::header() is deprecated. ' .
+            'Use Response::getHeader() and getHeaderLine() instead.'
+        );
+
         if ($name === null) {
             return $this->_getHeaders();
         }
@@ -379,6 +394,11 @@ class Response extends Message implements ResponseInterface
      */
     public function cookie($name = null, $all = false)
     {
+        deprecationWarning(
+            'Response::cookie() is deprecated. ' .
+            'Use Response::getCookie(), getCookieData() or getCookies() instead.'
+        );
+
         if ($name === null) {
             return $this->getCookies();
         }
@@ -509,6 +529,11 @@ class Response extends Message implements ResponseInterface
      */
     public function version()
     {
+        deprecationWarning(
+            'Response::version() is deprecated. ' .
+            'Use Response::getProtocolVersion() instead.'
+        );
+
         return $this->protocol;
     }
 

+ 130 - 0
src/Http/Response.php

@@ -484,6 +484,10 @@ class Response implements ResponseInterface
      */
     public function send()
     {
+        deprecationWarning(
+            'Will be removed in 4.0.0'
+        );
+
         if ($this->hasHeader('Location') && $this->_status === 200) {
             $this->statusCode(302);
         }
@@ -511,6 +515,10 @@ class Response implements ResponseInterface
      */
     public function sendHeaders()
     {
+        deprecationWarning(
+            'Will be removed in 4.0.0'
+        );
+
         $file = $line = null;
         if (headers_sent($file, $line)) {
             Log::warning("Headers already sent in {$file}:{$line}");
@@ -540,6 +548,10 @@ class Response implements ResponseInterface
      */
     protected function _setCookies()
     {
+        deprecationWarning(
+            'Will be removed in 4.0.0'
+        );
+
         foreach ($this->_cookies as $cookie) {
             setcookie(
                 $cookie->getName(),
@@ -592,6 +604,10 @@ class Response implements ResponseInterface
      */
     protected function _setContent()
     {
+        deprecationWarning(
+            'Will be removed in 4.0.0'
+        );
+
         if (in_array($this->_status, [304, 204])) {
             $this->body('');
         }
@@ -607,6 +623,10 @@ class Response implements ResponseInterface
      */
     protected function _sendHeader($name, $value = null)
     {
+        deprecationWarning(
+            'Will be removed in 4.0.0'
+        );
+
         if ($value === null) {
             header($name);
         } else {
@@ -627,6 +647,10 @@ class Response implements ResponseInterface
      */
     protected function _sendContent($content)
     {
+        deprecationWarning(
+            'Will be removed in 4.0.0'
+        );
+
         if (!is_string($content) && is_callable($content)) {
             $content = $content();
         }
@@ -678,6 +702,11 @@ class Response implements ResponseInterface
      */
     public function header($header = null, $value = null)
     {
+        deprecationWarning(
+            'Response::header() is deprecated. ' .
+            'Use `withHeader()`, `getHeaderLine()` and `getHeaders()` instead.'
+        );
+
         if ($header === null) {
             return $this->getSimpleHeaders();
         }
@@ -739,6 +768,11 @@ class Response implements ResponseInterface
      */
     public function location($url = null)
     {
+        deprecationWarning(
+            'Response::location() is deprecated. ' .
+            'Mutable responses are deprecated. Use `withLocation()` and `getHeaderLine()` instead.'
+        );
+
         if ($url === null) {
             $result = $this->getHeaderLine('Location');
             if (!$result) {
@@ -814,6 +848,11 @@ class Response implements ResponseInterface
      */
     public function body($content = null)
     {
+        deprecationWarning(
+            'Response::body() is deprecated. ' .
+            'Mutable response methods are deprecated. Use `withBody()` and `getBody()` instead.'
+        );
+
         if ($content === null) {
             if ($this->stream->isSeekable()) {
                 $this->stream->rewind();
@@ -871,6 +910,11 @@ class Response implements ResponseInterface
      */
     public function statusCode($code = null)
     {
+        deprecationWarning(
+            'Response::statusCode() is deprecated. ' .
+            'Use `getStatusCode()` and `withStatus()` instead.'
+        );
+
         if ($code === null) {
             return $this->_status;
         }
@@ -987,6 +1031,8 @@ class Response implements ResponseInterface
      */
     public function httpCodes($code = null)
     {
+        deprecationWarning('Will be removed in 4.0.0');
+
         if (empty($code)) {
             return $this->_statusCodes;
         }
@@ -1046,6 +1092,11 @@ class Response implements ResponseInterface
      */
     public function type($contentType = null)
     {
+        deprecationWarning(
+            'Response::type() is deprecated. ' .
+            'Use getType() or withType() instead.'
+        );
+
         if ($contentType === null) {
             return $this->getType();
         }
@@ -1168,6 +1219,11 @@ class Response implements ResponseInterface
      */
     public function charset($charset = null)
     {
+        deprecationWarning(
+            'Response::charset() is deprecated. ' .
+            'Use getCharset()/withCharset() instead.'
+        );
+
         if ($charset === null) {
             return $this->_charset;
         }
@@ -1210,6 +1266,11 @@ class Response implements ResponseInterface
      */
     public function disableCache()
     {
+        deprecationWarning(
+            'Response::disableCache() is deprecated. ' .
+            'Use withDisabledCache() instead.'
+        );
+
         $this->_setHeader('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT');
         $this->_setHeader('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT');
         $this->_setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
@@ -1237,6 +1298,11 @@ class Response implements ResponseInterface
      */
     public function cache($since, $time = '+1 day')
     {
+        deprecationWarning(
+            'Response::cache() is deprecated. ' .
+            'Use withCache() instead.'
+        );
+
         if (!is_int($time)) {
             $time = strtotime($time);
         }
@@ -1427,6 +1493,11 @@ class Response implements ResponseInterface
      */
     public function mustRevalidate($enable = null)
     {
+        deprecationWarning(
+            'Response::mustRevalidate() is deprecated. ' .
+            'Use withMustRevalidate() instead.'
+        );
+
         if ($enable !== null) {
             if ($enable) {
                 $this->_cacheDirectives['must-revalidate'] = true;
@@ -1496,6 +1567,11 @@ class Response implements ResponseInterface
      */
     public function expires($time = null)
     {
+        deprecationWarning(
+            'Response::expires() is deprecated. ' .
+            'Use withExpires() instead.'
+        );
+
         if ($time !== null) {
             $date = $this->_getUTCDate($time);
             $this->_setHeader('Expires', $date->format('D, j M Y H:i:s') . ' GMT');
@@ -1547,6 +1623,11 @@ class Response implements ResponseInterface
      */
     public function modified($time = null)
     {
+        deprecationWarning(
+            'Response::modified() is deprecated. ' .
+            'Use withModified() instead.'
+        );
+
         if ($time !== null) {
             $date = $this->_getUTCDate($time);
             $this->_setHeader('Last-Modified', $date->format('D, j M Y H:i:s') . ' GMT');
@@ -1650,6 +1731,11 @@ class Response implements ResponseInterface
      */
     public function vary($cacheVariances = null)
     {
+        deprecationWarning(
+            'Response::vary() is deprecated. ' .
+            'Use withVary() instead.'
+        );
+
         if ($cacheVariances !== null) {
             $cacheVariances = (array)$cacheVariances;
             $this->_setHeader('Vary', implode(', ', $cacheVariances));
@@ -1702,6 +1788,11 @@ class Response implements ResponseInterface
      */
     public function etag($hash = null, $weak = false)
     {
+        deprecationWarning(
+            'Response::etag() is deprecated. ' .
+            'Use withEtag() instead.'
+        );
+
         if ($hash !== null) {
             $this->_setHeader('Etag', sprintf('%s"%s"', $weak ? 'W/' : null, $hash));
         }
@@ -1797,6 +1888,11 @@ class Response implements ResponseInterface
      */
     public function download($filename)
     {
+        deprecationWarning(
+            'Response::download() is deprecated. ' .
+            'Use withDownload() instead.'
+        );
+
         $this->header('Content-Disposition', 'attachment; filename="' . $filename . '"');
     }
 
@@ -1821,6 +1917,11 @@ class Response implements ResponseInterface
      */
     public function protocol($protocol = null)
     {
+        deprecationWarning(
+            'Response::protocol() is deprecated. ' .
+            'Use getProtocolVersion() instead.'
+        );
+
         if ($protocol !== null) {
             $this->_protocol = $protocol;
         }
@@ -1838,6 +1939,11 @@ class Response implements ResponseInterface
      */
     public function length($bytes = null)
     {
+        deprecationWarning(
+            'Response::length() is deprecated. ' .
+            'Use withLength() instead.'
+        );
+
         if ($bytes !== null) {
             $this->_setHeader('Content-Length', $bytes);
         }
@@ -1951,6 +2057,11 @@ class Response implements ResponseInterface
      */
     public function cookie($options = null)
     {
+        deprecationWarning(
+            'Response::cookie() is deprecated. ' .
+            'Use getCookie(), getCookies() and withCookie() instead.'
+        );
+
         if ($options === null) {
             return $this->getCookies();
         }
@@ -2256,6 +2367,11 @@ class Response implements ResponseInterface
      */
     public function file($path, array $options = [])
     {
+        deprecationWarning(
+            'Response::file() is deprecated. ' .
+            'Use withFile() instead.'
+        );
+
         $file = $this->validateFile($path);
         $options += [
             'name' => null,
@@ -2485,6 +2601,8 @@ class Response implements ResponseInterface
      */
     protected function _sendFile($file, $range)
     {
+        deprecationWarning('Will be removed in 4.0.0');
+
         ob_implicit_flush(true);
 
         $file->open('rb');
@@ -2528,6 +2646,8 @@ class Response implements ResponseInterface
      */
     protected function _isActive()
     {
+        deprecationWarning('Will be removed in 4.0.0');
+
         return connection_status() === CONNECTION_NORMAL && !connection_aborted();
     }
 
@@ -2539,6 +2659,10 @@ class Response implements ResponseInterface
      */
     protected function _clearBuffer()
     {
+        deprecationWarning(
+            'This function is not needed anymore and will be removed.'
+        );
+
         //@codingStandardsIgnoreStart
         return @ob_end_clean();
         //@codingStandardsIgnoreEnd
@@ -2552,6 +2676,10 @@ class Response implements ResponseInterface
      */
     protected function _flushBuffer()
     {
+        deprecationWarning(
+            'This function is not needed anymore and will be removed.'
+        );
+
         //@codingStandardsIgnoreStart
         @flush();
         if (ob_get_level()) {
@@ -2570,6 +2698,8 @@ class Response implements ResponseInterface
      */
     public function stop($status = 0)
     {
+        deprecationWarning('Will be removed in 4.0.0');
+
         exit($status);
     }
 

+ 85 - 0
src/Http/ServerRequest.php

@@ -229,6 +229,11 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
      */
     public static function createFromGlobals()
     {
+        deprecationWarning(
+            'ServerRequest::createFromGlobals() is deprecated. ' .
+            'Use `Cake\Http\ServerRequestFactory` instead.'
+        );
+
         return ServerRequestFactory::fromGlobals();
     }
 
@@ -535,6 +540,11 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
      */
     public function session(Session $session = null)
     {
+        deprecationWarning(
+            'ServerRequest::session() is deprecated. ' .
+            'Use getSession() instead. The setter part will be removed.'
+        );
+
         if ($session === null) {
             return $this->session;
         }
@@ -625,6 +635,11 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
      */
     public function __get($name)
     {
+        deprecationWarning(
+            'Accessing routing parameters through __get will removed in 4.0.0. ' .
+            'Use getParam() instead.'
+        );
+
         if (isset($this->params[$name])) {
             return $this->params[$name];
         }
@@ -643,6 +658,11 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
      */
     public function __isset($name)
     {
+        deprecationWarning(
+            'Accessing routing parameters through __isset will removed in 4.0.0. ' .
+            'Use getParam() instead.'
+        );
+
         return isset($this->params[$name]);
     }
 
@@ -935,6 +955,11 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
      */
     public function here($base = true)
     {
+        deprecationWarning(
+            'This method will be removed in 4.0.0. ' .
+            'This method will be removed in 4.0.0. You should use getRequestTarget() instead.'
+        );
+
         $url = $this->here;
         if (!empty($this->query)) {
             $url .= '?' . http_build_query($this->query, null, '&');
@@ -975,6 +1000,11 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
      */
     public function header($name)
     {
+        deprecationWarning(
+            'ServerRequest::header() is deprecated. ' .
+            'The automatic fallback to env() will be removed in 4.0.0, see getHeader()'
+        );
+
         $name = $this->normalizeHeaderName($name);
 
         return $this->getEnv($name);
@@ -1128,6 +1158,11 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
      */
     public function method()
     {
+        deprecationWarning(
+            'ServerRequest::method() is deprecated. ' .
+            'This method will be removed in 4.0.0. Use getMethod() instead.'
+        );
+
         return $this->getEnv('REQUEST_METHOD');
     }
 
@@ -1424,6 +1459,11 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
      */
     public function query($name = null)
     {
+        deprecationWarning(
+            'ServerRequest::query() is deprecated. ' .
+            'Use getQuery() or the PSR-7 getQueryParams() and withQueryParams() methods instead.'
+        );
+
         if ($name === null) {
             return $this->query;
         }
@@ -1485,6 +1525,11 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
      */
     public function data($name = null, ...$args)
     {
+        deprecationWarning(
+            'ServerRequest::data() is deprecated. ' .
+            'Use withData() and getData() or getParsedBody() instead.'
+        );
+
         if (count($args) === 1) {
             $this->data = Hash::insert($this->data, $name, $args[0]);
 
@@ -1543,6 +1588,11 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
      */
     public function param($name, ...$args)
     {
+        deprecationWarning(
+            'ServerRequest::param() is deprecated. ' .
+            'Use getParam() and withParam() instead.'
+        );
+
         if (count($args) === 1) {
             $this->params = Hash::insert($this->params, $name, $args[0]);
 
@@ -1598,6 +1648,11 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
      */
     public function cookie($key)
     {
+        deprecationWarning(
+            'ServerRequest::cookie() is deprecated. ' .
+            'Use getCookie() instead.'
+        );
+
         if (isset($this->cookies[$key])) {
             return $this->cookies[$key];
         }
@@ -1805,6 +1860,11 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
      */
     public function env($key, $value = null, $default = null)
     {
+        deprecationWarning(
+            'ServerRequest::env() is deprecated. ' .
+            'Use getEnv()/withEnv() instead.'
+        );
+
         if ($value !== null) {
             $this->_environment[$key] = $value;
             $this->clearDetectorCache();
@@ -1878,6 +1938,11 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
      */
     public function setInput($input)
     {
+        deprecationWarning(
+            'This method will be removed in 4.0.0.' .
+            'Use withBody() instead.'
+        );
+
         $stream = new Stream('php://memory', 'rw');
         $stream->write($input);
         $stream->rewind();
@@ -2196,6 +2261,11 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
      */
     public function offsetGet($name)
     {
+        deprecationWarning(
+            'The ArrayAccess methods will be removed in 4.0.0.' .
+            'Use getParam(), getData() and getQuery() instead.'
+        );
+
         if (isset($this->params[$name])) {
             return $this->params[$name];
         }
@@ -2219,6 +2289,11 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
      */
     public function offsetSet($name, $value)
     {
+        deprecationWarning(
+            'The ArrayAccess methods will be removed in 4.0.0.' .
+            'Use withParam() instead.'
+        );
+
         $this->params[$name] = $value;
     }
 
@@ -2231,6 +2306,11 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
      */
     public function offsetExists($name)
     {
+        deprecationWarning(
+            'The ArrayAccess methods will be removed in 4.0.0.' .
+            'Use getParam() instead.'
+        );
+
         if ($name === 'url' || $name === 'data') {
             return true;
         }
@@ -2247,6 +2327,11 @@ class ServerRequest implements ArrayAccess, ServerRequestInterface
      */
     public function offsetUnset($name)
     {
+        deprecationWarning(
+            'The ArrayAccess methods will be removed in 4.0.0.' .
+            'Use withParam() instead.'
+        );
+
         unset($this->params[$name]);
     }
 }