Skip to content

Commit 401f838

Browse files
committed
Look for magic event properties if it's an Arrayable class
resolves #2
1 parent f917a19 commit 401f838

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Release Notes for Webhooks for Craft CMS
22

3+
## Unreleased
4+
5+
### Changed
6+
- Webhook requests now include data for any magic event properties defined by `fields()`, if the event class implements `yii\base\Arrayable`. ([#2](https://github.com/craftcms/webhooks/issues/2))
7+
38
## 1.1.1 - 2018-12-17
49

510
### Added

src/Plugin.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ public function init()
7676
];
7777

7878
$eventAttributes = $webhook->getEventAttributes();
79-
foreach ((new \ReflectionObject($e))->getProperties() as $property) {
80-
if ($property->isPublic() && $property->getDeclaringClass()->getName() !== Event::class) {
81-
$name = $property->getName();
82-
$data['event'][$name] = $this->toArray($e->$name, $eventAttributes[$name] ?? []);
79+
$ref = new \ReflectionClass($e);
80+
foreach (ArrayHelper::toArray($e, [], false) as $name => $value) {
81+
if (!$ref->hasProperty($name) || $ref->getProperty($name)->getDeclaringClass()->getName() !== Event::class) {
82+
$data['event'][$name] = $this->toArray($value, $eventAttributes[$name] ?? []);
8383
}
8484
}
8585
}

0 commit comments

Comments
 (0)