Apply fixes from StyleCI

This commit is contained in:
Daniil Gentili 2017-01-02 18:52:29 +00:00 committed by StyleCI Bot
parent ec23e14c68
commit 43ba430b6d
4 changed files with 54 additions and 39 deletions

View File

@ -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',
],
];

View File

@ -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)<a name="'.$method.'"></a>
';
$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.'\];<a name="'.$constructor.'"></a>
';
@ -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!');
}
}

View File

@ -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('<i', \danog\PHP\Struct::pack('<I', hexdec(preg_replace(['/^[^#]+#/', '/\s.+/'], '', $line))))[0];
$TL_dict[$type][$key]['params'] = [];
$TL_dict[$type][$key]['type'] = preg_replace(['/.+\s/', '/;/'], '', $line);
foreach (explode(' ', preg_replace(['/^[^\s]+\s/', '/=\s[^\s]+/', '/\s$/'], '', $line)) as $param) {
if ($param == '') continue;
if ($param[0] == '{') continue;
if ($param == '') {
continue;
}
if ($param[0] == '{') {
continue;
}
$explode = explode(':', $param);
$TL_dict[$type][$key]['params'][] = ['name' => $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);

View File

@ -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');