Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Making it possible to access name and subject directly on CakeEvent

  • Loading branch information...
commit 07d358d2cdd30b38b6fb5985a96c0f56984fd311 1 parent 32fe854
@lorenzo lorenzo authored
View
12 lib/Cake/Event/CakeEvent.php
@@ -76,6 +76,18 @@ public function __construct($name, $subject = null, $data = null) {
}
/**
+ * Dynamically returns the name and subject if accessed directly
+ *
+ * @param string $attribute
+ * @return mixed
+ */
+ public function __get($attribute) {
+ if ($attribute === 'name' || $attribute === 'subject') {
+ return $this->{$attribute}();
+ }
+ }
+
+/**
* Returns the name of this event. This is usually used as the event identifier
*
* @return string
View
11 lib/Cake/Test/Case/Event/CakeEventTest.php
@@ -71,4 +71,15 @@ public function testEventData() {
$event = new CakeEvent('fake.event', $this, array('some' => 'data'));
$this->assertEquals(array('some' => 'data'), $event->data);
}
+
+/**
+ * Tests that it is possible to get the name and subject directly
+ *
+ * @return void
+ */
+ public function testEventDirectPropertyAccess() {
+ $event = new CakeEvent('fake.event', $this);
+ $this->assertEquals($this, $event->subject);
+ $this->assertEquals('fake.event', $event->name);
+ }
}

0 comments on commit 07d358d

Please sign in to comment.
Something went wrong with that request. Please try again.