Skip to content

Commit

Permalink
Merge pull request #12597 from cakephp/3.next-requesthandler
Browse files Browse the repository at this point in the history
Deprecate RequestHandler's wrapper methods.
  • Loading branch information
ADmad committed Sep 27, 2018
2 parents 792e307 + b2f4ea6 commit edc1934
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 14 deletions.
34 changes: 33 additions & 1 deletion src/Controller/Component/RequestHandlerComponent.php
Expand Up @@ -49,6 +49,8 @@ class RequestHandlerComponent extends Component
/**
* Contains the file extension parsed out by the Router
*
* Deprecated as of 3.7.0. This property will be made protected in 4.0.0.
*
* @var string|null
* @see \Cake\Routing\Router::extensions()
*/
Expand Down Expand Up @@ -354,29 +356,44 @@ public function beforeRender(Event $event)
* Returns true if the current call accepts an XML response, false otherwise
*
* @return bool True if client accepts an XML response
* @deprecated 3.7.0 Use RequestHandler::prefers('xml') instead.
*/
public function isXml()
{
deprecationWarning(
'RequestHandlerComponent::isXml() is deprecated. Use RequestHandlerComponent::prefers(\'xml\') instead.'
);

return $this->prefers('xml');
}

/**
* Returns true if the current call accepts an RSS response, false otherwise
*
* @return bool True if client accepts an RSS response
* @deprecated 3.7.0 Use RequestHandler::prefers('rss') instead.
*/
public function isRss()
{
deprecationWarning(
'RequestHandlerComponent::isRss() is deprecated. Use RequestHandlerComponent::prefers(\'rss\') instead.'
);

return $this->prefers('rss');
}

/**
* Returns true if the current call accepts an Atom response, false otherwise
*
* @return bool True if client accepts an RSS response
* @return bool True if client accepts an Atom response
* @deprecated 3.7.0 Use RequestHandler::prefers('atom') instead.
*/
public function isAtom()
{
deprecationWarning(
'RequestHandlerComponent::isAtom() is deprecated. Use RequestHandlerComponent::prefers(\'atom\') instead.'
);

return $this->prefers('atom');
}

Expand All @@ -385,9 +402,14 @@ public function isAtom()
* client accepts WAP content.
*
* @return bool True if user agent is a mobile web browser
* @deprecated 3.7.0 Use ServerRequest::is('mobile') instead.
*/
public function isMobile()
{
deprecationWarning(
'RequestHandlerComponent::isMobile() is deprecated. Use ServerRequest::is(\'mobile\') instead.'
);

$request = $this->getController()->getRequest();

return $request->is('mobile') || $this->accepts('wap');
Expand All @@ -397,9 +419,14 @@ public function isMobile()
* Returns true if the client accepts WAP content
*
* @return bool
* @deprecated 3.7.0 Use RequestHandler::prefers('wap') instead.
*/
public function isWap()
{
deprecationWarning(
'RequestHandlerComponent::isWap() is deprecated. Use RequestHandlerComponent::prefers(\'wap\') instead.'
);

return $this->prefers('wap');
}

Expand Down Expand Up @@ -679,9 +706,14 @@ public function respondAs($type, array $options = [])
*
* @return mixed A string content type alias, or raw content type if no alias map exists,
* otherwise null
* @deprecated 3.7.0 Use $response->mapType($response->getType()) instead.
*/
public function responseType()
{
deprecationWarning(
'RequestHandlerComponent::responseType() is deprecated. Use $response->mapType($response->getType()) instead.'
);

$response = $this->getController()->response;

return $response->mapType($response->getType());
Expand Down
40 changes: 27 additions & 13 deletions tests/TestCase/Controller/Component/RequestHandlerComponentTest.php
Expand Up @@ -970,30 +970,40 @@ public function testRequestContentTypes()
'Accept',
'text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*'
);
$this->assertTrue($this->RequestHandler->isXml());
$this->assertFalse($this->RequestHandler->isAtom());
$this->assertFalse($this->RequestHandler->isRSS());
$this->deprecated(function () {
$this->assertTrue($this->RequestHandler->isXml());
$this->assertFalse($this->RequestHandler->isAtom());
$this->assertFalse($this->RequestHandler->isRSS());
});

$this->Controller->request = $this->request->withHeader(
'Accept',
'application/atom+xml,text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*'
);
$this->assertTrue($this->RequestHandler->isAtom());
$this->assertFalse($this->RequestHandler->isRSS());
$this->deprecated(function () {
$this->assertTrue($this->RequestHandler->isAtom());
$this->assertFalse($this->RequestHandler->isRSS());
});

$this->Controller->request = $this->request->withHeader(
'Accept',
'application/rss+xml,text/xml,application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*'
);
$this->assertFalse($this->RequestHandler->isAtom());
$this->assertTrue($this->RequestHandler->isRSS());
$this->deprecated(function () {
$this->assertFalse($this->RequestHandler->isAtom());
$this->assertTrue($this->RequestHandler->isRSS());
});

$this->assertFalse($this->RequestHandler->isWap());
$this->deprecated(function () {
$this->assertFalse($this->RequestHandler->isWap());
});
$this->Controller->request = $this->request->withHeader(
'Accept',
'text/vnd.wap.wml,text/html,text/plain,image/png,*/*'
);
$this->assertTrue($this->RequestHandler->isWap());
$this->deprecated(function () {
$this->assertTrue($this->RequestHandler->isWap());
});
}

/**
Expand All @@ -1003,9 +1013,11 @@ public function testRequestContentTypes()
*/
public function testResponseContentType()
{
$this->assertEquals('html', $this->RequestHandler->responseType());
$this->assertTrue($this->RequestHandler->respondAs('atom'));
$this->assertEquals('atom', $this->RequestHandler->responseType());
$this->deprecated(function () {
$this->assertEquals('html', $this->RequestHandler->responseType());
$this->assertTrue($this->RequestHandler->respondAs('atom'));
$this->assertEquals('atom', $this->RequestHandler->responseType());
});
}

/**
Expand All @@ -1023,7 +1035,9 @@ public function testMobileDeviceDetection()
->will($this->returnValue(true));

$this->Controller->request = $request;
$this->assertTrue($this->RequestHandler->isMobile());
$this->deprecated(function () {
$this->assertTrue($this->RequestHandler->isMobile());
});
}

/**
Expand Down

0 comments on commit edc1934

Please sign in to comment.