-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding ability to use classes as event handlers
- Loading branch information
Luke Watts
committed
Jun 15, 2019
1 parent
7aa7869
commit 86f8ccb
Showing
1 changed file
with
9 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,13 +165,12 @@ public static function __strictCall(string $class, string $method, array $additi | |
* __getMagicProperties | ||
* | ||
* Returns array of magic properties defined by annotation @property | ||
@author Luke Watts <[email protected]> | ||
* | ||
* @since 1.0.0 | ||
* @author Luke Watts <[email protected]> | ||
* | ||
* @since 1.0.0 | ||
* | ||
* @param string $class | ||
* | ||
* @return array of [name => bit mask] | ||
*/ | ||
public static function __getMagicProperties(string $class): array | ||
|
@@ -316,13 +315,15 @@ public static function __hasProperty(string $class, string $name) | |
*/ | ||
public function __call(string $name, array $args) | ||
{ | ||
$class = get_class($this); | ||
$class = get_class($this); | ||
|
||
// calling event handlers | ||
if (self::__isEventProperty($class, $name)) { | ||
if (is_iterable($this->$name)) { | ||
foreach ($this->$name as $handler) { | ||
$handler(...$args); | ||
if ($handler !== null) { | ||
$handler(...$args); | ||
} | ||
} | ||
} elseif ($this->$name !== null) { | ||
throw new \Error("Property $class::$$name must be iterable or null, " . gettype($this->$name) . ' given.'); | ||
|
@@ -399,7 +400,7 @@ public function &__get(string $name) | |
*/ | ||
public function __set(string $name, $value) | ||
{ | ||
$class = get_class($this); | ||
$class = get_class($this); | ||
|
||
if (self::__hasProperty($class, $name)) { | ||
$this->$name = $value; | ||
|