Fixed APIFactory, allowed reading of settings from the API class, changed the way of passing arguments to methods with the API (and APIFactory) class.

This commit is contained in:
danogentili 2016-11-16 17:37:27 +03:00
parent b28aab6359
commit e6093e65ac
5 changed files with 13 additions and 12 deletions

View File

@ -15,14 +15,15 @@ namespace danog\MadelineProto;
class API extends Tools
{
public $session;
public $settings;
public function __construct($params = [])
{
set_error_handler(['\danog\MadelineProto\Exception', 'ExceptionErrorHandler']);
$this->session = new MTProto($params);
$this->settings = &$this->session->settings;
\danog\MadelineProto\Logger::log('Running APIFactory...');
foreach ($this->session->tl->method_name_namespaced as $method) {
foreach ($this->session->tl->method_names_namespaced as $method) {
if (isset($method[1])) {
if (!isset($this->{$method[0]})) {
$this->{$method[0]} = new APIFactory($method[0], $this->session);
@ -32,10 +33,10 @@ class API extends Tools
}
\danog\MadelineProto\Logger::log('Ping...');
$ping = $this->ping(3);
$ping = $this->ping([3]);
\danog\MadelineProto\Logger::log('Pong: '.$ping['ping_id']);
\danog\MadelineProto\Logger::log('Getting future salts...');
$future_salts = $this->get_future_salts(3);
$future_salts = $this->get_future_salts([3]);
\danog\MadelineProto\Logger::log('MadelineProto is ready!');
}
@ -47,9 +48,9 @@ class API extends Tools
public function __call($name, $arguments)
{
if (!in_array($name, $this->session->tl->method_name_namespaced)) {
if (!in_array($name, $this->session->tl->method_names)) {
throw new Exception("The called method doesn't exist!");
}
return $this->session->method_call($name, $arguments);
return $this->session->method_call($name, $arguments[0]);
}
}

View File

@ -28,7 +28,7 @@ class APIFactory
if (!in_array($name, $this->allowed_methods)) {
throw new Exception("The called method doesn't exist!");
}
return $this->session->method_call($this->namespace.'.'.$name, $arguments);
return $this->session->method_call($this->namespace.'.'.$name, $arguments[0]);
}
}

View File

@ -125,7 +125,6 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
$this->future_salts = [];
$this->switch_dc($this->settings['connection_settings']['default_dc'], true);
}
public function setup_logger()

View File

@ -45,7 +45,8 @@ class TL extends \danog\MadelineProto\Tools
$z = new \danog\MadelineProto\TL\TLMethod($elem);
$this->method_id[$z->id] = $z;
$this->method_name[$z->method] = $z;
$this->method_name_namespaced[$z->method] = explode('.', $z->method);
$this->method_names[$z->method] = $z->method;
$this->method_names_namespaced[$z->method] = explode('.', $z->method);
}
}

View File

@ -21,9 +21,9 @@ if (file_exists('number.php')) {
[
'phone_number' => $number,
'sms_type' => 5,
'api_id' => $this->settings['app_info']['api_id'],
'api_hash' => $this->settings['app_info']['api_hash'],
'lang_code' => $this->settings['app_info']['lang_code'],
'api_id' => $MadelineProto->settings['app_info']['api_id'],
'api_hash' => $MadelineProto->settings['app_info']['api_hash'],
'lang_code' => $MadelineProto->settings['app_info']['lang_code'],
]
);
var_dump($sendCode);