mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Making it possible to access name and subject directly on CakeEvent
This commit is contained in:
parent
32fe854fab
commit
07d358d2cd
2 changed files with 23 additions and 0 deletions
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue