diff --git a/.php_cs.dist b/.php_cs.dist index 50a431d5..a75477be 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -4,7 +4,8 @@ $config = new Amp\CodeStyle\Config(); $config->getFinder() ->in(__DIR__ . '/src') ->in(__DIR__ . '/tests') - ->in(__DIR__ . '/userbots') + ->in(__DIR__ . '/examples') + ->in(__DIR__ . '/tools') ->in(__DIR__); $cacheDir = getenv('TRAVIS') ? getenv('HOME') . '/.php-cs-fixer' : __DIR__; diff --git a/src/danog/MadelineProto/AnnotationsBuilder.php b/src/danog/MadelineProto/AnnotationsBuilder.php index 8a520594..4f73c9db 100644 --- a/src/danog/MadelineProto/AnnotationsBuilder.php +++ b/src/danog/MadelineProto/AnnotationsBuilder.php @@ -30,7 +30,7 @@ class AnnotationsBuilder public function __construct($logger, $settings) { $this->logger = $logger; - $this->construct_TL($settings['tl_schema']); + $this->constructTL($settings['tl_schema']); $this->settings = $settings; } diff --git a/src/danog/MadelineProto/DocsBuilder.php b/src/danog/MadelineProto/DocsBuilder.php index d2220296..6c0b55f1 100644 --- a/src/danog/MadelineProto/DocsBuilder.php +++ b/src/danog/MadelineProto/DocsBuilder.php @@ -32,7 +32,7 @@ class DocsBuilder { $this->logger = $logger; \set_error_handler(['\\danog\\MadelineProto\\Exception', 'ExceptionErrorHandler']); - $this->construct_TL($settings['tl_schema']); + $this->constructTL($settings['tl_schema']); if (isset($settings['tl_schema']['td']) && !isset($settings['tl_schema']['telegram'])) { $this->constructors = $this->td_constructors; $this->methods = $this->td_methods; @@ -77,7 +77,7 @@ image: https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png [Constructors](constructors/) [Types](types/)'); - $this->mk_methodS(); + $this->mkmethodS(); $this->mkConstructors(); foreach (\glob('types/*') as $unlink) { \unlink($unlink); diff --git a/src/danog/MadelineProto/InternalDoc.php b/src/danog/MadelineProto/InternalDoc.php index 71e75623..4b7ab60a 100644 --- a/src/danog/MadelineProto/InternalDoc.php +++ b/src/danog/MadelineProto/InternalDoc.php @@ -4302,6 +4302,22 @@ class InternalDoc extends APIFactory { return $this->__call(__FUNCTION__, [$id, $extra]); } + /** + * Synchronous wrapper for method_call. + * + * @param string $method Method name + * @param array $args Arguments + * @param array $aargs Additional arguments + * + * @return array + */ + public function methodCall(string $method, $args = [ + ], array $aargs = [ + 'msg_id' => null, + ], array $extra = []) + { + return $this->__call(__FUNCTION__, [$method, $args, $aargs, $extra]); + } /** * Call method and wait asynchronously for response. * @@ -4313,7 +4329,7 @@ class InternalDoc extends APIFactory * * @return Promise */ - public function methodCall(string $method, $args = [ + public function methodCallRead(string $method, $args = [ ], array $aargs = [ 'msg_id' => null, ], array $extra = []) @@ -5049,8 +5065,16 @@ class InternalDoc extends APIFactory { return $this->__call(__FUNCTION__, [$a, $b, $extra]); } - - public function flock(string $file, int $operation, $polling, array $extra = []) + /** + * Asynchronously lock a file + * Resolves with a callbable that MUST eventually be called in order to release the lock. + * + * @param string $file File to lock + * @param integer $operation Locking mode (see flock) + * @param numeric $polling Polling interval for lock + * @return Promise + */ + public function flock(string $file, int $operation, $polling = 0.1, array $extra = []) { return $this->__call(__FUNCTION__, [$file, $operation, $polling, $extra]); } @@ -5060,6 +5084,11 @@ class InternalDoc extends APIFactory return $this->__call(__FUNCTION__, [$status, $message, $extra]); } + public function flockGenerator(string $file, int $operation, $polling, array $extra = []) + { + return $this->__call(__FUNCTION__, [$file, $operation, $polling, $extra]); + } + public function sleep($time, array $extra = []) { return $this->__call(__FUNCTION__, [$time, $extra]); @@ -5070,6 +5099,11 @@ class InternalDoc extends APIFactory return $this->__call(__FUNCTION__, [$prompt, $extra]); } + public function readLineGenerator($prompt = '', array $extra = []) + { + return $this->__call(__FUNCTION__, [$prompt, $extra]); + } + public function echo($string, array $extra = []) { return $this->__call(__FUNCTION__, [$string, $extra]); diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index 18b81681..4607a651 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -471,7 +471,7 @@ class MTProto extends AsyncConstruct implements TLCallback if (!($this->authorization['user']['bot'] ?? false)) { $callbacks []= $this->minDatabase; } - $this->construct_TL($this->settings['tl_schema']['src'], $callbacks); + $this->constructTL($this->settings['tl_schema']['src'], $callbacks); yield $this->connectToAllDcs(); $this->startLoops(); $this->datacenter->curdc = 2; diff --git a/src/danog/MadelineProto/Server/Handler.php b/src/danog/MadelineProto/Server/Handler.php index 02a6821b..8aa265f8 100644 --- a/src/danog/MadelineProto/Server/Handler.php +++ b/src/danog/MadelineProto/Server/Handler.php @@ -42,7 +42,7 @@ class Handler extends \danog\MadelineProto\Connection $this->sock->setOption(\SOL_SOCKET, \SO_RCVTIMEO, $timeout); $this->sock->setOption(\SOL_SOCKET, \SO_SNDTIMEO, $timeout); $this->logger = new \danog\MadelineProto\Logger(3); - $this->construct_TL(['socket' => __DIR__.'/../TL_socket.tl']); + $this->constructTL(['socket' => __DIR__.'/../TL_socket.tl']); } public function __destruct() diff --git a/tools/build_docs.php b/tools/build_docs.php index 0c20710b..edf0c0aa 100755 --- a/tools/build_docs.php +++ b/tools/build_docs.php @@ -11,9 +11,12 @@ * If not, see . */ +\chdir($d=__DIR__.'/..'); + require 'vendor/autoload.php'; $param = 1; +\danog\MadelineProto\Magic::classExists(); \danog\MadelineProto\Logger::constructor($param); $logger = \danog\MadelineProto\Logger::$default; @@ -30,37 +33,37 @@ image: https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png $docs = [ /* [ - 'tl_schema' => ['td' => __DIR__.'/src/danog/MadelineProto/TL_td.tl'], + 'tl_schema' => ['td' => "$d/src/danog/MadelineProto/TL_td.tl"], 'title' => 'MadelineProto API documentation (td-lib)', 'description' => 'MadelineProto API documentation (td-lib)', - 'output_dir' => __DIR__.'/docs/docs/TD_docs', + 'output_dir' => "$d/docs/docs/TD_docs", 'readme' => false, 'td' => true, ],*/ [ - 'tl_schema' => ['mtproto' => __DIR__.'/src/danog/MadelineProto/TL_mtproto_v1.json'], + 'tl_schema' => ['mtproto' => "$d/src/danog/MadelineProto/TL_mtproto_v1.json"], 'title' => 'MadelineProto API documentation (mtproto)', 'description' => 'MadelineProto API documentation (mtproto)', - 'output_dir' => __DIR__.'/docs/docs/MTProto_docs', + 'output_dir' => "$d/docs/docs/MTProto_docs", 'readme' => false, ], [ - 'tl_schema' => ['telegram' => __DIR__.'/src/danog/MadelineProto/TL_telegram_v105.tl', 'calls' => __DIR__.'/src/danog/MadelineProto/TL_calls.tl', 'secret' => __DIR__.'/src/danog/MadelineProto/TL_secret.tl', 'td' => __DIR__.'/src/danog/MadelineProto/TL_td.tl'], + 'tl_schema' => ['telegram' => "$d/src/danog/MadelineProto/TL_telegram_v105.tl", 'calls' => "$d/src/danog/MadelineProto/TL_calls.tl", 'secret' => "$d/src/danog/MadelineProto/TL_secret.tl", 'td' => "$d/src/danog/MadelineProto/TL_td.tl"], 'title' => 'MadelineProto API documentation (layer 105)', 'description' => 'MadelineProto API documentation (layer 105)', - 'output_dir' => __DIR__.'/docs/docs/API_docs', + 'output_dir' => "$d/docs/docs/API_docs", 'readme' => false, ], ]; $layer_list = ''; -foreach (\array_slice(\glob(__DIR__.'/src/danog/MadelineProto/TL_telegram_*'), 0, -1) as $file) { +foreach (\array_slice(\glob("$d/src/danog/MadelineProto/TL_telegram_*"), 0, -1) as $file) { $layer = \preg_replace(['/.*telegram_/', '/\..+/'], '', $file); $docs[] = [ 'tl_schema' => ['telegram' => $file], 'title' => 'MadelineProto API documentation (layer '.$layer.')', 'description' => 'MadelineProto API documentation (layer '.$layer.')', - 'output_dir' => __DIR__.'/docs/old_docs/API_docs_'.$layer, + 'output_dir' => "$d/docs/old_docs/API_docs_".$layer, 'readme' => true, ]; $layer_list = '[Layer '.$layer.'](API_docs_'.$layer.'/) @@ -76,14 +79,14 @@ description: Documentation of old mtproto layers '.$layer_list); $doc = new \danog\MadelineProto\AnnotationsBuilder($logger, $docs[1]); -$doc->mk_annotations(); +$doc->mkAnnotations(); foreach ($docs as $settings) { $doc = new \danog\MadelineProto\DocsBuilder($logger, $settings); - $doc->mk_docs(); + $doc->mkDocs(); } -\chdir(__DIR__); +\chdir(__DIR__.'/..'); $orderedfiles = []; $order = [ diff --git a/tools/std.php b/tools/std.php index c22b38d8..62129673 100644 --- a/tools/std.php +++ b/tools/std.php @@ -13,7 +13,7 @@ foreach ($classes as $class) { $class = new \ReflectionClass($class); $methods = \array_merge($class->getMethods(), $methods); } -$methods = array_unique($methods); +$methods = \array_unique($methods); function ssort($a, $b) { @@ -31,14 +31,16 @@ foreach ($methods as $methodObj) { } $new = Tools::from_snake_case($method); $new = \str_ireplace(['mtproto', 'api'], ['MTProto', 'API'], $new); - if (!in_array($method, ['discard_call_async', 'accept_call_async', 'request_call_async'])) $new = preg_replace('/async$/i', '', $new); + if (!\in_array($method, ['discard_call_async', 'accept_call_async', 'request_call_async'])) { + $new = \preg_replace('/async$/i', '', $new); + } - if (method_exists((string) $methodObj->getDeclaringClass(), preg_replace('/async$/i', '', $method))) { - var_dump("Skipping $method => $new"); + if (\method_exists((string) $methodObj->getDeclaringClass(), \preg_replace('/async$/i', '', $method))) { + \var_dump("Skipping $method => $new"); continue; } - if (!function_exists($method)) { + if (!\function_exists($method)) { $find[] = "$method("; $replace[] = "$new("; continue;