src/EventSubscriber/SendSMS.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Func;
  4. use App\DTO\AppDTO;
  5. use App\Service\Auth\Auth;
  6. use App\Service\Cart\Cart;
  7. use App\Event\OrderMakedEvent;
  8. use App\Service\Sms\SmsFactory;
  9. use App\Entity\Cart as EntityCart;
  10. use Symfony\Component\Security\Core\Security;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. /** @package App\EventSubscriber */
  13. class SendSMS implements EventSubscriberInterface
  14. {
  15.     private Cart $Cart;
  16.     private Auth $Auth;
  17.     public function __construct(private AppDTO $appCart $CartAuth $AuthSecurity $security)
  18.     {
  19.         $this->Cart $Cart;    
  20.         $this->Auth $Auth;
  21.         $this->Auth->setUser($security->getUser());
  22.     }
  23.     public function onOrderMaked(OrderMakedEvent $event): void
  24.     {
  25.         $order $event->getOrder();        
  26.         
  27.         SmsFactory::factory($this->app->sett->get('smsprovider'))
  28.             ->send(
  29.                 Func::mkphone($order->getPhone()),
  30.                 '',
  31.                 "Message! ".Func::mess_from_tmp($this->app->templates->get('order_maked_sms'),
  32.                 ['order_id' => $order->getId()])
  33.             );
  34.     }
  35.     public static function getSubscribedEvents(): array
  36.     {
  37.         return [
  38.             OrderMakedEvent::NAME => 'onOrderMaked',
  39.         ];
  40.     }
  41. }