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.
If not, see <http://www.gnu.org/licenses/>.
*/
namespace danog\MadelineProto;
class API extends APIFactory
@ -17,6 +18,7 @@ class API extends APIFactory
use \danog\Serializable;
public $session;
public $serialized = 0;
public function __magic_construct($params = [])
{
set_error_handler(['\\danog\\MadelineProto\\Exception', 'ExceptionErrorHandler']);
@ -32,6 +34,7 @@ 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 {
@ -40,10 +43,11 @@ 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) {
@ -68,6 +72,7 @@ class API extends APIFactory
$this->API = $unserialized->API;
$this->APIFactory();
}
return;
}
$this->API = new MTProto($params);
@ -75,16 +80,18 @@ 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())) {
@ -95,45 +102,56 @@ 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);
}
}
}

View File

@ -209,7 +209,7 @@ trait PeerHandler
$dbres = json_decode(@file_get_contents('https://id.pwrtelegram.xyz/db/getusername?id='.$id, false, stream_context_create(['http' => ['timeout' => 2]])), true);
if (isset($dbres['ok']) && $dbres['ok']) {
$this->resolve_username('@'.$dbres['result']);
return $this->get_info($id, false);
}
}

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.
If not, see <http://www.gnu.org/licenses/>.
*/
namespace danog\MadelineProto;
/**
@ -19,7 +20,8 @@ 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)) {
@ -27,14 +29,17 @@ class Serialization
}
}
}
public static function realpaths($file)
{
if ($file[0] !== '/') {
$file = getcwd() . '/' . $file;
$file = getcwd().'/'.$file;
}
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.
*
@ -59,6 +64,7 @@ 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']);
@ -66,8 +72,10 @@ class Serialization
flock($realpaths['lockfile'], LOCK_UN);
fclose($realpaths['lockfile']);
}
return $wrote;
}
/**
* Deserialize API class.
*
@ -88,6 +96,7 @@ 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 {
@ -96,10 +105,11 @@ 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) {
@ -123,6 +133,7 @@ class Serialization
if ($unserialized instanceof \danog\MadelineProto\API) {
$unserialized->session = $filename;
}
return $unserialized;
}
}
}