Skip to content

Commit f532334

Browse files
committed
#1 reset object per default on send
Signed-off-by: scrummer <scrummer@gmx.ch>
1 parent b0847ec commit f532334

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/DiscordWebhookBundle/DependencyInjection/DiscordWebhookExtension.php

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function load(array $configs, ContainerBuilder $container): void
3030
->register(DiscordWebhook::class, DiscordWebhook::class)
3131
->setPublic(true)
3232
->setArgument('$url', $config['default_url'])
33+
->setArgument('$serviceName', DiscordWebhook::class)
3334
->addTag('discord_webhook.client', ['key' => DiscordWebhook::class]);
3435

3536
// configure the additional named clients
@@ -47,6 +48,7 @@ private function configureClients(array $config, ContainerBuilder $container, Fi
4748
->register($name, DiscordWebhook::class)
4849
->setPublic(true)
4950
->setArgument('$url', $clientConfig['webhook_url'])
51+
->setArgument('$serviceName', $name)
5052
->addMethodCall('setUsername', [$clientConfig['username']])
5153
->addMethodCall('setAvatar', [$clientConfig['avatar_url']])
5254
->addTag('discord_webhook.client', ['key' => $name]);

src/DiscordWebhookBundle/DiscordWebhook.php

+19-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,27 @@
1313
*/
1414
class DiscordWebhook extends Webhook
1515
{
16-
public function __construct(array|string $url = [])
16+
private string $serviceName;
17+
18+
public function __construct(array|string $url = [], string $serviceName = DiscordWebhook::class)
1719
{
1820
parent::__construct($url);
21+
22+
$this->serviceName = $serviceName;
23+
}
24+
25+
public function send(): bool
26+
{
27+
$status = parent::send(false);
28+
$ignoredFields = [];
29+
30+
if ($this->serviceName !== DiscordWebhook::class) {
31+
$ignoredFields = ['username', 'avatarUrl'];
32+
}
33+
34+
$this->reset($ignoredFields);
35+
36+
return $status;
1937
}
2038

2139
public function setUrl(string $webhook): void

0 commit comments

Comments
 (0)