mirror of
https://github.com/danog/MadelineProto.git
synced 2025-01-22 05:31:18 +01:00
Apply fixes from StyleCI
This commit is contained in:
parent
ec23e14c68
commit
43ba430b6d
@ -24,28 +24,28 @@ description: PHP implementation of telegram\'s MTProto protocol
|
|||||||
|
|
||||||
$docs = [
|
$docs = [
|
||||||
[
|
[
|
||||||
'tl_schema' => ['mtproto' => __DIR__.'/src/danog/MadelineProto/TL_mtproto_v1.json'],
|
'tl_schema' => ['mtproto' => __DIR__.'/src/danog/MadelineProto/TL_mtproto_v1.json'],
|
||||||
'title' => 'MadelineProto API documentation (mtproto)',
|
'title' => 'MadelineProto API documentation (mtproto)',
|
||||||
'description' => 'MadelineProto API documentation (mtproto)',
|
'description' => 'MadelineProto API documentation (mtproto)',
|
||||||
'output_dir' => __DIR__.'/docs/MTProto_docs'
|
'output_dir' => __DIR__.'/docs/MTProto_docs',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'tl_schema' => ['telegram' => __DIR__.'/src/danog/MadelineProto/TL_telegram_v57.json'],
|
'tl_schema' => ['telegram' => __DIR__.'/src/danog/MadelineProto/TL_telegram_v57.json'],
|
||||||
'title' => 'MadelineProto API documentation (layer 57)',
|
'title' => 'MadelineProto API documentation (layer 57)',
|
||||||
'description' => 'MadelineProto API documentation (layer 57)',
|
'description' => 'MadelineProto API documentation (layer 57)',
|
||||||
'output_dir' => __DIR__.'/docs/API_docs'
|
'output_dir' => __DIR__.'/docs/API_docs',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'tl_schema' => ['telegram' => __DIR__.'/src/danog/MadelineProto/TL_telegram_v55.json'],
|
'tl_schema' => ['telegram' => __DIR__.'/src/danog/MadelineProto/TL_telegram_v55.json'],
|
||||||
'title' => 'MadelineProto API documentation (layer 55)',
|
'title' => 'MadelineProto API documentation (layer 55)',
|
||||||
'description' => 'MadelineProto API documentation (layer 55)',
|
'description' => 'MadelineProto API documentation (layer 55)',
|
||||||
'output_dir' => __DIR__.'/docs/API_docs_55'
|
'output_dir' => __DIR__.'/docs/API_docs_55',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'tl_schema' => ['telegram' => __DIR__.'/src/danog/MadelineProto/TL_telegram_v46.tl'],
|
'tl_schema' => ['telegram' => __DIR__.'/src/danog/MadelineProto/TL_telegram_v46.tl'],
|
||||||
'title' => 'MadelineProto API documentation (layer 46)',
|
'title' => 'MadelineProto API documentation (layer 46)',
|
||||||
'description' => 'MadelineProto API documentation (layer 46)',
|
'description' => 'MadelineProto API documentation (layer 46)',
|
||||||
'output_dir' => __DIR__.'/docs/API_docs_46'
|
'output_dir' => __DIR__.'/docs/API_docs_46',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -15,14 +15,19 @@ namespace danog\MadelineProto;
|
|||||||
class DocsBuilder
|
class DocsBuilder
|
||||||
{
|
{
|
||||||
use \danog\MadelineProto\TL\TL;
|
use \danog\MadelineProto\TL\TL;
|
||||||
public function __construct($settings) {
|
|
||||||
|
public function __construct($settings)
|
||||||
|
{
|
||||||
$this->construct_TL($settings['tl_schema']);
|
$this->construct_TL($settings['tl_schema']);
|
||||||
$this->settings = $settings;
|
$this->settings = $settings;
|
||||||
if (!file_exists($this->settings['output_dir'])) mkdir($this->settings['output_dir']);
|
if (!file_exists($this->settings['output_dir'])) {
|
||||||
|
mkdir($this->settings['output_dir']);
|
||||||
|
}
|
||||||
chdir($this->settings['output_dir']);
|
chdir($this->settings['output_dir']);
|
||||||
|
|
||||||
}
|
}
|
||||||
public function mk_docs() {
|
|
||||||
|
public function mk_docs()
|
||||||
|
{
|
||||||
$types = [];
|
$types = [];
|
||||||
|
|
||||||
\danog\MadelineProto\Logger::log('Generating documentation index...');
|
\danog\MadelineProto\Logger::log('Generating documentation index...');
|
||||||
@ -69,7 +74,7 @@ description: '.$this->settings['description'].'
|
|||||||
if (!in_array($key, $types[$real_type]['methods'])) {
|
if (!in_array($key, $types[$real_type]['methods'])) {
|
||||||
$types[$real_type]['methods'][] = $key;
|
$types[$real_type]['methods'][] = $key;
|
||||||
}
|
}
|
||||||
|
|
||||||
$params = '';
|
$params = '';
|
||||||
foreach ($this->methods->params[$key] as $param) {
|
foreach ($this->methods->params[$key] as $param) {
|
||||||
if (in_array($param['name'], ['flags', 'random_id'])) {
|
if (in_array($param['name'], ['flags', 'random_id'])) {
|
||||||
@ -94,15 +99,15 @@ description: '.$this->settings['description'].'
|
|||||||
'['.
|
'['.
|
||||||
str_replace('_', '\_', $ptype).
|
str_replace('_', '\_', $ptype).
|
||||||
'](../'.$link_type.'/'.$ptype.'.md)';
|
'](../'.$link_type.'/'.$ptype.'.md)';
|
||||||
|
|
||||||
$params .= (isset($param['subtype']) ? '\['.$ptype.'\]' : $ptype).', ';
|
$params .= (isset($param['subtype']) ? '\['.$ptype.'\]' : $ptype).', ';
|
||||||
}
|
}
|
||||||
$md_method = '['.$real_method.']('.$method.'.md)';
|
$md_method = '['.$real_method.']('.$method.'.md)';
|
||||||
|
|
||||||
$methods[$method] = '$MadelineProto->'.$md_method.'(\['.$params.'\]) == [$'.str_replace('_', '\_', $type).'](../types/'.$real_type.'.md)<a name="'.$method.'"></a>
|
$methods[$method] = '$MadelineProto->'.$md_method.'(\['.$params.'\]) == [$'.str_replace('_', '\_', $type).'](../types/'.$real_type.'.md)<a name="'.$method.'"></a>
|
||||||
|
|
||||||
';
|
';
|
||||||
|
|
||||||
$params = '';
|
$params = '';
|
||||||
$table = empty($this->methods->params[$key]) ? '' : '### Parameters:
|
$table = empty($this->methods->params[$key]) ? '' : '### Parameters:
|
||||||
|
|
||||||
@ -206,11 +211,9 @@ description: List of methods
|
|||||||
$type = str_replace(['.', '<', '>'], ['_', '_of_', ''], $this->constructors->type[$key]);
|
$type = str_replace(['.', '<', '>'], ['_', '_of_', ''], $this->constructors->type[$key]);
|
||||||
$real_type = preg_replace('/.*_of_/', '', $type);
|
$real_type = preg_replace('/.*_of_/', '', $type);
|
||||||
|
|
||||||
|
|
||||||
$constructor = str_replace(['.', '<', '>'], ['_', '_of_', ''], $constructor);
|
$constructor = str_replace(['.', '<', '>'], ['_', '_of_', ''], $constructor);
|
||||||
$real_constructor = preg_replace('/.*_of_/', '', $constructor);
|
$real_constructor = preg_replace('/.*_of_/', '', $constructor);
|
||||||
|
|
||||||
|
|
||||||
$params = '';
|
$params = '';
|
||||||
foreach ($this->constructors->params[$key] as $param) {
|
foreach ($this->constructors->params[$key] as $param) {
|
||||||
if (in_array($param['name'], ['flags', 'random_id'])) {
|
if (in_array($param['name'], ['flags', 'random_id'])) {
|
||||||
@ -234,17 +237,17 @@ description: List of methods
|
|||||||
if (preg_match('/%/', $ptype)) {
|
if (preg_match('/%/', $ptype)) {
|
||||||
$ptype = $this->constructors->find_by_type(str_replace('%', '', $ptype))['predicate'];
|
$ptype = $this->constructors->find_by_type(str_replace('%', '', $ptype))['predicate'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$params .= "'".$param['name']."' => ";
|
$params .= "'".$param['name']."' => ";
|
||||||
$ptype =
|
$ptype =
|
||||||
'['.
|
'['.
|
||||||
str_replace('_', '\_', $ptype).
|
str_replace('_', '\_', $ptype).
|
||||||
'](../'.$link_type.'/'.$ptype.'.md)';
|
'](../'.$link_type.'/'.$ptype.'.md)';
|
||||||
|
|
||||||
$params .= (isset($param['subtype']) ? '\['.$ptype.'\]' : $ptype).', ';
|
$params .= (isset($param['subtype']) ? '\['.$ptype.'\]' : $ptype).', ';
|
||||||
}
|
}
|
||||||
$md_constructor = str_replace('_', '\_', $constructor);
|
$md_constructor = str_replace('_', '\_', $constructor);
|
||||||
|
|
||||||
$constructors[$constructor] = '[$'.$md_constructor.'](../constructors/'.$real_constructor.'.md) = \['.$params.'\];<a name="'.$constructor.'"></a>
|
$constructors[$constructor] = '[$'.$md_constructor.'](../constructors/'.$real_constructor.'.md) = \['.$params.'\];<a name="'.$constructor.'"></a>
|
||||||
|
|
||||||
';
|
';
|
||||||
@ -266,7 +269,7 @@ description: List of methods
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$ptype = str_replace('.', '_', $param[isset($param['subtype']) ? 'subtype' : 'type']);
|
$ptype = str_replace('.', '_', $param[isset($param['subtype']) ? 'subtype' : 'type']);
|
||||||
|
|
||||||
$link_type = 'types';
|
$link_type = 'types';
|
||||||
if (isset($param['subtype'])) {
|
if (isset($param['subtype'])) {
|
||||||
if ($param['type'] == 'vector') {
|
if ($param['type'] == 'vector') {
|
||||||
@ -543,6 +546,6 @@ description: Represents a boolean.
|
|||||||
|
|
||||||
Represents a boolean.');
|
Represents a boolean.');
|
||||||
|
|
||||||
\danog\MadelineProto\Logger::log('Done!');
|
\danog\MadelineProto\Logger::log('Done!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,24 +29,39 @@ trait TL
|
|||||||
$tl_file = explode("\n", $filec);
|
$tl_file = explode("\n", $filec);
|
||||||
$key = 0;
|
$key = 0;
|
||||||
foreach ($tl_file as $line) {
|
foreach ($tl_file as $line) {
|
||||||
if ($line == '') continue;
|
if ($line == '') {
|
||||||
if ($line == '---functions---') { $type = 'methods'; continue; }
|
continue;
|
||||||
if (!preg_match('/^[^\s]+#/', $line)) continue;
|
}
|
||||||
if (preg_match('/^vector#/', $line)) continue;
|
if ($line == '---functions---') {
|
||||||
|
$type = 'methods';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!preg_match('/^[^\s]+#/', $line)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (preg_match('/^vector#/', $line)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$TL_dict[$type][$key][$type == 'constructors' ? 'predicate' : 'method'] = preg_replace('/#.*/', '', $line);
|
$TL_dict[$type][$key][$type == 'constructors' ? 'predicate' : 'method'] = preg_replace('/#.*/', '', $line);
|
||||||
$TL_dict[$type][$key]['id'] = \danog\PHP\Struct::unpack('<i', \danog\PHP\Struct::pack('<I', hexdec(preg_replace(['/^[^#]+#/', '/\s.+/'], '', $line))))[0];
|
$TL_dict[$type][$key]['id'] = \danog\PHP\Struct::unpack('<i', \danog\PHP\Struct::pack('<I', hexdec(preg_replace(['/^[^#]+#/', '/\s.+/'], '', $line))))[0];
|
||||||
$TL_dict[$type][$key]['params'] = [];
|
$TL_dict[$type][$key]['params'] = [];
|
||||||
$TL_dict[$type][$key]['type'] = preg_replace(['/.+\s/', '/;/'], '', $line);
|
$TL_dict[$type][$key]['type'] = preg_replace(['/.+\s/', '/;/'], '', $line);
|
||||||
foreach (explode(' ', preg_replace(['/^[^\s]+\s/', '/=\s[^\s]+/', '/\s$/'], '', $line)) as $param) {
|
foreach (explode(' ', preg_replace(['/^[^\s]+\s/', '/=\s[^\s]+/', '/\s$/'], '', $line)) as $param) {
|
||||||
if ($param == '') continue;
|
if ($param == '') {
|
||||||
if ($param[0] == '{') continue;
|
continue;
|
||||||
|
}
|
||||||
|
if ($param[0] == '{') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$explode = explode(':', $param);
|
$explode = explode(':', $param);
|
||||||
$TL_dict[$type][$key]['params'][] = ['name' => $explode[0], 'type' => $explode[1]];
|
$TL_dict[$type][$key]['params'][] = ['name' => $explode[0], 'type' => $explode[1]];
|
||||||
}
|
}
|
||||||
$key++;
|
$key++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (empty($TL_dict) || empty($TL_dict['constructors']) || empty($TL_dict['methods'])) throw new Exception('Invalid source file was provided: '.$file);
|
if (empty($TL_dict) || empty($TL_dict['constructors']) || empty($TL_dict['methods'])) {
|
||||||
|
throw new Exception('Invalid source file was provided: '.$file);
|
||||||
|
}
|
||||||
\danog\MadelineProto\Logger::log('Translating objects...');
|
\danog\MadelineProto\Logger::log('Translating objects...');
|
||||||
foreach ($TL_dict['constructors'] as $elem) {
|
foreach ($TL_dict['constructors'] as $elem) {
|
||||||
$this->constructors->add($elem, $type);
|
$this->constructors->add($elem, $type);
|
||||||
|
@ -32,7 +32,7 @@ if (file_exists('number.php') && $MadelineProto === false) {
|
|||||||
$sentCode = $MadelineProto->phone_login($number);
|
$sentCode = $MadelineProto->phone_login($number);
|
||||||
\danog\MadelineProto\Logger::log($sentCode);
|
\danog\MadelineProto\Logger::log($sentCode);
|
||||||
echo 'Enter the code you received: ';
|
echo 'Enter the code you received: ';
|
||||||
$code = fgets(STDIN, (isset($sentCode['type']['length']) ? $sentCode['type']['length'] : 5)+1);
|
$code = fgets(STDIN, (isset($sentCode['type']['length']) ? $sentCode['type']['length'] : 5) + 1);
|
||||||
$authorization = $MadelineProto->complete_phone_login($code);
|
$authorization = $MadelineProto->complete_phone_login($code);
|
||||||
\danog\MadelineProto\Logger::log($authorization);
|
\danog\MadelineProto\Logger::log($authorization);
|
||||||
echo 'Serializing MadelineProto to session.madeline...'.PHP_EOL;
|
echo 'Serializing MadelineProto to session.madeline...'.PHP_EOL;
|
||||||
@ -91,7 +91,7 @@ if (file_exists('number.php') && $MadelineProto === false) {
|
|||||||
$sentCode = $MadelineProto->phone_login($number);
|
$sentCode = $MadelineProto->phone_login($number);
|
||||||
\danog\MadelineProto\Logger::log($sentCode);
|
\danog\MadelineProto\Logger::log($sentCode);
|
||||||
echo 'Enter the code you received: ';
|
echo 'Enter the code you received: ';
|
||||||
$code = fgets(STDIN, (isset($sentCode['type']['length']) ? $sentCode['type']['length'] : 5)+1);
|
$code = fgets(STDIN, (isset($sentCode['type']['length']) ? $sentCode['type']['length'] : 5) + 1);
|
||||||
|
|
||||||
$authorization = $MadelineProto->complete_phone_login($code);
|
$authorization = $MadelineProto->complete_phone_login($code);
|
||||||
\danog\MadelineProto\Logger::log($authorization);
|
\danog\MadelineProto\Logger::log($authorization);
|
||||||
@ -100,6 +100,3 @@ if (file_exists('number.php') && $MadelineProto === false) {
|
|||||||
}
|
}
|
||||||
echo 'Deserializing MadelineProto from session_old.madeline...'.PHP_EOL;
|
echo 'Deserializing MadelineProto from session_old.madeline...'.PHP_EOL;
|
||||||
$MadelineProto = \danog\MadelineProto\Serialization::deserialize('session_old.madeline');
|
$MadelineProto = \danog\MadelineProto\Serialization::deserialize('session_old.madeline');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user