src/Library/PyTg/PyTgUtils.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\Library\PyTg;
  3. use App\Library\PyTg\PyTg;
  4. use Symfony\Component\HttpFoundation\RequestStack;
  5. use Symfony\Component\Routing\RouterInterface;
  6. class PyTgUtils
  7. {
  8.     /**
  9.      * @var PyTg
  10.      */
  11.     public $pyTg;
  12.     /**
  13.      * @var RequestStack
  14.      */
  15.     private $requestStack;
  16.     /**
  17.      * @var RouterInterface
  18.      */
  19.     private $router;
  20.     private $isInited false;
  21.     public function __construct(PyTg $pyTgRouterInterface $routerRequestStack $requestStack)
  22.     {
  23.         $this->pyTg $pyTg;
  24.         $this->requestStack $requestStack;
  25.         $this->router $router;
  26.     }
  27.     public function init($passErrorTextCallback$checkAuth true$redirectOnError true$phone$accountName,
  28.                          $pythonTelegramPath)
  29.     {
  30.         if ($this->isInited) {
  31.             return;
  32.         }
  33.         if ($checkAuth) {
  34.             if (!$phone && $this->requestStack->getCurrentRequest()->attributes->get('_route') != "telegram_client__auth") {
  35.                 $passErrorTextCallback("Необходимо выполнить вход");
  36.                 if ($redirectOnError) {
  37.                     header('Location: ' $this->router->generate("telegram_client__auth"));
  38.                     exit;
  39.                 }
  40.             }
  41.         }
  42.         $this->pyTg->setPythonTelegramPath($pythonTelegramPath);
  43.         $this->pyTg->setPhone($phone);
  44.         $this->pyTg->setAccountName($accountName);
  45.         $this->isInited true;
  46.     }
  47.     private function assertIsInited()
  48.     {
  49.         if (!$this->isInited) {
  50.             throw new \Exception("PyTgUtils not initialized");
  51.         }
  52.     }
  53.     public function setTechAdminAccount()
  54.     {
  55.         $this->pyTg->setPhone("+79226641140");
  56.         $this->pyTg->setAccountName("+79226641140");
  57.     }
  58.     public function setOAVAccount()
  59.     {
  60.         $this->pyTg->setPhone("+79536871054");
  61.         $this->pyTg->setAccountName("+79536871054");
  62.     }
  63. }