src/EventSubscriber/SendSMS.php line 30

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