Skip to content

Commit b701f2e

Browse files
committed
feat(Utils): Enhance configuration application logic
- Introduce a flag to track if configuration was applied successfully - Implement logic to apply configuration to object methods or properties - Ensure better control flow for configuration application based on method or property existence
1 parent 10403ca commit b701f2e

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# laravel-exception-notify
22

3+
<p align="center"><img src="docs/ntfy.jpg" width="61.8%" alt="usage" title="usage"></p>
4+
35
> Monitor exception and report to the notification channels(Dump、Log、Mail、AnPush、Bark、Chanify、DingTalk、Discord、Gitter、GoogleChat、IGot、Lark、Mattermost、MicrosoftTeams、NowPush、Ntfy、Push、Pushback、PushBullet、PushDeer、PushMe、Pushover、PushPlus、QQ、RocketChat、ServerChan、ShowdocPush、SimplePush、Slack、Telegram、WeWork、WPush、XiZhi、YiFengChuanHua、Zulip).
46
57
[![tests](https://github.com/guanguans/laravel-exception-notify/workflows/tests/badge.svg)](https://github.com/guanguans/laravel-exception-notify/actions)
@@ -57,10 +59,10 @@ EXCEPTION_NOTIFY_WEWORK_TOKEN=73a3d5a3-ceff-4da8-bcf3-ff5891778
5759
php artisan exception-notify:test --ansi -v
5860
```
5961

60-
### Notification examples
62+
### :camera_flash: Notification examples
6163

6264
<details>
63-
<summary>details</summary>
65+
<summary>:monocle_face: details</summary>
6466

6567
| discord | slack | telegram |
6668
|:----------------------------:|:------------------------:|:------------------------------:|

docs/ntfy.jpg

494 KB
Loading

rector.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
->withSkip([
8686
'**/__snapshots__/*',
8787
'**/Fixtures/*',
88-
__DIR__.'/src/Channels/Channel.php',
88+
__DIR__.'/src/Support/Utils.php',
8989
__FILE__,
9090
])
9191
->withCache(__DIR__.'/.build/rector/')

src/Support/Utils.php

+25
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public static function applyConfigurationToObject(object $object, array $configu
4040
->all()
4141
)
4242
->each(static function (mixed $value, string $key) use ($object): void {
43+
$hasApplied = false;
44+
45+
// Apply configuration to object by method
4346
foreach (
4447
[
4548
static fn (string $key): string => $key,
@@ -56,6 +59,28 @@ public static function applyConfigurationToObject(object $object, array $configu
5659
}
5760

5861
1 === $numberOfParameters ? $object->{$method}($value) : app()->call([$object, $method], $value);
62+
$hasApplied = true;
63+
64+
break;
65+
}
66+
}
67+
68+
if ($hasApplied) {
69+
return;
70+
}
71+
72+
// Apply configuration to object by property
73+
foreach (
74+
[
75+
static fn (string $key): string => $key,
76+
static fn (string $key): string => Str::camel($key),
77+
] as $caster
78+
) {
79+
if (
80+
property_exists($object, $property = $caster($key))
81+
&& with(new \ReflectionProperty($object, $property))->isPublic()
82+
) {
83+
$object->{$key} = $value;
5984

6085
return;
6186
}

tests/Support/UtilsTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
new ReportExceptionMail($this->faker()->title(), $this->faker()->text()),
2929
[
3030
'render' => 'value',
31+
'theme' => 'default',
3132
'extender' => MailableExtender::class,
3233
]
3334
))->toBeInstanceOf(ReportExceptionMail::class);

0 commit comments

Comments
 (0)