Making it possible to access name and subject directly on CakeEvent

This commit is contained in:
Jose Lorenzo Rodriguez 2011-12-24 19:57:59 -04:30
parent 32fe854fab
commit 07d358d2cd
2 changed files with 23 additions and 0 deletions

View file

@ -75,6 +75,18 @@ class CakeEvent {
$this->_subject = $subject;
}
/**
* 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
*

View file

@ -71,4 +71,15 @@ class CakeEventTest extends CakeTestCase {
$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);
}
}