Skip to content

Commit

Permalink
#1 reset object per default on send
Browse files Browse the repository at this point in the history
Signed-off-by: scrummer <[email protected]>
  • Loading branch information
scrummer committed Jan 26, 2022
1 parent b0847ec commit f532334
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function load(array $configs, ContainerBuilder $container): void
->register(DiscordWebhook::class, DiscordWebhook::class)
->setPublic(true)
->setArgument('$url', $config['default_url'])
->setArgument('$serviceName', DiscordWebhook::class)
->addTag('discord_webhook.client', ['key' => DiscordWebhook::class]);

// configure the additional named clients
Expand All @@ -47,6 +48,7 @@ private function configureClients(array $config, ContainerBuilder $container, Fi
->register($name, DiscordWebhook::class)
->setPublic(true)
->setArgument('$url', $clientConfig['webhook_url'])
->setArgument('$serviceName', $name)
->addMethodCall('setUsername', [$clientConfig['username']])
->addMethodCall('setAvatar', [$clientConfig['avatar_url']])
->addTag('discord_webhook.client', ['key' => $name]);
Expand Down
20 changes: 19 additions & 1 deletion src/DiscordWebhookBundle/DiscordWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,27 @@
*/
class DiscordWebhook extends Webhook
{
public function __construct(array|string $url = [])
private string $serviceName;

public function __construct(array|string $url = [], string $serviceName = DiscordWebhook::class)
{
parent::__construct($url);

$this->serviceName = $serviceName;
}

public function send(): bool
{
$status = parent::send(false);
$ignoredFields = [];

if ($this->serviceName !== DiscordWebhook::class) {
$ignoredFields = ['username', 'avatarUrl'];
}

$this->reset($ignoredFields);

return $status;
}

public function setUrl(string $webhook): void
Expand Down

0 comments on commit f532334

Please sign in to comment.