Small cleanups
This commit is contained in:
parent
a545e3463e
commit
ec2719db4e
@ -48,7 +48,8 @@
|
||||
"amphp/websocket": "dev-master as 1",
|
||||
"ext-ctype": "*",
|
||||
"danog/7to70": "^1",
|
||||
"danog/7to5": "^1"
|
||||
"danog/7to5": "^1",
|
||||
"vimeo/psalm": "dev-master"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-libtgvoip": "Install the php-libtgvoip extension to make phone calls (https://github.com/danog/php-libtgvoip)"
|
||||
@ -64,7 +65,6 @@
|
||||
"files": [
|
||||
"src/BigIntegor.php",
|
||||
"src/YieldReturnValue.php",
|
||||
"src/ReflectionGenerator.php",
|
||||
"src/polyfill.php"
|
||||
]
|
||||
},
|
||||
|
@ -140,7 +140,6 @@ class API extends InternalDoc
|
||||
if (isset($this->API)) {
|
||||
$this->storage = $this->API->storage ?? $this->storage;
|
||||
|
||||
$unserialized->oldInstance = true;
|
||||
unset($unserialized);
|
||||
|
||||
yield from $this->API->initAsynchronously();
|
||||
@ -165,6 +164,15 @@ class API extends InternalDoc
|
||||
$this->logger->logger(Lang::$current_lang['madelineproto_ready'], Logger::NOTICE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wakeup function.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __wakeup(): void
|
||||
{
|
||||
$this->oldInstance = true;
|
||||
}
|
||||
/**
|
||||
* Destruct function.
|
||||
*
|
||||
@ -248,7 +256,7 @@ class API extends InternalDoc
|
||||
$promises = [];
|
||||
foreach ($instances as $k => $instance) {
|
||||
$instance->start(['async' => false]);
|
||||
$promises []= Tools::call($instance->startAndLoopAsync($eventHandler[$k]));
|
||||
$promises []= $instance->startAndLoopAsync($eventHandler[$k]);
|
||||
}
|
||||
Tools::wait(Tools::all($promises));
|
||||
return;
|
||||
|
@ -153,8 +153,10 @@ class DoHConnector implements Connector
|
||||
}
|
||||
return ResourceSocket::fromClientSocket($socket, $socketContext->getTlsContext());
|
||||
}
|
||||
|
||||
// This is reached if either all URIs failed or the maximum number of attempts is reached.
|
||||
/** @noinspection PhpUndefinedVariableInspection */
|
||||
|
||||
throw $e;
|
||||
})());
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ trait CallHandler
|
||||
* @param array $args Arguments
|
||||
* @param array $aargs Additional arguments
|
||||
*
|
||||
* @return Generator
|
||||
* @return \Generator
|
||||
*/
|
||||
public function methodCallAsyncWrite(string $method, $args = [], array $aargs = ['msg_id' => null]): \Generator
|
||||
{
|
||||
|
@ -17,11 +17,68 @@
|
||||
* @link https://docs.madelineproto.xyz MadelineProto documentation
|
||||
*/
|
||||
|
||||
namespace danog\MadelineProto\MTProtoSession;
|
||||
|
||||
use danog\MadelineProto\MTProtoSession\MsgIdHandler\MsgIdHandler32;
|
||||
use danog\MadelineProto\MTProtoSession\MsgIdHandler\MsgIdHandler64;
|
||||
|
||||
if (PHP_INT_SIZE === 8) {
|
||||
\class_alias(MsgIdHandler64::class, \danog\MadelineProto\MTProtoSession\MsgIdHandler::class);
|
||||
} else {
|
||||
\class_alias(MsgIdHandler32::class, \danog\MadelineProto\MTProtoSession\MsgIdHandler::class);
|
||||
/**
|
||||
* Manages message ids.
|
||||
*/
|
||||
abstract class MsgIdHandler
|
||||
{
|
||||
/**
|
||||
* Session instance.
|
||||
*
|
||||
* @var Session
|
||||
*/
|
||||
protected $session;
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Session $session Session
|
||||
*/
|
||||
private function __construct(Session $session)
|
||||
{
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create MsgIdHandler instance.
|
||||
*
|
||||
* @param Session $session Session
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function createInstance(Session $session): self
|
||||
{
|
||||
if (PHP_INT_SIZE === 8) {
|
||||
return new MsgIdHandler64($session);
|
||||
}
|
||||
return new MsgIdHandler32($session);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check validity of given message ID.
|
||||
*
|
||||
* @param string $newMessageId New message ID
|
||||
* @param array $aargs Params
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract public function checkMessageId($newMessageId, array $aargs): void;
|
||||
/**
|
||||
* Generate outgoing message ID.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function generateMessageId(): string;
|
||||
/**
|
||||
* Get maximum message ID.
|
||||
*
|
||||
* @param boolean $incoming Incoming or outgoing message ID
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function getMaxId(bool $incoming);
|
||||
}
|
||||
|
@ -19,12 +19,12 @@
|
||||
|
||||
namespace danog\MadelineProto\MTProtoSession\MsgIdHandler;
|
||||
|
||||
use danog\MadelineProto\MTProtoSession\MsgIdHandlerAbstract;
|
||||
use danog\MadelineProto\MTProtoSession\MsgIdHandler;
|
||||
|
||||
/**
|
||||
* Manages message ids.
|
||||
*/
|
||||
class MsgIdHandler32 extends MsgIdHandlerAbstract
|
||||
class MsgIdHandler32 extends MsgIdHandler
|
||||
{
|
||||
/**
|
||||
* Maximum incoming ID.
|
||||
|
@ -19,13 +19,13 @@
|
||||
|
||||
namespace danog\MadelineProto\MTProtoSession\MsgIdHandler;
|
||||
|
||||
use danog\MadelineProto\MTProtoSession\MsgIdHandlerAbstract;
|
||||
use danog\MadelineProto\MTProtoSession\MsgIdHandler;
|
||||
use danog\MadelineProto\Tools;
|
||||
|
||||
/**
|
||||
* Manages message ids.
|
||||
*/
|
||||
class MsgIdHandler64 extends MsgIdHandlerAbstract
|
||||
class MsgIdHandler64 extends MsgIdHandler
|
||||
{
|
||||
/**
|
||||
* Maximum incoming ID.
|
||||
|
@ -1,66 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* MsgIdHandler module.
|
||||
*
|
||||
* This file is part of MadelineProto.
|
||||
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Affero General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License along with MadelineProto.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author Daniil Gentili <daniil@daniil.it>
|
||||
* @copyright 2016-2020 Daniil Gentili <daniil@daniil.it>
|
||||
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
|
||||
*
|
||||
* @link https://docs.madelineproto.xyz MadelineProto documentation
|
||||
*/
|
||||
|
||||
namespace danog\MadelineProto\MTProtoSession;
|
||||
|
||||
/**
|
||||
* Manages message ids.
|
||||
*/
|
||||
abstract class MsgIdHandlerAbstract
|
||||
{
|
||||
/**
|
||||
* Session instance.
|
||||
*
|
||||
* @var Session
|
||||
*/
|
||||
protected $session;
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Session $session Session
|
||||
*/
|
||||
public function __construct(Session $session)
|
||||
{
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check validity of given message ID.
|
||||
*
|
||||
* @param string $newMessageId New message ID
|
||||
* @param array $aargs Params
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract public function checkMessageId($newMessageId, array $aargs): void;
|
||||
/**
|
||||
* Generate outgoing message ID.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function generateMessageId(): string;
|
||||
/**
|
||||
* Get maximum message ID.
|
||||
*
|
||||
* @param boolean $incoming Incoming or outgoing message ID
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function getMaxId(bool $incoming);
|
||||
}
|
@ -53,7 +53,7 @@ abstract class Session
|
||||
$this->session_id = \danog\MadelineProto\Tools::random(8);
|
||||
$this->session_in_seq_no = 0;
|
||||
$this->session_out_seq_no = 0;
|
||||
$this->msgIdHandler = new MsgIdHandler($this);
|
||||
$this->msgIdHandler = MsgIdHandler::createInstance($this);
|
||||
}
|
||||
/**
|
||||
* Create MTProto session if needed.
|
||||
|
@ -27,6 +27,12 @@ use function Amp\File\get;
|
||||
*/
|
||||
class Serialization
|
||||
{
|
||||
/**
|
||||
* List of session paths.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $paths = [];
|
||||
/**
|
||||
* Extract path components for serialization.
|
||||
*
|
||||
@ -60,7 +66,7 @@ class Serialization
|
||||
} finally {
|
||||
$unlock();
|
||||
}
|
||||
\danog\MadelineProto\Magic::classExists();
|
||||
Magic::classExists();
|
||||
try {
|
||||
$unserialized = \unserialize($tounserialize);
|
||||
} catch (\danog\MadelineProto\Bug74586Exception $e) {
|
||||
|
Loading…
Reference in New Issue
Block a user