-
Notifications
You must be signed in to change notification settings - Fork 519
Open
Description
Sometimes I have some trouble debugging Vich events. So today I tried to add a logger:
<?php
namespace App\EventListener;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Vich\UploaderBundle\Event\Event;
use Vich\UploaderBundle\Event\Events;
final readonly class VichUploaderListener
{
public function __construct(private LoggerInterface $logger)
{
}
#[AsEventListener(Events::PRE_UPLOAD)]
#[AsEventListener(Events::POST_UPLOAD)]
// TODO add more events...
public function __invoke(Event $event): void
{
$object = $event->getObject();
$mapping = $event->getMapping();
$message = sprintf('"%s" {mapping} {object}', $event::class);
$this->logger->info($message, ['object' => $object, 'mapping' => $mapping]);
}
}I was wondering if it could be useful in the bundle itself.
I can spot some improvements already: limit to the dev environment, maybe use a dedicated "vich" channel.