Method phpdoc

This commit is contained in:
Daniil Gentili 2019-09-18 21:21:34 +02:00
parent 445c647438
commit bbb908ac68
8 changed files with 91 additions and 86 deletions

View File

@ -74,6 +74,17 @@ class AnnotationsBuilder
{ {
\danog\MadelineProto\Logger::log('Creating internal classes...', \danog\MadelineProto\Logger::NOTICE); \danog\MadelineProto\Logger::log('Creating internal classes...', \danog\MadelineProto\Logger::NOTICE);
$handle = \fopen(\dirname(__FILE__).'/InternalDoc.php', 'w'); $handle = \fopen(\dirname(__FILE__).'/InternalDoc.php', 'w');
\fwrite($handle, "<?php namespace danog\\MadelineProto; class InternalDoc extends APIFactory {}");
$class = new \ReflectionClass(API::class);
$methods = $class->getMethods(\ReflectionMethod::IS_STATIC | \ReflectionMethod::IS_PUBLIC);
$ignoreMethods = [];
foreach ($methods as $method) {
$ignoreMethods[$method->getName()] = $method->getName();
}
\fclose($handle);
$handle = \fopen(\dirname(__FILE__).'/InternalDoc.php', 'w');
$internalDoc = []; $internalDoc = [];
foreach ($this->methods->by_id as $id => $data) { foreach ($this->methods->by_id as $id => $data) {
if (!\strpos($data['method'], '.')) { if (!\strpos($data['method'], '.')) {
@ -126,12 +137,15 @@ class AnnotationsBuilder
} }
$internalDoc[$namespace][$method]['return'] = $type; $internalDoc[$namespace][$method]['return'] = $type;
} }
$class = new \ReflectionClass(MTProto::class); $class = new \ReflectionClass(MTProto::class);
$methods = $class->getMethods(\ReflectionMethod::IS_STATIC | \ReflectionMethod::IS_PUBLIC); $methods = $class->getMethods(\ReflectionMethod::IS_STATIC | \ReflectionMethod::IS_PUBLIC);
foreach ($methods as $method) { foreach ($methods as $key => $method) {
$name = $method->getName(); $name = $method->getName();
if ($method == 'method_call_async_read') { if ($method == 'method_call_async_read') {
unset($methods[\array_search('method_call', $methods)]); unset($methods[\array_search('method_call', $methods)]);
} elseif (\strpos($name, '__') === 0) {
unset($methods[$key]);
} elseif (\stripos($name, 'async') !== false) { } elseif (\stripos($name, 'async') !== false) {
if (\strpos($name, '_async') !== false) { if (\strpos($name, '_async') !== false) {
unset($methods[\array_search(\str_ireplace('_async', '', $method), $methods)]); unset($methods[\array_search(\str_ireplace('_async', '', $method), $methods)]);
@ -142,7 +156,13 @@ class AnnotationsBuilder
} }
foreach ($methods as $method) { foreach ($methods as $method) {
$name = $method->getName(); $name = $method->getName();
if (isset($ignoreMethods[$name])) {
continue;
}
$originalName = $name; $originalName = $name;
if ($originalName === 'loop_async') {
$originalName = 'loop';
}
if ($name == 'method_call_async_read') { if ($name == 'method_call_async_read') {
$name = 'method_call'; $name = 'method_call';
@ -153,13 +173,15 @@ class AnnotationsBuilder
$name = \str_ireplace('async', '', $name); $name = \str_ireplace('async', '', $name);
} }
} }
$name = \strpos($name, '__') === 0 ? $name : Tools::from_snake_case($name); $name = Tools::from_snake_case($name);
$name = \str_ireplace(['mtproto', 'api'], ['MTProto', 'API'], $name);
$doc = 'public function '; $doc = 'public function ';
$doc .= $name; $doc .= $name;
$doc .= '('; $doc .= '(';
$paramList = ''; $paramList = '';
$hasVariadic = false;
foreach ($method->getParameters() as $param) { foreach ($method->getParameters() as $param) {
if ($param->allowsNull()) { if ($param->allowsNull()) {
//$doc .= '?'; //$doc .= '?';
@ -168,6 +190,9 @@ class AnnotationsBuilder
if ($type->allowsNull()) { if ($type->allowsNull()) {
$doc .= '?'; $doc .= '?';
} }
if (!$type->isBuiltin()) {
$doc .= '\\';
}
$doc .= $type->getName(); $doc .= $type->getName();
$doc .= ' '; $doc .= ' ';
} }
@ -182,14 +207,18 @@ class AnnotationsBuilder
if ($param->isOptional() && !$param->isVariadic()) { if ($param->isOptional() && !$param->isVariadic()) {
$doc .= ' = '; $doc .= ' = ';
if ($param->isDefaultValueConstant()) { if ($param->isDefaultValueConstant()) {
$doc .= str_replace(['NULL', 'self'], ['null', 'MTProto'], $param->getDefaultValueConstantName()); $doc .= \str_replace(['NULL', 'self'], ['null', 'MTProto'], $param->getDefaultValueConstantName());
} else { } else {
$doc .= str_replace('NULL', 'null', var_export($param->getDefaultValue(), true)); $doc .= \str_replace('NULL', 'null', \var_export($param->getDefaultValue(), true));
} }
} }
$doc .= ', '; $doc .= ', ';
if ($param->isVariadic()) {
$hasVariadic = true;
$paramList .= '...';
}
$paramList .= '$'.$param->getName().', '; $paramList .= '$'.$param->getName().', ';
} }
$doc = \rtrim($doc, ', '); $doc = \rtrim($doc, ', ');
@ -202,8 +231,10 @@ class AnnotationsBuilder
} }
$doc .= $type->getName(); $doc .= $type->getName();
} }
$paramList = $hasVariadic ? "Tools::arr($paramList)" : "[$paramList]";
$doc .= "\n{\n"; $doc .= "\n{\n";
$doc .= " return \$this->__call('$originalName', [$paramList]);\n"; $doc .= " return \$this->__call('$originalName', $paramList);\n";
$doc .= "}\n"; $doc .= "}\n";
$internalDoc['InternalDoc'][$name]['method'] = $method->getDocComment() ?? ''; $internalDoc['InternalDoc'][$name]['method'] = $method->getDocComment() ?? '';

View File

@ -232,12 +232,12 @@ class DataCenter
$DoHHTTPClient = new DefaultClient( $DoHHTTPClient = new DefaultClient(
$this->CookieJar, $this->CookieJar,
new HttpSocketPool( new HttpSocketPool(
new ProxySocketPool( new ProxySocketPool(
function (string $uri, CancellationToken $token = null, ClientConnectContext $ctx = null) { function (string $uri, CancellationToken $token = null, ClientConnectContext $ctx = null) {
return $this->rawConnectAsync($uri, $token, $ctx, true); return $this->rawConnectAsync($uri, $token, $ctx, true);
} }
) )
) )
); );
$DoHConfig = new DoHConfig( $DoHConfig = new DoHConfig(
[ [

View File

@ -4019,16 +4019,6 @@ interface folders
class InternalDoc extends APIFactory class InternalDoc extends APIFactory
{ {
public function __construct(...$params)
{
return $this->__call('__construct', [$params]);
}
public function __sleep()
{
return $this->__call('__sleep', []);
}
public function logger($param, $level = danog\MadelineProto\Logger::NOTICE, $file = null) public function logger($param, $level = danog\MadelineProto\Logger::NOTICE, $file = null)
{ {
return $this->__call('logger', [$param, $level, $file]); return $this->__call('logger', [$param, $level, $file]);
@ -4078,11 +4068,6 @@ class InternalDoc extends APIFactory
return $this->__call('hasAllAuth', []); return $this->__call('hasAllAuth', []);
} }
public function serialize()
{
return $this->__call('serialize', []);
}
public function startLoops() public function startLoops()
{ {
return $this->__call('startLoops', []); return $this->__call('startLoops', []);
@ -4093,16 +4078,6 @@ class InternalDoc extends APIFactory
return $this->__call('stopLoops', []); return $this->__call('stopLoops', []);
} }
public function __wakeup($backtrace)
{
return $this->__call('__wakeup_async', [$backtrace]);
}
public function __destruct()
{
return $this->__call('__destruct', []);
}
public function getSettings($settings, $previousSettings = array ( public function getSettings($settings, $previousSettings = array (
)) ))
{ {
@ -4228,26 +4203,6 @@ class InternalDoc extends APIFactory
{ {
return $this->__call('getTypeMismatchCallbacks', []); return $this->__call('getTypeMismatchCallbacks', []);
} }
public function __debugInfo()
{
return $this->__call('__debugInfo', []);
}
public function init()
{
return $this->__call('initAsync', []);
}
public function setInitPromise($promise)
{
return $this->__call('setInitPromise', [$promise]);
}
public function fetchserializableobject($hash)
{
return $this->__call('fetchserializableobject', [$hash]);
}
/** /**
* Create authorization key. * Create authorization key.
* *
@ -4268,7 +4223,7 @@ class InternalDoc extends APIFactory
* *
* @return bool * @return bool
*/ */
public function checkG(phpseclib\Math\BigInteger $g_a, phpseclib\Math\BigInteger $p): bool public function checkG(\phpseclib\Math\BigInteger $g_a, \phpseclib\Math\BigInteger $p): bool
{ {
return $this->__call('check_G', [$g_a, $p]); return $this->__call('check_G', [$g_a, $p]);
} }
@ -4280,7 +4235,7 @@ class InternalDoc extends APIFactory
* *
* @return boolean * @return boolean
*/ */
public function checkPG(phpseclib\Math\BigInteger $p, phpseclib\Math\BigInteger $g): bool public function checkPG(\phpseclib\Math\BigInteger $p, \phpseclib\Math\BigInteger $g): bool
{ {
return $this->__call('check_p_g', [$p, $g]); return $this->__call('check_p_g', [$p, $g]);
} }
@ -4333,7 +4288,7 @@ class InternalDoc extends APIFactory
* *
* @return \Generator * @return \Generator
*/ */
public function initAuthorizationSocket(string $id, danog\MadelineProto\DataCenterConnection $socket): Generator public function initAuthorizationSocket(string $id, \danog\MadelineProto\DataCenterConnection $socket): Generator
{ {
return $this->__call('init_authorization_socket_async', [$id, $socket]); return $this->__call('init_authorization_socket_async', [$id, $socket]);
} }
@ -4735,12 +4690,12 @@ class InternalDoc extends APIFactory
return $this->__call('handle_encrypted_update_async', [$message, $test]); return $this->__call('handle_encrypted_update_async', [$message, $test]);
} }
public function tryMtprotoV1Decrypt($message_key, $chat_id, $old, $encrypted_data) public function tryMTProtoV1Decrypt($message_key, $chat_id, $old, $encrypted_data)
{ {
return $this->__call('try_mtproto_v1_decrypt', [$message_key, $chat_id, $old, $encrypted_data]); return $this->__call('try_mtproto_v1_decrypt', [$message_key, $chat_id, $old, $encrypted_data]);
} }
public function tryMtprotoV2Decrypt($message_key, $chat_id, $old, $encrypted_data) public function tryMTProtoV2Decrypt($message_key, $chat_id, $old, $encrypted_data)
{ {
return $this->__call('try_mtproto_v2_decrypt', [$message_key, $chat_id, $old, $encrypted_data]); return $this->__call('try_mtproto_v2_decrypt', [$message_key, $chat_id, $old, $encrypted_data]);
} }
@ -4857,7 +4812,7 @@ class InternalDoc extends APIFactory
return $this->__call('parse_reply_markup', [$markup]); return $this->__call('parse_reply_markup', [$markup]);
} }
public function mTProtoToBotAPI($data, $sent_arguments = array ( public function MTProtoToBotAPI($data, $sent_arguments = array (
)) ))
{ {
return $this->__call('MTProto_to_botAPI_async', [$data, $sent_arguments]); return $this->__call('MTProto_to_botAPI_async', [$data, $sent_arguments]);
@ -4918,7 +4873,7 @@ class InternalDoc extends APIFactory
return $this->__call('rle_encode', [$string]); return $this->__call('rle_encode', [$string]);
} }
public function photosizeToBotapi($photoSize, $photo, $thumbnail = false) public function photosizeToBotAPI($photoSize, $photo, $thumbnail = false)
{ {
return $this->__call('photosize_to_botapi_async', [$photoSize, $photo, $thumbnail]); return $this->__call('photosize_to_botapi_async', [$photoSize, $photo, $thumbnail]);
} }
@ -4958,17 +4913,17 @@ class InternalDoc extends APIFactory
return $this->__call('tdcli_to_td', [$params, $key]); return $this->__call('tdcli_to_td', [$params, $key]);
} }
public function tdToMtproto($params) public function tdToMTProto($params)
{ {
return $this->__call('td_to_mtproto_async', [$params]); return $this->__call('td_to_mtproto_async', [$params]);
} }
public function mtprotoToTdcli($params) public function MTProtoToTdcli($params)
{ {
return $this->__call('mtproto_to_tdcli_async', [$params]); return $this->__call('mtproto_to_tdcli_async', [$params]);
} }
public function mtprotoToTd(&$params) public function MTProtoToTd(&$params)
{ {
return $this->__call('mtproto_to_td_async', [$params]); return $this->__call('mtproto_to_td_async', [$params]);
} }
@ -5126,10 +5081,10 @@ class InternalDoc extends APIFactory
return $this->__call('is_array_or_alike', [$var]); return $this->__call('is_array_or_alike', [$var]);
} }
/** /**
* Convert to camelCase * Convert to camelCase.
* *
* @param string $input * @param string $input
* *
* @return string * @return string
*/ */
public function fromSnakeCase(string $input): string public function fromSnakeCase(string $input): string
@ -5137,16 +5092,27 @@ class InternalDoc extends APIFactory
return $this->__call('from_snake_case', [$input]); return $this->__call('from_snake_case', [$input]);
} }
/** /**
* Convert to snake_case * Convert to snake_case.
* *
* @param string $input * @param string $input
* *
* @return string * @return string
*/ */
public function fromCamelCase(string $input): string public function fromCamelCase(string $input): string
{ {
return $this->__call('from_camel_case', [$input]); return $this->__call('from_camel_case', [$input]);
} }
/**
* Create array
*
* @param mixed ...$params Params
*
* @return array
*/
public function arr(...$params): array
{
return $this->__call('arr', Tools::arr(...$params));
}
public function requestCall($user) public function requestCall($user)
{ {
@ -5283,7 +5249,7 @@ class InternalDoc extends APIFactory
public function loop($max_forks = 0) public function loop($max_forks = 0)
{ {
return $this->__call('loop_async', [$max_forks]); return $this->__call('loop', [$max_forks]);
} }
public function closeConnection($message = 'OK!') public function closeConnection($message = 'OK!')

View File

@ -552,7 +552,6 @@ class MTProto extends AsyncConstruct implements TLCallback
} }
public function a(callable $a, ?string $b = null, $c = null, $d = 2, $e = self::METHOD_BEFORE_CALLBACK): ?string public function a(callable $a, ?string $b = null, $c = null, $d = 2, $e = self::METHOD_BEFORE_CALLBACK): ?string
{ {
} }
/** /**
* Get all datacenter connections. * Get all datacenter connections.

View File

@ -21,7 +21,6 @@ namespace danog\MadelineProto\MTProtoSession;
use Amp\Loop; use Amp\Loop;
use danog\MadelineProto\MTProto; use danog\MadelineProto\MTProto;
use danog\MadelineProto\TL\PrettyException;
/** /**
* Manages responses. * Manages responses.
@ -309,11 +308,11 @@ trait ResponseHandler
} }
/** /**
* Reject request with exception * Reject request with exception.
* *
* @param array $request Request * @param array $request Request
* @param \Throwable $data Exception * @param \Throwable $data Exception
* *
* @return void * @return void
*/ */
public function handle_reject(array &$request, \Throwable $data) public function handle_reject(array &$request, \Throwable $data)

