diff --git a/bot.php b/bot.php
index 5cb83033..136ef372 100755
--- a/bot.php
+++ b/bot.php
@@ -65,7 +65,7 @@ class EventHandler extends \danog\MadelineProto\EventHandler
}
}
-$settings = ['app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb98ae0f581e'], 'updates' => ['handle_updates' => true]];;
+$settings = ['app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb98ae0f581e'], 'updates' => ['handle_updates' => true]];
$MadelineProto = new \danog\MadelineProto\API('bot.madeline', $settings);
diff --git a/src/HttpProxy.php b/src/HttpProxy.php
index 8d1d7cd1..66a418b1 100644
--- a/src/HttpProxy.php
+++ b/src/HttpProxy.php
@@ -114,7 +114,9 @@ class HttpProxy implements \danog\MadelineProto\Proxy
{
list($protocol, $code, $description) = explode(' ', $this->read_http_line(), 3);
list($protocol, $protocol_version) = explode('/', $protocol);
- if ($protocol !== 'HTTP') throw new \danog\MadelineProto\Exception('Wrong protocol');
+ if ($protocol !== 'HTTP') {
+ throw new \danog\MadelineProto\Exception('Wrong protocol');
+ }
$code = (int) $code;
$headers = [];
while (strlen($current_header = $this->read_http_line())) {
diff --git a/src/Socket.php b/src/Socket.php
index 42564ddf..7881d52a 100644
--- a/src/Socket.php
+++ b/src/Socket.php
@@ -120,9 +120,12 @@ If not, see .
$packet = '';
while (strlen($packet) < $length) {
$read = stream_get_contents($this->sock, $length - strlen($packet));
- if ($read === false || strlen($read) === 0) throw new \danog\MadelineProto\NothingInTheSocketException();
+ if ($read === false || strlen($read) === 0) {
+ throw new \danog\MadelineProto\NothingInTheSocketException();
+ }
$packet .= $read;
}
+
return $packet;
}
@@ -136,7 +139,7 @@ If not, see .
$wrote = 0;
if (($wrote += fwrite($this->sock, $buffer, $length)) !== $length) {
- while (($wrote += fwrite($this->sock, substr($buffer, $wrote), $length-$wrote)) !== $length) {
+ while (($wrote += fwrite($this->sock, substr($buffer, $wrote), $length - $wrote)) !== $length) {
}
}
@@ -282,9 +285,12 @@ if (!extension_loaded('pthreads')) {
$packet = '';
while (strlen($packet) < $length) {
$read = socket_read($this->sock, $length - strlen($packet), $flags);
- if ($read === false || strlen($read) === false) throw new \danog\MadelineProto\NothingInTheSocketException();
+ if ($read === false || strlen($read) === false) {
+ throw new \danog\MadelineProto\NothingInTheSocketException();
+ }
$packet .= $read;
}
+
return $packet;
}
@@ -298,7 +304,7 @@ if (!extension_loaded('pthreads')) {
$wrote = 0;
if (($wrote += socket_write($this->sock, $buffer, $length)) !== $length) {
- while (($wrote += socket_write($this->sock, substr($buffer, $wrote), $length-$wrote)) !== $length) {
+ while (($wrote += socket_write($this->sock, substr($buffer, $wrote), $length - $wrote)) !== $length) {
}
}
diff --git a/src/SocksProxy.php b/src/SocksProxy.php
index b44be660..24666fc2 100644
--- a/src/SocksProxy.php
+++ b/src/SocksProxy.php
@@ -33,39 +33,51 @@ class SocksProxy implements \danog\MadelineProto\Proxy
$this->type = $type;
$this->protocol = $protocol;
}
- public function setExtra(array $extra = []) {
+
+ public function setExtra(array $extra = [])
+ {
$this->extra = $extra;
$name = $this->protocol === PHP_INT_MAX ? '\\FSocket' : '\\Socket';
$this->sock = new $name(strlen(@inet_pton($this->extra['address'])) !== 4 ? \AF_INET6 : \AF_INET, \SOCK_STREAM, $this->protocol);
}
- public function setOption(int $level, int $name, $value) {
+
+ public function setOption(int $level, int $name, $value)
+ {
return $this->sock->setOption($level, $name, $value);
}
- public function getOption(int $level, int $name) {
+ public function getOption(int $level, int $name)
+ {
return $this->sock->getOption($level, $name);
}
- public function setBlocking(bool $blocking) {
+ public function setBlocking(bool $blocking)
+ {
return $this->sock->setBlocking($blocking);
}
- public function bind(string $address, int $port = 0) {
+ public function bind(string $address, int $port = 0)
+ {
throw new \danog\MadelineProto\Exception('Not Implemented');
}
- public function listen(int $backlog = 0) {
- throw new \danog\MadelineProto\Exception('Not Implemented');
- }
- public function accept() {
+ public function listen(int $backlog = 0)
+ {
throw new \danog\MadelineProto\Exception('Not Implemented');
}
+ public function accept()
+ {
+ throw new \danog\MadelineProto\Exception('Not Implemented');
+ }
- public function select(array &$read, array &$write, array &$except, int $tv_sec, int $tv_usec = 0) {
+ public function select(array &$read, array &$write, array &$except, int $tv_sec, int $tv_usec = 0)
+ {
return $this->sock->select($read, $write, $except, $tv_sec, $tv_usec);
}
- public function connect(string $address, int $port = 0) {
+
+ public function connect(string $address, int $port = 0)
+ {
$this->sock->connect($this->extra['address'], $this->extra['port']);
$methods = chr(0);
@@ -92,17 +104,18 @@ class SocksProxy implements \danog\MadelineProto\Proxy
if ($result !== 0) {
throw new \danog\MadelineProto\Exception("Wrong authorization status: $version");
}
- } else if ($method !== 0) {
+ } elseif ($method !== 0) {
throw new \danog\MadelineProto\Exception("Wrong method: $method");
}
- $payload = pack("C3", 0x05, 0x01, 0x00);
+ $payload = pack('C3', 0x05, 0x01, 0x00);
+
try {
$ip = inet_pton($address);
- $payload .= pack("C1", strlen($ip) === 4 ? 0x01 : 0x04).$ip;
+ $payload .= pack('C1', strlen($ip) === 4 ? 0x01 : 0x04).$ip;
} catch (\danog\MadelineProto\Exception $e) {
- $payload .= pack("C2", 0x03, strlen($address)).$address;
+ $payload .= pack('C2', 0x03, strlen($address)).$address;
}
- $payload .= pack("n", $port);
+ $payload .= pack('n', $port);
$this->sock->write($payload);
$version = ord($this->sock->read(1));
@@ -130,37 +143,49 @@ class SocksProxy implements \danog\MadelineProto\Proxy
$ip = $this->sock->read(ord($this->sock->read(1)));
break;
}
- $port = unpack("n", $this->sock->read(2))[1];
+ $port = unpack('n', $this->sock->read(2))[1];
\danog\MadelineProto\Logger::log(['Connected to '.$ip.':'.$port.' via socks5']);
+
return true;
}
- public function read(int $length, int $flags = 0) {
+
+ public function read(int $length, int $flags = 0)
+ {
return $this->sock->read($length, $flags);
}
- public function write(string $buffer, int $length = -1) {
+ public function write(string $buffer, int $length = -1)
+ {
return $this->sock->write($buffer, $length);
}
- public function send(string $data, int $length, int $flags) {
+ public function send(string $data, int $length, int $flags)
+ {
throw new \danog\MadelineProto\Exception('Not Implemented');
}
- public function close() {
+ public function close()
+ {
$this->sock->close();
}
- public function getPeerName(bool $port = true) {
+ public function getPeerName(bool $port = true)
+ {
throw new \danog\MadelineProto\Exception('Not Implemented');
}
- public function getSockName(bool $port = true) {
+ public function getSockName(bool $port = true)
+ {
throw new \danog\MadelineProto\Exception('Not Implemented');
}
- public function getProxyHeaders() {
+
+ public function getProxyHeaders()
+ {
return '';
}
- public function getResource() {
+
+ public function getResource()
+ {
return $this->sock->getResource();
}
}
diff --git a/src/danog/MadelineProto/Connection.php b/src/danog/MadelineProto/Connection.php
index 0c0d81a2..df0255c7 100644
--- a/src/danog/MadelineProto/Connection.php
+++ b/src/danog/MadelineProto/Connection.php
@@ -374,7 +374,9 @@ class Connection
{
list($protocol, $code, $description) = explode(' ', $this->read_http_line(), 3);
list($protocol, $protocol_version) = explode('/', $protocol);
- if ($protocol !== 'HTTP') throw new \danog\MadelineProto\Exception('Wrong protocol');
+ if ($protocol !== 'HTTP') {
+ throw new \danog\MadelineProto\Exception('Wrong protocol');
+ }
$code = (int) $code;
$headers = [];
while (strlen($current_header = $this->read_http_line())) {
diff --git a/src/danog/MadelineProto/DataCenter.php b/src/danog/MadelineProto/DataCenter.php
index 1d0344b5..38b2e9be 100644
--- a/src/danog/MadelineProto/DataCenter.php
+++ b/src/danog/MadelineProto/DataCenter.php
@@ -100,9 +100,9 @@ class DataCenter
return true;
} catch (\danog\MadelineProto\Exception $e) {
- \danog\MadelineProto\Logger::log("Connection failed: ".$e->getMessage(), \danog\MadelineProto\Logger::ERROR);
+ \danog\MadelineProto\Logger::log('Connection failed: '.$e->getMessage(), \danog\MadelineProto\Logger::ERROR);
} catch (\danog\MadelineProto\NothingInTheSocketException $e) {
- \danog\MadelineProto\Logger::log("Connection failed: read timeout", \danog\MadelineProto\Logger::ERROR);
+ \danog\MadelineProto\Logger::log('Connection failed: read timeout', \danog\MadelineProto\Logger::ERROR);
}
if (isset($this->settings[$dc_config_number]['do_not_retry']) && $this->settings[$dc_config_number]['do_not_retry']) {
break;