Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add CakeRequest::__isset()

Fixes #2266
  • Loading branch information...
commit 9c5ad71abc04be18841abbdcfcf711b3b3a07107 1 parent e5c8a44
@markstory markstory authored
View
11 lib/Cake/Network/CakeRequest.php
@@ -414,6 +414,17 @@ public function __get($name) {
}
/**
+ * 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
* as `is($type)` or `is$Type()`.
View
20 lib/Cake/Test/Case/Network/CakeRequestTest.php
@@ -683,6 +683,26 @@ public function test__get() {
}
/**
+ * 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
*
* @return void
Please sign in to comment.
Something went wrong with that request. Please try again.