mirror of
https://github.com/danog/TelegramApiServer.git
synced 2024-12-02 09:17:46 +01:00
Codestyle
This commit is contained in:
parent
89b90be411
commit
a9b118d5b2
@ -81,5 +81,8 @@ foreach ($options['session'] as $session) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$client = new TelegramApiServer\Client(array_keys($sessionFiles));
|
new TelegramApiServer\Server\Server(
|
||||||
new TelegramApiServer\Server\Server($client, $options);
|
new TelegramApiServer\Client(),
|
||||||
|
$options,
|
||||||
|
array_keys($sessionFiles)
|
||||||
|
);
|
@ -15,17 +15,6 @@ class Client
|
|||||||
public static string $sessionFolder = 'sessions';
|
public static string $sessionFolder = 'sessions';
|
||||||
/** @var MadelineProto\API[] */
|
/** @var MadelineProto\API[] */
|
||||||
public array $instances = [];
|
public array $instances = [];
|
||||||
private array $sessionsFiles;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Client constructor.
|
|
||||||
*
|
|
||||||
* @param array $sessions
|
|
||||||
*/
|
|
||||||
public function __construct(array $sessionsFiles)
|
|
||||||
{
|
|
||||||
$this->sessionsFiles = $sessionsFiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string|null $session
|
* @param string|null $session
|
||||||
@ -69,19 +58,19 @@ class Client
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function connect()
|
public function connect($sessionFiles)
|
||||||
{
|
{
|
||||||
//При каждой инициализации настройки обновляются из массива $config
|
//При каждой инициализации настройки обновляются из массива $config
|
||||||
echo PHP_EOL . 'Starting MadelineProto...' . PHP_EOL;
|
echo PHP_EOL . 'Starting MadelineProto...' . PHP_EOL;
|
||||||
$time = microtime(true);
|
$time = microtime(true);
|
||||||
|
|
||||||
foreach ($this->sessionsFiles as $file) {
|
foreach ($sessionFiles as $file) {
|
||||||
$session = static::getSessionName($file);
|
$session = static::getSessionName($file);
|
||||||
$this->addSession($session, true);
|
$this->addSession($session, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$time = round(microtime(true) - $time, 3);
|
$time = round(microtime(true) - $time, 3);
|
||||||
$sessionsCount = count($this->sessionsFiles);
|
$sessionsCount = count($sessionFiles);
|
||||||
|
|
||||||
echo
|
echo
|
||||||
"\nTelegramApiServer ready."
|
"\nTelegramApiServer ready."
|
||||||
@ -109,7 +98,8 @@ class Client
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeSession($session) {
|
public function removeSession($session)
|
||||||
|
{
|
||||||
if (empty($this->instances[$session])) {
|
if (empty($this->instances[$session])) {
|
||||||
throw new InvalidArgumentException('Instance not found');
|
throw new InvalidArgumentException('Instance not found');
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
namespace TelegramApiServer\Server;
|
namespace TelegramApiServer\Server;
|
||||||
|
|
||||||
use Amp;
|
use Amp;
|
||||||
use danog\MadelineProto\Tools;
|
|
||||||
use TelegramApiServer\Client;
|
use TelegramApiServer\Client;
|
||||||
use TelegramApiServer\Config;
|
use TelegramApiServer\Config;
|
||||||
use TelegramApiServer\Logger;
|
use TelegramApiServer\Logger;
|
||||||
@ -12,12 +11,14 @@ class Server
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Server constructor.
|
* Server constructor.
|
||||||
|
*
|
||||||
* @param Client $client
|
* @param Client $client
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
* @param array|null $sessionFiles
|
||||||
*/
|
*/
|
||||||
public function __construct(Client $client, array $options)
|
public function __construct(Client $client, array $options, ?array $sessionFiles)
|
||||||
{
|
{
|
||||||
Amp\Loop::run(function () use ($client, $options) {
|
Amp\Loop::run(function () use ($client, $options, $sessionFiles) {
|
||||||
$server = new Amp\Http\Server\Server(
|
$server = new Amp\Http\Server\Server(
|
||||||
$this->getServerAddresses(static::getConfig($options)),
|
$this->getServerAddresses(static::getConfig($options)),
|
||||||
(new Router($client))->getRouter(),
|
(new Router($client))->getRouter(),
|
||||||
@ -27,7 +28,7 @@ class Server
|
|||||||
->withBodySizeLimit(30*1024*1024)
|
->withBodySizeLimit(30*1024*1024)
|
||||||
);
|
);
|
||||||
|
|
||||||
$client->connect();
|
$client->connect($sessionFiles);
|
||||||
yield $server->start();
|
yield $server->start();
|
||||||
|
|
||||||
$this->registerShutdown($server);
|
$this->registerShutdown($server);
|
||||||
|
Loading…
Reference in New Issue
Block a user