From eb3ee22e3fdc83cde0ce2a23fd530dc1be2910d0 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Wed, 17 May 2017 22:51:13 +0100 Subject: [PATCH] Bugfixes --- a.php | 42 +++++------------------ src/Threaded.php | 26 +++++++------- src/Volatile.php | 4 +-- src/danog/MadelineProto/Button.php | 17 ++++----- src/danog/MadelineProto/Connection.php | 4 ++- src/danog/MadelineProto/MTProto.php | 7 ++++ src/danog/MadelineProto/Serialization.php | 4 +++ 7 files changed, 43 insertions(+), 61 deletions(-) diff --git a/a.php b/a.php index b8f1c6ec..0f909c9d 100644 --- a/a.php +++ b/a.php @@ -1,38 +1,12 @@ a = 'le'; + } +} +$a = new a; - public function run() - { - $this->a[1] = new b(); - $this->a[1]->a['a'] = []; - var_dump($this); - } -} -class b extends \Volatile -{ - public $a = []; -} -class main extends Threaded -{ - public function __construct() - { - $this->a = new a(); - var_dump($this->a); - $this->a->run(); - // One of the OH NOES (b) is printed here - } - - public function run() - { - // $this->a; - } -} -$a = new main(); -$pool = new Pool(1); -//$pool->submit($a); // One of the OH NOES (a) is printed here +var_dump($a); diff --git a/src/Threaded.php b/src/Threaded.php index 7b935d46..40fcccf9 100644 --- a/src/Threaded.php +++ b/src/Threaded.php @@ -31,23 +31,23 @@ if (!extension_loaded('pthreads')) { public function count() { - return count($this->data); + return count((array)$this); } public function getIterator() { - return new ArrayIterator($this->data); + return new ArrayIterator($this); } public function __set($offset, $value) { if ($offset === null) { - $offset = count($this->data); + $offset = count($this); } if (!$this instanceof Volatile) { - if (isset($this->data[$offset]) && - $this->data[$offset] instanceof self) { + if (isset($this->{$offset}) && + $this->{$offset} instanceof self) { throw new \RuntimeException(); } } @@ -60,32 +60,32 @@ if (!extension_loaded('pthreads')) { $value = $safety; } - return $this->data[$offset] = $value; + return $this->{$offset} = $value; } public function __get($offset) { - return $this->data[$offset]; + return $this->{$offset}; } public function __isset($offset) { - return isset($this->data[$offset]); + return isset($this->{$offset}); } public function __unset($offset) { if (!$this instanceof Volatile) { - if (isset($this->data[$offset]) && $this->data[$offset] instanceof self) { + if (isset($this->{$offset}) && $this->{$offset} instanceof self) { throw new \RuntimeException(); } } - unset($this->data[$offset]); + unset($this->{$offset}); } public function shift() { - return array_shift($this->data); + } public function chunk($size) @@ -100,13 +100,12 @@ if (!extension_loaded('pthreads')) { public function pop() { - return array_pop($this->data); } public function merge($merge) { foreach ($merge as $k => $v) { - $this->data[$k] = $v; + $this->{$k} = $v; } } @@ -193,7 +192,6 @@ if (!extension_loaded('pthreads')) { return $value; } - protected $data; protected $state; } } diff --git a/src/Volatile.php b/src/Volatile.php index d62cc378..6cd483ee 100644 --- a/src/Volatile.php +++ b/src/Volatile.php @@ -6,7 +6,7 @@ if (!extension_loaded('pthreads')) { public function __set($offset, $value) { if ($offset === null) { - $offset = count($this->data); + $offset = count((array)$this); } if (is_array($value)) { @@ -17,7 +17,7 @@ if (!extension_loaded('pthreads')) { $value = $safety; } - return $this->data[$offset] = $value; + return $this->{$offset} = $value; } } } diff --git a/src/danog/MadelineProto/Button.php b/src/danog/MadelineProto/Button.php index 862f4dc3..97f746eb 100644 --- a/src/danog/MadelineProto/Button.php +++ b/src/danog/MadelineProto/Button.php @@ -16,8 +16,8 @@ class Button extends \Volatile implements \JsonSerializable { use \danog\Serializable; private $info = []; - - public function __construct($API, $message, $button) + private $data = []; + public function ___construct($API, $message, $button) { $this->data = $button; $this->info['peer'] = $message['to_id']; @@ -27,20 +27,17 @@ class Button extends \Volatile implements \JsonSerializable public function click($donotwait = false) { - switch ($this->_) { + switch ($this->data['_']) { default: return false; - case 'keyboardButtonUrl': return $this->url; - case 'keyboardButton': return $this->info['API']->method_call('messages.sendMessage', ['peer' => $this->info['peer'], 'message' => $this->text, 'reply_to_msg_id' => $this->info['id']], ['datacenter' => $this->info['API']->datacenter->curdc]); - case 'keyboardButtonCallback': return $this->info['API']->method_call('messages.getBotCallbackAnswer', ['peer' => $this->info['peer'], 'msg_id' => $this->info['id'], 'data' => $this->data], ['noResponse' => $donotwait, 'datacenter' => $this->info['API']->datacenter->curdc]); + case 'keyboardButtonUrl': return $this->data['url']; + case 'keyboardButton': return $this->info['API']->method_call('messages.sendMessage', ['peer' => $this->info['peer'], 'message' => $this->data['text'], 'reply_to_msg_id' => $this->info['id']], ['datacenter' => $this->info['API']->datacenter->curdc]); + case 'keyboardButtonCallback': return $this->info['API']->method_call('messages.getBotCallbackAnswer', ['peer' => $this->info['peer'], 'msg_id' => $this->info['id'], 'data' => $this->data['data']], ['noResponse' => $donotwait, 'datacenter' => $this->info['API']->datacenter->curdc]); case 'keyboardButtonGame': return $this->info['API']->method_call('messages.getBotCallbackAnswer', ['peer' => $this->info['peer'], 'msg_id' => $this->info['id'], 'game' => true], ['noResponse' => $donotwait, 'datacenter' => $this->info['API']->datacenter->curdc]); } } public function jsonSerialize() { - $res = get_object_vars($this); - unset($res['info']); - - return $res; + return (array) $this->data; } } diff --git a/src/danog/MadelineProto/Connection.php b/src/danog/MadelineProto/Connection.php index 3fb292f4..38832e15 100644 --- a/src/danog/MadelineProto/Connection.php +++ b/src/danog/MadelineProto/Connection.php @@ -154,12 +154,14 @@ class Connection extends \Volatile if (isset($t['sock'])) { unset($t['sock']); } + if (isset($t['data'])) { + unset($t['data']); + } $keys = array_keys((array) $t); if (count($keys) !== count(array_unique($keys))) { throw new Bug74586Exception(); } - return $keys; } diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index 8faf7f99..304780f5 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -118,6 +118,9 @@ class MTProto extends \Volatile if (isset($t['readers'])) { unset($t['readers']); } + if (isset($t['data'])) { + unset($t['data']); + } $keys = array_keys((array) $t); if (count($keys) !== count(array_unique($keys))) { @@ -148,6 +151,10 @@ class MTProto extends \Volatile if (method_exists($elem, 'wakeup')) $this->datacenter->sockets[$key] = $elem->wakeup(); } */ + if (isset($this->data)) { + foreach ($this->data as $k => $v) { $this->{$k} = $v; } + unset($this->data); + } $this->getting_state = false; $this->reset_session(); if (!isset($this->v) || $this->v !== $this->getV()) { diff --git a/src/danog/MadelineProto/Serialization.php b/src/danog/MadelineProto/Serialization.php index 99f09246..c657f7eb 100644 --- a/src/danog/MadelineProto/Serialization.php +++ b/src/danog/MadelineProto/Serialization.php @@ -59,10 +59,14 @@ class Serialization foreach (['RSA', 'TL\TLMethod', 'TL\TLConstructor', 'MTProto', 'API', 'DataCenter', 'Connection'] as $class) { class_exists('\danog\MadelineProto\\'.$class); } + class_exists('\Volatile'); + \danog\MadelineProto\Logger::class_exists(); try { $unserialized = \danog\MadelineProto\Logger::$has_thread ? \danog\Serialization::unserialize($unserialized) : unserialize($unserialized); } catch (Bug74586Exception $e) { $unserialized = \danog\Serialization::unserialize($unserialized); + } catch (Exception $e) { + $unserialized = \danog\Serialization::unserialize($unserialized); } } else { throw new Exception('File does not exist');