Add CakeRequest::__isset()

Fixes #2266
This commit is contained in:
mark_story 2011-11-16 20:20:50 -05:00
parent e5c8a446d6
commit 9c5ad71abc
2 changed files with 31 additions and 0 deletions

View file

@ -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

View file

@ -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
*