diff --git a/src/danog/MadelineProto/API.php b/src/danog/MadelineProto/API.php
index 5b2a37024..f42ea5908 100644
--- a/src/danog/MadelineProto/API.php
+++ b/src/danog/MadelineProto/API.php
@@ -10,7 +10,6 @@ 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 .
*/
-
namespace danog\MadelineProto;
class API extends APIFactory
@@ -18,15 +17,14 @@ class API extends APIFactory
use \danog\Serializable;
public $session;
public $serialized = 0;
-
public function __magic_construct($params = [])
{
set_error_handler(['\\danog\\MadelineProto\\Exception', 'ExceptionErrorHandler']);
set_exception_handler(['\\danog\\MadelineProto\\Serialization', 'serialize_all']);
if (is_string($params)) {
- if (file_exists($params)) {
- $this->session = $params;
- $realpaths = Serialization::realpaths($params);
+ $realpaths = Serialization::realpaths($params);
+ if (file_exists($realpaths['file'])) {
+ $this->session = $realpaths['file'];
if (!file_exists($realpaths['lockfile'])) {
touch($realpaths['lockfile']);
clearstatcache();
@@ -34,7 +32,6 @@ class API extends APIFactory
$realpaths['lockfile'] = fopen($realpaths['lockfile'], 'r');
\danog\MadelineProto\Logger::log(['Waiting for shared lock of serialization lockfile...']);
flock($realpaths['lockfile'], LOCK_SH);
-
try {
$unserialized = file_get_contents($realpaths['file']);
} finally {
@@ -43,11 +40,10 @@ class API extends APIFactory
}
$tounserialize = str_replace('O:26:"danog\\MadelineProto\\Button":', 'O:35:"danog\\MadelineProto\\TL\\Types\\Button":', $unserialized);
foreach (['RSA', 'TL\\TLMethod', 'TL\\TLConstructor', 'MTProto', 'API', 'DataCenter', 'Connection', 'TL\\Types\\Button', 'TL\\Types\\Bytes', 'APIFactory'] as $class) {
- class_exists('\\danog\\MadelineProto\\'.$class);
+ class_exists('\\danog\\MadelineProto\\' . $class);
}
class_exists('\\Volatile');
\danog\MadelineProto\Logger::class_exists();
-
try {
$unserialized = unserialize($tounserialize);
} catch (\danog\MadelineProto\Bug74586Exception $e) {
@@ -72,7 +68,6 @@ class API extends APIFactory
$this->API = $unserialized->API;
$this->APIFactory();
}
-
return;
}
$this->API = new MTProto($params);
@@ -80,18 +75,16 @@ class API extends APIFactory
$this->APIFactory();
\danog\MadelineProto\Logger::log(['Ping...'], Logger::ULTRA_VERBOSE);
$pong = $this->ping(['ping_id' => 3]);
- \danog\MadelineProto\Logger::log(['Pong: '.$pong['ping_id']], Logger::ULTRA_VERBOSE);
+ \danog\MadelineProto\Logger::log(['Pong: ' . $pong['ping_id']], Logger::ULTRA_VERBOSE);
//\danog\MadelineProto\Logger::log(['Getting future salts...'], Logger::ULTRA_VERBOSE);
//$this->future_salts = $this->get_future_salts(['num' => 3]);
\danog\MadelineProto\Logger::log([\danog\MadelineProto\Lang::$current_lang['madelineproto_ready']], Logger::NOTICE);
}
-
public function __wakeup()
{
//if (method_exists($this->API, 'wakeup')) $this->API = $this->API->wakeup();
$this->APIFactory();
}
-
public function __destruct()
{
if (\danog\MadelineProto\Logger::$has_thread && is_object(\Thread::getCurrentThread())) {
@@ -102,56 +95,45 @@ class API extends APIFactory
}
restore_error_handler();
}
-
public function __sleep()
{
return ['API'];
}
-
public function &__get($name)
{
if ($name === 'settings') {
$this->API->setdem = true;
-
return $this->API->settings;
}
-
return $this->API->storage[$name];
}
-
public function __set($name, $value)
{
if ($name === 'settings') {
return $this->API->__construct($value);
}
-
return $this->API->storage[$name] = $value;
}
-
public function __isset($name)
{
return isset($this->API->storage[$name]);
}
-
public function __unset($name)
{
unset($this->API->storage[$name]);
}
-
public function APIFactory()
{
foreach ($this->API->get_method_namespaces() as $namespace) {
$this->{$namespace} = new APIFactory($namespace, $this->API);
}
}
-
public function serialize($params = '')
{
if ($params === '') {
$params = $this->session;
}
Logger::log([\danog\MadelineProto\Lang::$current_lang['serializing_madelineproto']]);
-
return Serialization::serialize($params, $this);
}
-}
+}
\ No newline at end of file
diff --git a/src/danog/MadelineProto/Serialization.php b/src/danog/MadelineProto/Serialization.php
index 0d0dbafd9..055ca565d 100644
--- a/src/danog/MadelineProto/Serialization.php
+++ b/src/danog/MadelineProto/Serialization.php
@@ -10,7 +10,6 @@ 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 .
*/
-
namespace danog\MadelineProto;
/**
@@ -20,8 +19,7 @@ class Serialization
{
public static function serialize_all($exception)
{
- echo $exception.PHP_EOL;
-
+ echo $exception . PHP_EOL;
return;
foreach (self::$instances as $instance) {
if (isset($instance->session)) {
@@ -29,16 +27,14 @@ class Serialization
}
}
}
-
public static function realpaths($file)
{
if ($file[0] !== '/') {
- $file = getcwd().'/'.$file;
+ $file = getcwd() . '/' . $file;
}
-
- return ['file' => $file, 'lockfile' => $file.'.lock', 'tempfile' => $file.'.temp.session'];
+ var_dump(getcwd());
+ return ['file' => $file, 'lockfile' => $file . '.lock', 'tempfile' => $file . '.temp.session'];
}
-
/**
* Serialize API class.
*
@@ -63,7 +59,6 @@ class Serialization
$realpaths['lockfile'] = fopen($realpaths['lockfile'], 'w');
\danog\MadelineProto\Logger::log(['Waiting for exclusive lock of serialization lockfile...']);
flock($realpaths['lockfile'], LOCK_EX);
-
try {
$wrote = file_put_contents($realpaths['tempfile'], serialize($instance));
rename($realpaths['tempfile'], $realpaths['file']);
@@ -71,10 +66,8 @@ class Serialization
flock($realpaths['lockfile'], LOCK_UN);
fclose($realpaths['lockfile']);
}
-
return $wrote;
}
-
/**
* Deserialize API class.
*
@@ -86,8 +79,8 @@ class Serialization
*/
public static function deserialize($filename, $no_updates = false)
{
- if (file_exists($filename)) {
- $realpaths = self::realpaths($filename);
+ $realpaths = self::realpaths($filename);
+ if (file_exists($realpaths['file'])) {
if (!file_exists($realpaths['lockfile'])) {
touch($realpaths['lockfile']);
clearstatcache();
@@ -95,7 +88,6 @@ class Serialization
$realpaths['lockfile'] = fopen($realpaths['lockfile'], 'r');
\danog\MadelineProto\Logger::log(['Waiting for shared lock of serialization lockfile...']);
flock($realpaths['lockfile'], LOCK_SH);
-
try {
$unserialized = file_get_contents($realpaths['file']);
} finally {
@@ -104,11 +96,10 @@ class Serialization
}
$tounserialize = str_replace('O:26:"danog\\MadelineProto\\Button":', 'O:35:"danog\\MadelineProto\\TL\\Types\\Button":', $unserialized);
foreach (['RSA', 'TL\\TLMethod', 'TL\\TLConstructor', 'MTProto', 'API', 'DataCenter', 'Connection', 'TL\\Types\\Button', 'TL\\Types\\Bytes', 'APIFactory'] as $class) {
- class_exists('\\danog\\MadelineProto\\'.$class);
+ class_exists('\\danog\\MadelineProto\\' . $class);
}
class_exists('\\Volatile');
\danog\MadelineProto\Logger::class_exists();
-
try {
$unserialized = unserialize($tounserialize);
} catch (\danog\MadelineProto\Bug74586Exception $e) {
@@ -132,7 +123,6 @@ class Serialization
if ($unserialized instanceof \danog\MadelineProto\API) {
$unserialized->session = $filename;
}
-
return $unserialized;
}
-}
+}
\ No newline at end of file