> For the complete documentation index, see [llms.txt](https://akyos.gitbook.io/book/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://akyos.gitbook.io/book/symfony/events.md).

# Events

Symfony est composer d'une gestion d'évènements natifs qui permettent de se greffer où l'on veut et n'importe quand à condition que le dispatcher soit appelé.

Dans nos cas, il faut que l'on créé des évènements customs pour reprendre ce principe.

Quand vous voulez envoyer par exemple des notifications, passez déjà par un dispatcher pour ensuite écouter votre évènement afin d'envoyer cette dernière. Il se peut qu'à un autre endroit, vous auriez besoin de la renvoyer. Il vous suffira de rappeler votre dispatcher pour reprendre le cours des évènements et ne pas en oublier.&#x20;

```php
<?php

namespace App\Event\AppointmentEvent;

use App\Entity\Appointments;
use Symfony\Contracts\EventDispatcher\Event;

class RecallAppointmentEvent extends Event
{
    public function __construct(
        private Appointments $appoitment,
    ) {
    }

    public function getAppointment(): mixed
    {
        return $this->appoitment;
    }

    public function setAppointment(Appointments $appoitment)
    {
        $this->appoitment = $appoitment;
    }
}

```

```php
#[AsEventListener(event: RecallAppointmentEvent::class, method: 'onRecallAppointment')]
final class AppointmentEventListener
```

```php
<?php

namespace App\MessageHandler;

use App\Event\AppointmentEvent\RecallAppointmentEvent;
use App\Message\Minus1Recall;
use App\Repository\AppointmentsRepository;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;

#[AsMessageHandler]
final class Minus1RecallHandler
{
    public function __construct(private readonly AppointmentsRepository $appointmentsRepository, private readonly EventDispatcherInterface $eventDispatcher)
    {
    }

    public function __invoke(Minus1Recall $message)
    {
        $els = $this->appointmentsRepository->findBy(['appointmentDate' => (new \DateTime('now'))->modify('+1 day')]);

        foreach ($els as $el){
            $this->eventDispatcher->dispatch(new RecallAppointmentEvent($el));
        }
    }
}

```
