Apply fixes from StyleCI

This commit is contained in:
Daniil Gentili 2018-02-25 16:50:03 +00:00 committed by StyleCI Bot
parent 633aee1019
commit 782e145072
3 changed files with 38 additions and 9 deletions

View File

@ -10,6 +10,7 @@ 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. You should have received a copy of the GNU General Public License along with MadelineProto.
If not, see <http://www.gnu.org/licenses/>. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace danog\MadelineProto; namespace danog\MadelineProto;
class API extends APIFactory class API extends APIFactory
@ -17,6 +18,7 @@ class API extends APIFactory
use \danog\Serializable; use \danog\Serializable;
public $session; public $session;
public $serialized = 0; public $serialized = 0;
public function __magic_construct($params = []) public function __magic_construct($params = [])
{ {
set_error_handler(['\\danog\\MadelineProto\\Exception', 'ExceptionErrorHandler']); set_error_handler(['\\danog\\MadelineProto\\Exception', 'ExceptionErrorHandler']);
@ -32,6 +34,7 @@ class API extends APIFactory
$realpaths['lockfile'] = fopen($realpaths['lockfile'], 'r'); $realpaths['lockfile'] = fopen($realpaths['lockfile'], 'r');
\danog\MadelineProto\Logger::log(['Waiting for shared lock of serialization lockfile...']); \danog\MadelineProto\Logger::log(['Waiting for shared lock of serialization lockfile...']);
flock($realpaths['lockfile'], LOCK_SH); flock($realpaths['lockfile'], LOCK_SH);
try { try {
$unserialized = file_get_contents($realpaths['file']); $unserialized = file_get_contents($realpaths['file']);
} finally { } finally {
@ -40,10 +43,11 @@ class API extends APIFactory
} }
$tounserialize = str_replace('O:26:"danog\\MadelineProto\\Button":', 'O:35:"danog\\MadelineProto\\TL\\Types\\Button":', $unserialized); $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) { 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'); class_exists('\\Volatile');
\danog\MadelineProto\Logger::class_exists(); \danog\MadelineProto\Logger::class_exists();
try { try {
$unserialized = unserialize($tounserialize); $unserialized = unserialize($tounserialize);
} catch (\danog\MadelineProto\Bug74586Exception $e) { } catch (\danog\MadelineProto\Bug74586Exception $e) {
@ -68,6 +72,7 @@ class API extends APIFactory
$this->API = $unserialized->API; $this->API = $unserialized->API;
$this->APIFactory(); $this->APIFactory();
} }
return; return;
} }
$this->API = new MTProto($params); $this->API = new MTProto($params);
@ -75,16 +80,18 @@ class API extends APIFactory
$this->APIFactory(); $this->APIFactory();
\danog\MadelineProto\Logger::log(['Ping...'], Logger::ULTRA_VERBOSE); \danog\MadelineProto\Logger::log(['Ping...'], Logger::ULTRA_VERBOSE);
$pong = $this->ping(['ping_id' => 3]); $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); //\danog\MadelineProto\Logger::log(['Getting future salts...'], Logger::ULTRA_VERBOSE);
//$this->future_salts = $this->get_future_salts(['num' => 3]); //$this->future_salts = $this->get_future_salts(['num' => 3]);
\danog\MadelineProto\Logger::log([\danog\MadelineProto\Lang::$current_lang['madelineproto_ready']], Logger::NOTICE); \danog\MadelineProto\Logger::log([\danog\MadelineProto\Lang::$current_lang['madelineproto_ready']], Logger::NOTICE);
} }
public function __wakeup() public function __wakeup()
{ {
//if (method_exists($this->API, 'wakeup')) $this->API = $this->API->wakeup(); //if (method_exists($this->API, 'wakeup')) $this->API = $this->API->wakeup();
$this->APIFactory(); $this->APIFactory();
} }
public function __destruct() public function __destruct()
{ {
if (\danog\MadelineProto\Logger::$has_thread && is_object(\Thread::getCurrentThread())) { if (\danog\MadelineProto\Logger::$has_thread && is_object(\Thread::getCurrentThread())) {
@ -95,45 +102,56 @@ class API extends APIFactory
} }
restore_error_handler(); restore_error_handler();
} }
public function __sleep() public function __sleep()
{ {
return ['API']; return ['API'];
} }
public function &__get($name) public function &__get($name)
{ {
if ($name === 'settings') { if ($name === 'settings') {
$this->API->setdem = true; $this->API->setdem = true;
return $this->API->settings; return $this->API->settings;
} }
return $this->API->storage[$name]; return $this->API->storage[$name];
} }
public function __set($name, $value) public function __set($name, $value)
{ {
if ($name === 'settings') { if ($name === 'settings') {
return $this->API->__construct($value); return $this->API->__construct($value);
} }
return $this->API->storage[$name] = $value; return $this->API->storage[$name] = $value;
} }
public function __isset($name) public function __isset($name)
{ {
return isset($this->API->storage[$name]); return isset($this->API->storage[$name]);
} }
public function __unset($name) public function __unset($name)
{ {
unset($this->API->storage[$name]); unset($this->API->storage[$name]);
} }
public function APIFactory() public function APIFactory()
{ {
foreach ($this->API->get_method_namespaces() as $namespace) { foreach ($this->API->get_method_namespaces() as $namespace) {
$this->{$namespace} = new APIFactory($namespace, $this->API); $this->{$namespace} = new APIFactory($namespace, $this->API);
} }
} }
public function serialize($params = '') public function serialize($params = '')
{ {
if ($params === '') { if ($params === '') {
$params = $this->session; $params = $this->session;
} }
Logger::log([\danog\MadelineProto\Lang::$current_lang['serializing_madelineproto']]); Logger::log([\danog\MadelineProto\Lang::$current_lang['serializing_madelineproto']]);
return Serialization::serialize($params, $this); return Serialization::serialize($params, $this);
} }
} }

