Skip to content

Commit

Permalink
Adding deprecation warning for the Http package
Browse files Browse the repository at this point in the history
  • Loading branch information
burzum authored and markstory committed Nov 16, 2017
1 parent aad65a0 commit 9adee92
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Http/ActionDispatcher.php
Expand Up @@ -149,6 +149,11 @@ protected function _invoke(Controller $controller)
*/
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);
}
Expand Down
10 changes: 10 additions & 0 deletions src/Http/Client/CookieCollection.php
Expand Up @@ -27,6 +27,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.
*
Expand Down
5 changes: 5 additions & 0 deletions src/Http/Client/Message.php
Expand Up @@ -151,6 +151,11 @@ class Message
*/
public function headers()
{
deprecationWarning(
'Message::headers() is deprecated. ' .
'Use getHeaders() instead.'
);

return $this->headers;
}

Expand Down
27 changes: 27 additions & 0 deletions src/Http/Client/Request.php
Expand Up @@ -64,6 +64,11 @@ public function __construct($url = '', $method = self::METHOD_GET, array $header
*/
public function method($method = null)
{
deprecationWarning(
'Request::method() is deprecated. ' .
'Use getMethod() and withMethod() instead.'
);

if ($method === null) {
return $this->method;
}
Expand All @@ -88,6 +93,11 @@ public function method($method = null)
*/
public function url($url = null)
{
deprecationWarning(
'Request::url() is deprecated. ' .
'Use getUri() and withUri() instead.'
);

if ($url === null) {
return '' . $this->getUri();
}
Expand Down Expand Up @@ -130,6 +140,11 @@ public function url($url = null)
*/
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 === '') {
Expand Down Expand Up @@ -192,6 +207,13 @@ protected function addHeaders(array $headers)
*/
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;
}
Expand All @@ -217,6 +239,11 @@ public function cookie($name, $value = null)
*/
public function version($version = null)
{
deprecationWarning(
'Request::version() is deprecated. ' .
'Use getProtocolVersion() and withProtocolVersion() instead.'
);

if ($version === null) {
return $this->protocol;
}
Expand Down
25 changes: 25 additions & 0 deletions src/Http/Client/Response.php
Expand Up @@ -270,6 +270,11 @@ public function isRedirect()
*/
public function statusCode()
{
deprecationWarning(
'Response::statusCode() is deprecated. ' .
'Use Response::getStatusCode() instead.'
);

return $this->code;
}

Expand Down Expand Up @@ -317,6 +322,11 @@ public function getReasonPhrase()
*/
public function encoding()
{
deprecationWarning(
'Response::encoding() is deprecated. ' .
'Use Response::getEncoding() instead.'
);

return $this->getEncoding();
}

Expand Down Expand Up @@ -352,6 +362,11 @@ public function getEncoding()
*/
public function header($name = null)
{
deprecationWarning(
'Response::header() is deprecated. ' .
'Use Response::getHeader() and getHeaderLine() instead.'
);

if ($name === null) {
return $this->_getHeaders();
}
Expand Down Expand Up @@ -379,6 +394,11 @@ public function header($name = null)
*/
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();
}
Expand Down Expand Up @@ -509,6 +529,11 @@ protected function _getCookies()
*/
public function version()
{
deprecationWarning(
'Response::version() is deprecated. ' .
'Use Response::getProtocolVersion() instead.'
);

return $this->protocol;
}

Expand Down

0 comments on commit 9adee92

Please sign in to comment.