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:
parent
b28aab6359
commit
e6093e65ac
@ -15,14 +15,15 @@ namespace danog\MadelineProto;
|
|||||||
class API extends Tools
|
class API extends Tools
|
||||||
{
|
{
|
||||||
public $session;
|
public $session;
|
||||||
|
public $settings;
|
||||||
public function __construct($params = [])
|
public function __construct($params = [])
|
||||||
{
|
{
|
||||||
set_error_handler(['\danog\MadelineProto\Exception', 'ExceptionErrorHandler']);
|
set_error_handler(['\danog\MadelineProto\Exception', 'ExceptionErrorHandler']);
|
||||||
$this->session = new MTProto($params);
|
$this->session = new MTProto($params);
|
||||||
|
$this->settings = &$this->session->settings;
|
||||||
|
|
||||||
\danog\MadelineProto\Logger::log('Running APIFactory...');
|
\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($method[1])) {
|
||||||
if (!isset($this->{$method[0]})) {
|
if (!isset($this->{$method[0]})) {
|
||||||
$this->{$method[0]} = new APIFactory($method[0], $this->session);
|
$this->{$method[0]} = new APIFactory($method[0], $this->session);
|
||||||
@ -32,10 +33,10 @@ class API extends Tools
|
|||||||
}
|
}
|
||||||
|
|
||||||
\danog\MadelineProto\Logger::log('Ping...');
|
\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('Pong: '.$ping['ping_id']);
|
||||||
\danog\MadelineProto\Logger::log('Getting future salts...');
|
\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!');
|
\danog\MadelineProto\Logger::log('MadelineProto is ready!');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,9 +48,9 @@ class API extends Tools
|
|||||||
|
|
||||||
public function __call($name, $arguments)
|
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!");
|
throw new Exception("The called method doesn't exist!");
|
||||||
}
|
}
|
||||||
return $this->session->method_call($name, $arguments);
|
return $this->session->method_call($name, $arguments[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ class APIFactory
|
|||||||
if (!in_array($name, $this->allowed_methods)) {
|
if (!in_array($name, $this->allowed_methods)) {
|
||||||
throw new Exception("The called method doesn't exist!");
|
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]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -125,7 +125,6 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
|
|||||||
$this->future_salts = [];
|
$this->future_salts = [];
|
||||||
|
|
||||||
$this->switch_dc($this->settings['connection_settings']['default_dc'], true);
|
$this->switch_dc($this->settings['connection_settings']['default_dc'], true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setup_logger()
|
public function setup_logger()
|
||||||
|
@ -45,7 +45,8 @@ class TL extends \danog\MadelineProto\Tools
|
|||||||
$z = new \danog\MadelineProto\TL\TLMethod($elem);
|
$z = new \danog\MadelineProto\TL\TLMethod($elem);
|
||||||
$this->method_id[$z->id] = $z;
|
$this->method_id[$z->id] = $z;
|
||||||
$this->method_name[$z->method] = $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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,9 +21,9 @@ if (file_exists('number.php')) {
|
|||||||
[
|
[
|
||||||
'phone_number' => $number,
|
'phone_number' => $number,
|
||||||
'sms_type' => 5,
|
'sms_type' => 5,
|
||||||
'api_id' => $this->settings['app_info']['api_id'],
|
'api_id' => $MadelineProto->settings['app_info']['api_id'],
|
||||||
'api_hash' => $this->settings['app_info']['api_hash'],
|
'api_hash' => $MadelineProto->settings['app_info']['api_hash'],
|
||||||
'lang_code' => $this->settings['app_info']['lang_code'],
|
'lang_code' => $MadelineProto->settings['app_info']['lang_code'],
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
var_dump($sendCode);
|
var_dump($sendCode);
|
||||||
|
Loading…
Reference in New Issue
Block a user