Apply fixes from StyleCI
This commit is contained in:
parent
e9dc0ba6f6
commit
9f428b3e4c
|
@ -171,7 +171,7 @@ if (!extension_loaded('pthreads')) {
|
|||
public function accept()
|
||||
{
|
||||
if ($socket = socket_accept($this->sock)) {
|
||||
return new SocketBase($socket);
|
||||
return new self($socket);
|
||||
} else {
|
||||
return $socket;
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ class Server
|
|||
$this->sock->setOption(\SOL_SOCKET, \SO_SNDTIMEO, $timeout);
|
||||
while (true) {
|
||||
pcntl_signal_dispatch();
|
||||
|
||||
try {
|
||||
if ($sock = $this->sock->accept()) {
|
||||
$this->handle($sock);
|
||||
|
@ -52,6 +53,7 @@ class Server
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function handle($socket)
|
||||
{
|
||||
$pid = pcntl_fork();
|
||||
|
@ -72,6 +74,7 @@ class Server
|
|||
foreach ($this->pids as $pid) {
|
||||
pcntl_wait($pid);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
\danog\MadelineProto\Logger::log('Shutting fork '.getmypid().' down');
|
||||
|
|
|
@ -29,24 +29,32 @@ class Handler extends \danog\MadelineProto\Connection
|
|||
$this->protocol = $protocol;
|
||||
$this->construct_TL(['socket' => __DIR__.'/../TL_socket.tl']);
|
||||
}
|
||||
public function __destruct() {
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
unset($this->sock);
|
||||
$this->destruct_madeline();
|
||||
exit();
|
||||
}
|
||||
public function destruct_madeline() {
|
||||
|
||||
public function destruct_madeline()
|
||||
{
|
||||
if ($this->madeline !== null) {
|
||||
$this->madeline->settings['logger'] = ['logger' => 0];
|
||||
$this->madeline->serialize();
|
||||
unset($this->madeline);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function loop()
|
||||
{
|
||||
while (true) {
|
||||
$request_id = 0;
|
||||
|
||||
try {
|
||||
$message = $this->read_message();
|
||||
} catch (\danog\MadelineProto\NothingInTheSocketException $e) {
|
||||
|
@ -55,6 +63,7 @@ class Handler extends \danog\MadelineProto\Connection
|
|||
if ($message === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$message = $this->deserialize($message, ['type' => '', 'datacenter' => '']);
|
||||
if ($message['_'] !== 'socketMessageRequest') {
|
||||
|
@ -75,10 +84,11 @@ class Handler extends \danog\MadelineProto\Connection
|
|||
$this->send_exception($request_id, $e);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
public function on_request($method, $args) {
|
||||
public function on_request($method, $args)
|
||||
{
|
||||
if (count($method) === 0 || count($method) > 2) {
|
||||
throw new \danog\MadelineProto\Exception('Invalid method called');
|
||||
}
|
||||
|
@ -91,6 +101,7 @@ class Handler extends \danog\MadelineProto\Connection
|
|||
$args[1]['updates']['callback'] = [$this, 'update_handler'];
|
||||
}
|
||||
$this->madeline = new \danog\MadelineProto\API(...$args);
|
||||
|
||||
return true;
|
||||
}
|
||||
if ($method[0] === '__destruct') {
|
||||
|
@ -105,7 +116,7 @@ class Handler extends \danog\MadelineProto\Connection
|
|||
$arg = [$this, $arg['callback']];
|
||||
}
|
||||
if ($arg['_'] === 'stream' && isset($arg['stream_id'])) {
|
||||
$arg = fopen('madelineSocket://', 'r+b', false, Handler::getContext($this, $arg['stream_id']));
|
||||
$arg = fopen('madelineSocket://', 'r+b', false, self::getContext($this, $arg['stream_id']));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,23 +127,34 @@ class Handler extends \danog\MadelineProto\Connection
|
|||
return $this->madeline->{$method[0]}->{$method[1]}(...$args);
|
||||
}
|
||||
}
|
||||
public function send_exception($request_id, $e) {
|
||||
|
||||
public function send_exception($request_id, $e)
|
||||
{
|
||||
echo $e;
|
||||
//$this->send_message($this->serialize_object(['type' => 'socketMessageException'], ['request_id' => $request_id, 'exception' => $e]));
|
||||
}
|
||||
public function send_response($request_id, $response) {
|
||||
|
||||
public function send_response($request_id, $response)
|
||||
{
|
||||
$this->send_message($this->serialize_object(['type' => 'socketMessageResponse'], ['request_id' => $request_id, 'data' => $response]));
|
||||
}
|
||||
public function send_data($stream_id, $data) {
|
||||
|
||||
public function send_data($stream_id, $data)
|
||||
{
|
||||
$this->send_message($this->serialize_object(['type' => 'socketMessageRawData'], ['stream_id' => $stream_id, 'data' => $data]));
|
||||
}
|
||||
public function logger($message, $level) {
|
||||
|
||||
public function logger($message, $level)
|
||||
{
|
||||
}
|
||||
public function update_handler($update) {
|
||||
|
||||
public function update_handler($update)
|
||||
{
|
||||
$this->send_message($this->serialize_object(['type' => 'socketMessageUpdate'], ['data' => $update]));
|
||||
}
|
||||
public function __call($method, $args) {
|
||||
|
||||
public function __call($method, $args)
|
||||
{
|
||||
$this->send_message($this->serialize_object(['type' => 'socketMessageRequest'], ['request_id' => 0, 'method' => $method, 'args' => $args]));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user