src/SMS/EventListener/SmsLogListener.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\SMS\EventListener;
  3. use App\SMS\Event\SmsEvent;
  4. use Psr\Log\LoggerInterface;
  5. class SmsLogListener
  6. {
  7.     public function __construct(private readonly LoggerInterface $logger)
  8.     {
  9.     }
  10.     /**
  11.      * Called after a "message" is sent.
  12.      */
  13.     public function onSentSms(SmsEvent $event): void
  14.     {
  15.         $data $event->getData();
  16.         $log sprintf(
  17.             'Credit cost: %s | (%d) Success: %s | (%d) Failed: %s',
  18.             $data['totalCreditsRemoved'],
  19.             count($data['validReceivers']),
  20.             implode(', '$data['validReceivers']),
  21.             count($data['invalidReceivers']),
  22.             implode(', '$data['invalidReceivers'])
  23.         );
  24.         $this->logger->info($log);
  25.     }
  26. }