Skip to content

Commit

Permalink
Codestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
xtrime-ru committed Jan 20, 2020
1 parent 89b90be commit a9b118d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
7 changes: 5 additions & 2 deletions server.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,8 @@
}
}

$client = new TelegramApiServer\Client(array_keys($sessionFiles));
new TelegramApiServer\Server\Server($client, $options);
new TelegramApiServer\Server\Server(
new TelegramApiServer\Client(),
$options,
array_keys($sessionFiles)
);
20 changes: 5 additions & 15 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -69,19 +58,19 @@ public static function checkOrCreateSessionFolder($session, $rootDir): void
}
}

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."
Expand Down Expand Up @@ -109,7 +98,8 @@ public function addSession(string $session, bool $startSession = false)
}
}

public function removeSession($session) {
public function removeSession($session)
{
if (empty($this->instances[$session])) {
throw new InvalidArgumentException('Instance not found');
}
Expand Down
9 changes: 5 additions & 4 deletions src/Server/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace TelegramApiServer\Server;

use Amp;
use danog\MadelineProto\Tools;
use TelegramApiServer\Client;
use TelegramApiServer\Config;
use TelegramApiServer\Logger;
Expand All @@ -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(),
Expand All @@ -27,7 +28,7 @@ public function __construct(Client $client, array $options)
->withBodySizeLimit(30*1024*1024)
);

$client->connect();
$client->connect($sessionFiles);
yield $server->start();

$this->registerShutdown($server);
Expand Down

0 comments on commit a9b118d

Please sign in to comment.