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