Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Webhook][RemoveEvent] Add a date to RemoteEvent #57691

Open
sylfabre opened this issue Jul 9, 2024 · 1 comment
Open

[Webhook][RemoveEvent] Add a date to RemoteEvent #57691

sylfabre opened this issue Jul 9, 2024 · 1 comment

Comments

@sylfabre
Copy link
Contributor

sylfabre commented Jul 9, 2024

Description

Hello

Some events extending RemoveEvent like AbstractMailerEvent add a DateTimeImmutable $date property.

Why is this date not part of the basic RemoveEvent?
I think it would make sense for an event to always have a date, wouldn't it?

Thanks!

Example

<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\RemoteEvent;

/**
 * @author Fabien Potencier <[email protected]>
 */
class RemoteEvent
{
    public function __construct(
        private readonly string $name,
        private readonly string $id,
        private readonly \DateTimeImmutable $date, /** NEW */
        private readonly array $payload,
    ) {
    }

    public function getName(): string
    {
        return $this->name;
    }

    public function getId(): string
    {
        return $this->id;
    }

     /** NEW */
    public function getDate(): \DateTimeImmutable
    {
        return $this->date;
    }

    public function getPayload(): array
    {
        return $this->payload;
    }
}

An alternative is to define a TimedRemoteEvent like the following one to use as a base wherever relevant (ex : AbstractMailerEvent)

<?php

class TimedRemoteEvent extends RemoteEvent
{
    public function __construct(
        string $name,
        string $id,
        private readonly \DateTimeImmutable $date,
        array $payload,
    ) {
		parent::__construct($name, $id, $payload);
    }

    public function getDate(): \DateTimeImmutable
    {
        return $this->date;
    }
}
@faizanakram99
Copy link
Contributor

in addition to date, maybe the payload should be object|array instead of just array, it is quite handy with serializable dtos as payload or domain events as payloads

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants