Codestyle

This commit is contained in:
Alexander Pankratov 2020-01-20 04:38:14 +03:00
parent 89b90be411
commit a9b118d5b2
3 changed files with 15 additions and 21 deletions

View File

@ -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)
);

View File

@ -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');
}

View File

@ -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);