diff --git a/build_docs.php b/build_docs.php
index eebd3e31..386c9a4a 100755
--- a/build_docs.php
+++ b/build_docs.php
@@ -24,28 +24,28 @@ description: PHP implementation of telegram\'s MTProto protocol
$docs = [
[
- 'tl_schema' => ['mtproto' => __DIR__.'/src/danog/MadelineProto/TL_mtproto_v1.json'],
- 'title' => 'MadelineProto API documentation (mtproto)',
+ 'tl_schema' => ['mtproto' => __DIR__.'/src/danog/MadelineProto/TL_mtproto_v1.json'],
+ 'title' => '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'],
- 'title' => 'MadelineProto API documentation (layer 57)',
+ 'tl_schema' => ['telegram' => __DIR__.'/src/danog/MadelineProto/TL_telegram_v57.json'],
+ 'title' => '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'],
- 'title' => 'MadelineProto API documentation (layer 55)',
+ 'tl_schema' => ['telegram' => __DIR__.'/src/danog/MadelineProto/TL_telegram_v55.json'],
+ 'title' => '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'],
- 'title' => 'MadelineProto API documentation (layer 46)',
+ 'tl_schema' => ['telegram' => __DIR__.'/src/danog/MadelineProto/TL_telegram_v46.tl'],
+ 'title' => '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',
],
];
diff --git a/src/danog/MadelineProto/DocsBuilder.php b/src/danog/MadelineProto/DocsBuilder.php
index e30533ad..69e7e043 100755
--- a/src/danog/MadelineProto/DocsBuilder.php
+++ b/src/danog/MadelineProto/DocsBuilder.php
@@ -15,14 +15,19 @@ namespace danog\MadelineProto;
class DocsBuilder
{
use \danog\MadelineProto\TL\TL;
- public function __construct($settings) {
+
+ public function __construct($settings)
+ {
$this->construct_TL($settings['tl_schema']);
$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']);
-
}
- public function mk_docs() {
+
+ public function mk_docs()
+ {
$types = [];
\danog\MadelineProto\Logger::log('Generating documentation index...');
@@ -69,7 +74,7 @@ description: '.$this->settings['description'].'
if (!in_array($key, $types[$real_type]['methods'])) {
$types[$real_type]['methods'][] = $key;
}
-
+
$params = '';
foreach ($this->methods->params[$key] as $param) {
if (in_array($param['name'], ['flags', 'random_id'])) {
@@ -94,15 +99,15 @@ description: '.$this->settings['description'].'
'['.
str_replace('_', '\_', $ptype).
'](../'.$link_type.'/'.$ptype.'.md)';
-
+
$params .= (isset($param['subtype']) ? '\['.$ptype.'\]' : $ptype).', ';
}
$md_method = '['.$real_method.']('.$method.'.md)';
-
+
$methods[$method] = '$MadelineProto->'.$md_method.'(\['.$params.'\]) == [$'.str_replace('_', '\_', $type).'](../types/'.$real_type.'.md)
';
-
+
$params = '';
$table = empty($this->methods->params[$key]) ? '' : '### Parameters:
@@ -206,11 +211,9 @@ description: List of methods
$type = str_replace(['.', '<', '>'], ['_', '_of_', ''], $this->constructors->type[$key]);
$real_type = preg_replace('/.*_of_/', '', $type);
-
$constructor = str_replace(['.', '<', '>'], ['_', '_of_', ''], $constructor);
$real_constructor = preg_replace('/.*_of_/', '', $constructor);
-
$params = '';
foreach ($this->constructors->params[$key] as $param) {
if (in_array($param['name'], ['flags', 'random_id'])) {
@@ -234,17 +237,17 @@ description: List of methods
if (preg_match('/%/', $ptype)) {
$ptype = $this->constructors->find_by_type(str_replace('%', '', $ptype))['predicate'];
}
-
+
$params .= "'".$param['name']."' => ";
$ptype =
'['.
str_replace('_', '\_', $ptype).
'](../'.$link_type.'/'.$ptype.'.md)';
-
+
$params .= (isset($param['subtype']) ? '\['.$ptype.'\]' : $ptype).', ';
}
$md_constructor = str_replace('_', '\_', $constructor);
-
+
$constructors[$constructor] = '[$'.$md_constructor.'](../constructors/'.$real_constructor.'.md) = \['.$params.'\];
';
@@ -266,7 +269,7 @@ description: List of methods
continue;
}
$ptype = str_replace('.', '_', $param[isset($param['subtype']) ? 'subtype' : 'type']);
-
+
$link_type = 'types';
if (isset($param['subtype'])) {
if ($param['type'] == 'vector') {
@@ -543,6 +546,6 @@ description: Represents a boolean.
Represents a boolean.');
-\danog\MadelineProto\Logger::log('Done!');
+ \danog\MadelineProto\Logger::log('Done!');
}
}
diff --git a/src/danog/MadelineProto/TL/TL.php b/src/danog/MadelineProto/TL/TL.php
index 0de9e874..c2c88b65 100644
--- a/src/danog/MadelineProto/TL/TL.php
+++ b/src/danog/MadelineProto/TL/TL.php
@@ -29,24 +29,39 @@ trait TL
$tl_file = explode("\n", $filec);
$key = 0;
foreach ($tl_file as $line) {
- if ($line == '') continue;
- if ($line == '---functions---') { $type = 'methods'; continue; }
- if (!preg_match('/^[^\s]+#/', $line)) continue;
- if (preg_match('/^vector#/', $line)) continue;
+ if ($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]['id'] = \danog\PHP\Struct::unpack(' $explode[0], 'type' => $explode[1]];
}
$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...');
foreach ($TL_dict['constructors'] as $elem) {
$this->constructors->add($elem, $type);
diff --git a/testing.php b/testing.php
index a657add8..7b689f0d 100755
--- a/testing.php
+++ b/testing.php
@@ -32,7 +32,7 @@ if (file_exists('number.php') && $MadelineProto === false) {
$sentCode = $MadelineProto->phone_login($number);
\danog\MadelineProto\Logger::log($sentCode);
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);
\danog\MadelineProto\Logger::log($authorization);
echo 'Serializing MadelineProto to session.madeline...'.PHP_EOL;
@@ -91,7 +91,7 @@ if (file_exists('number.php') && $MadelineProto === false) {
$sentCode = $MadelineProto->phone_login($number);
\danog\MadelineProto\Logger::log($sentCode);
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);
\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;
$MadelineProto = \danog\MadelineProto\Serialization::deserialize('session_old.madeline');
-
-
-