View File

@ -10,6 +10,7 @@ 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. You should have received a copy of the GNU General Public License along with MadelineProto.
If not, see <http://www.gnu.org/licenses/>. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace danog\MadelineProto; namespace danog\MadelineProto;
/** /**
@ -19,7 +20,8 @@ class Serialization
{ {
public static function serialize_all($exception) public static function serialize_all($exception)
{ {
echo $exception . PHP_EOL; echo $exception.PHP_EOL;
return; return;
foreach (self::$instances as $instance) { foreach (self::$instances as $instance) {
if (isset($instance->session)) { if (isset($instance->session)) {
@ -27,14 +29,17 @@ class Serialization
} }
} }
} }
public static function realpaths($file) public static function realpaths($file)
{ {
if ($file[0] !== '/') { if ($file[0] !== '/') {
$file = getcwd() . '/' . $file; $file = getcwd().'/'.$file;
} }
var_dump(getcwd()); var_dump(getcwd());
return ['file' => $file, 'lockfile' => $file . '.lock', 'tempfile' => $file . '.temp.session'];
return ['file' => $file, 'lockfile' => $file.'.lock', 'tempfile' => $file.'.temp.session'];
} }
/** /**
* Serialize API class. * Serialize API class.
* *
@ -59,6 +64,7 @@ class Serialization
$realpaths['lockfile'] = fopen($realpaths['lockfile'], 'w'); $realpaths['lockfile'] = fopen($realpaths['lockfile'], 'w');
\danog\MadelineProto\Logger::log(['Waiting for exclusive lock of serialization lockfile...']); \danog\MadelineProto\Logger::log(['Waiting for exclusive lock of serialization lockfile...']);
flock($realpaths['lockfile'], LOCK_EX); flock($realpaths['lockfile'], LOCK_EX);
try { try {
$wrote = file_put_contents($realpaths['tempfile'], serialize($instance)); $wrote = file_put_contents($realpaths['tempfile'], serialize($instance));
rename($realpaths['tempfile'], $realpaths['file']); rename($realpaths['tempfile'], $realpaths['file']);
@ -66,8 +72,10 @@ class Serialization
flock($realpaths['lockfile'], LOCK_UN); flock($realpaths['lockfile'], LOCK_UN);
fclose($realpaths['lockfile']); fclose($realpaths['lockfile']);
} }
return $wrote; return $wrote;
} }
/** /**
* Deserialize API class. * Deserialize API class.
* *
@ -88,6 +96,7 @@ class Serialization
$realpaths['lockfile'] = fopen($realpaths['lockfile'], 'r'); $realpaths['lockfile'] = fopen($realpaths['lockfile'], 'r');
\danog\MadelineProto\Logger::log(['Waiting for shared lock of serialization lockfile...']); \danog\MadelineProto\Logger::log(['Waiting for shared lock of serialization lockfile...']);
flock($realpaths['lockfile'], LOCK_SH); flock($realpaths['lockfile'], LOCK_SH);
try { try {
$unserialized = file_get_contents($realpaths['file']); $unserialized = file_get_contents($realpaths['file']);
} finally { } finally {
@ -96,10 +105,11 @@ class Serialization
} }
$tounserialize = str_replace('O:26:"danog\\MadelineProto\\Button":', 'O:35:"danog\\MadelineProto\\TL\\Types\\Button":', $unserialized); $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) { 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'); class_exists('\\Volatile');
\danog\MadelineProto\Logger::class_exists(); \danog\MadelineProto\Logger::class_exists();
try { try {
$unserialized = unserialize($tounserialize); $unserialized = unserialize($tounserialize);
} catch (\danog\MadelineProto\Bug74586Exception $e) { } catch (\danog\MadelineProto\Bug74586Exception $e) {
@ -123,6 +133,7 @@ class Serialization
if ($unserialized instanceof \danog\MadelineProto\API) { if ($unserialized instanceof \danog\MadelineProto\API) {
$unserialized->session = $filename; $unserialized->session = $filename;
} }
return $unserialized; return $unserialized;
} }
} }