src/EventSubscriber/SendSMS.php line 32

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