From 9c5ad71abc04be18841abbdcfcf711b3b3a07107 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 16 Nov 2011 20:20:50 -0500 Subject: [PATCH] Add CakeRequest::__isset() Fixes #2266 --- lib/Cake/Network/CakeRequest.php | 11 ++++++++++ .../Test/Case/Network/CakeRequestTest.php | 20 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index 2df0ac019..7da41879a 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -413,6 +413,17 @@ class CakeRequest implements ArrayAccess { return null; } +/** + * Magic isset method allows isset/empty checks + * on routing parameters. + * + * @param string $name The property being accessed. + * @return bool Existence + */ + public function __isset($name) { + return isset($this->params[$name]); + } + /** * Check whether or not a Request is a certain type. Uses the built in detection rules * as well as additional rules defined with CakeRequest::addDetector(). Any detector can be called diff --git a/lib/Cake/Test/Case/Network/CakeRequestTest.php b/lib/Cake/Test/Case/Network/CakeRequestTest.php index 6af42d745..dc21e80f9 100644 --- a/lib/Cake/Test/Case/Network/CakeRequestTest.php +++ b/lib/Cake/Test/Case/Network/CakeRequestTest.php @@ -682,6 +682,26 @@ class CakeRequestTest extends CakeTestCase { $this->assertIdentical($request->banana, null); } +/** + * Test isset()/empty() with overloaded properties. + * + * @return void + */ + public function test__isset() { + $request = new CakeRequest('some/path'); + $request->params = array( + 'controller' => 'posts', + 'action' => 'view', + 'plugin' => 'blogs', + 'named' => array() + ); + + $this->assertTrue(isset($request->controller)); + $this->assertFalse(isset($request->notthere)); + $this->assertFalse(empty($request->controller)); + $this->assertTrue(empty($request->named)); + } + /** * test the array access implementation *