Skip to content

Commit

Permalink
Add CakeRequest::__isset()
Browse files Browse the repository at this point in the history
Fixes #2266
  • Loading branch information
markstory committed Nov 17, 2011
1 parent e5c8a44 commit 9c5ad71
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/Cake/Network/CakeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,17 @@ public function __get($name) {
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
Expand Down
20 changes: 20 additions & 0 deletions lib/Cake/Test/Case/Network/CakeRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,26 @@ public function test__get() {
$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
*
Expand Down

0 comments on commit 9c5ad71

Please sign in to comment.