<?php
namespace App\Library\PyTg;
use App\Library\PyTg\PyTg;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\RouterInterface;
class PyTgUtils
{
/**
* @var PyTg
*/
public $pyTg;
/**
* @var RequestStack
*/
private $requestStack;
/**
* @var RouterInterface
*/
private $router;
private $isInited = false;
public function __construct(PyTg $pyTg, RouterInterface $router, RequestStack $requestStack)
{
$this->pyTg = $pyTg;
$this->requestStack = $requestStack;
$this->router = $router;
}
public function init($passErrorTextCallback, $checkAuth = true, $redirectOnError = true, $phone, $accountName,
$pythonTelegramPath)
{
if ($this->isInited) {
return;
}
if ($checkAuth) {
if (!$phone && $this->requestStack->getCurrentRequest()->attributes->get('_route') != "telegram_client__auth") {
$passErrorTextCallback("Необходимо выполнить вход");
if ($redirectOnError) {
header('Location: ' . $this->router->generate("telegram_client__auth"));
exit;
}
}
}
$this->pyTg->setPythonTelegramPath($pythonTelegramPath);
$this->pyTg->setPhone($phone);
$this->pyTg->setAccountName($accountName);
$this->isInited = true;
}
private function assertIsInited()
{
if (!$this->isInited) {
throw new \Exception("PyTgUtils not initialized");
}
}
public function setTechAdminAccount()
{
$this->pyTg->setPhone("+79226641140");
$this->pyTg->setAccountName("+79226641140");
}
public function setOAVAccount()
{
$this->pyTg->setPhone("+79536871054");
$this->pyTg->setAccountName("+79536871054");
}
}