src/EventSubscriber/SendSMS.php line 29

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 App\Env;
  11. use Symfony\Component\Security\Core\Security;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. /** @package App\EventSubscriber */
  14. class SendSMS implements EventSubscriberInterface
  15. {
  16.     private Cart $Cart;
  17.     private Auth $Auth;
  18.     public function __construct(private AppDTO $appCart $CartAuth $AuthSecurity $security)
  19.     {
  20.         $this->Cart $Cart;    
  21.         $this->Auth $Auth;
  22.         $this->Auth->setUser($security->getUser());
  23.     }
  24.     public function onOrderMaked(OrderMakedEvent $event): void
  25.     {
  26.         if (Env::site() != Env::DOM && Env::site() != Env::OPT) {
  27.             return;
  28.         }
  29.         
  30.         $order $event->getOrder();        
  31.         
  32.         SmsFactory::factory($this->app->sett->get('smsprovider'))
  33.             ->send(
  34.                 Func::mkphone($order->getPhone()),
  35.                 '',
  36.                 Func::mess_from_tmp($this->app->templates->get('order_maked_sms'),
  37.                 ['order_id' => $order->getId()])
  38.             );
  39.     }
  40.     public static function getSubscribedEvents(): array
  41.     {
  42.         return [
  43.             OrderMakedEvent::NAME => 'onOrderMaked',
  44.         ];
  45.     }
  46. }