View File

@ -19,8 +19,6 @@
namespace danog\MadelineProto\TL; namespace danog\MadelineProto\TL;
use danog\MadelineProto\Tools;
/** /**
* Handle async stack traces. * Handle async stack traces.
*/ */

View File

@ -450,21 +450,21 @@ trait Tools
} }
/** /**
* Convert to camelCase * Convert to camelCase.
* *
* @param string $input * @param string $input
* *
* @return string * @return string
*/ */
public static function from_snake_case(string $input): string public static function from_snake_case(string $input): string
{ {
return lcfirst(str_replace('_', '', ucwords($input, '_'))); return \lcfirst(\str_replace('_', '', \ucwords($input, '_')));
} }
/** /**
* Convert to snake_case * Convert to snake_case.
* *
* @param string $input * @param string $input
* *
* @return string * @return string
*/ */
public static function from_camel_case(string $input): string public static function from_camel_case(string $input): string
@ -477,4 +477,16 @@ trait Tools
return \implode('_', $ret); return \implode('_', $ret);
} }
/**
* Create array
*
* @param mixed ...$params Params
*
* @return array
*/
public static function arr(...$params): array
{
return $params;
}
} }

View File

@ -20,24 +20,24 @@
namespace danog\MadelineProto; namespace danog\MadelineProto;
/** /**
* Represents a piece of a coroutine stack trace * Represents a piece of a coroutine stack trace.
*/ */
class Trace class Trace
{ {
/** /**
* Next piece of the stack trace * Next piece of the stack trace.
* *
* @var Trace * @var Trace
*/ */
private $next; private $next;
/** /**
* Current stack trace frames * Current stack trace frames.
* *
* @var array * @var array
*/ */
private $frames = []; private $frames = [];
/** /**
* Create trace * Create trace.
* *
* @param array $frames Current frames * @param array $frames Current frames
* @param self $next Next trace * @param self $next Next trace
@ -49,17 +49,17 @@ class Trace
} }
/** /**
* Get stack trace * Get stack trace.
* *
* @return array * @return array
*/ */
public function getTrace(): array public function getTrace(): array
{ {
return iterator_to_array($this->getTraceGenerator()); return \iterator_to_array($this->getTraceGenerator());
} }
/** /**
* Get stack trace * Get stack trace.
* *
* @return \Generator * @return \Generator
*/ */
@ -72,4 +72,4 @@ class Trace
yield from $this->next->getTraceGenerator(); yield from $this->next->getTraceGenerator();
} }
} }
} }