diff --git a/src/danog/MadelineProto/API.php b/src/danog/MadelineProto/API.php index 0b057e3c..3e37d61c 100644 --- a/src/danog/MadelineProto/API.php +++ b/src/danog/MadelineProto/API.php @@ -138,7 +138,7 @@ class API extends InternalDoc $this->APIFactory(); $unserialized->oldInstance = true; $deferred->resolve(); - yield $this->API->initAsync(); + yield $this->API->initAsynchronously(); $this->APIFactory(); //\danog\MadelineProto\Logger::log('Ping...', Logger::ULTRA_VERBOSE); $this->asyncInitPromise = null; @@ -161,7 +161,7 @@ class API extends InternalDoc $this->APIFactory(); $deferred->resolve(); Logger::log(\danog\MadelineProto\Lang::$current_lang['apifactory_start'], Logger::VERBOSE); - yield $this->API->initAsync(); + yield $this->API->initAsynchronously(); $this->APIFactory(); $this->asyncInitPromise = null; //\danog\MadelineProto\Logger::log('Ping...', Logger::ULTRA_VERBOSE); @@ -300,7 +300,7 @@ class API extends InternalDoc return false; } if ($this->API && $this->API->asyncInitPromise) { - yield $this->API->initAsync(); + yield $this->API->initAsynchronously(); } $this->serialized = \time(); $realpaths = Serialization::realpaths($filename); diff --git a/src/danog/MadelineProto/APIFactory.php b/src/danog/MadelineProto/APIFactory.php index 891c5463..1730c55e 100644 --- a/src/danog/MadelineProto/APIFactory.php +++ b/src/danog/MadelineProto/APIFactory.php @@ -160,7 +160,7 @@ class APIFactory extends AsyncConstruct public function __call_async($name, $arguments) { if ($this->asyncInitPromise) { - yield $this->initAsync(); + yield $this->initAsynchronously(); $this->API->logger->logger('Finished init asynchronously'); } if (Magic::is_fork() && !Magic::$processed_fork) { @@ -170,7 +170,7 @@ class APIFactory extends AsyncConstruct throw new Exception('API did not init!'); } if ($this->API->asyncInitPromise) { - yield $this->API->initAsync(); + yield $this->API->initAsynchronously(); $this->API->logger->logger('Finished init asynchronously'); } if (isset($this->session) && !\is_null($this->session) && \time() - $this->serialized > $this->API->settings['serialization']['serialization_interval']) { @@ -180,10 +180,10 @@ class APIFactory extends AsyncConstruct if ($this->API->flushSettings) { $this->API->flushSettings = false; $this->API->__construct($this->API->settings); - yield $this->API->initAsync(); + yield $this->API->initAsynchronously(); } if ($this->API->asyncInitPromise) { - yield $this->API->initAsync(); + yield $this->API->initAsynchronously(); $this->API->logger->logger('Finished init asynchronously'); } diff --git a/src/danog/MadelineProto/Async/AsyncConstruct.php b/src/danog/MadelineProto/Async/AsyncConstruct.php index 7d08c7ed..6767e568 100644 --- a/src/danog/MadelineProto/Async/AsyncConstruct.php +++ b/src/danog/MadelineProto/Async/AsyncConstruct.php @@ -38,7 +38,7 @@ class AsyncConstruct } } - public function initAsync() + public function initAsynchronously() { if ($this->asyncInitPromise) { yield $this->asyncInitPromise; diff --git a/src/danog/MadelineProto/CombinedAPI.php b/src/danog/MadelineProto/CombinedAPI.php index 31171846..ca1c1061 100644 --- a/src/danog/MadelineProto/CombinedAPI.php +++ b/src/danog/MadelineProto/CombinedAPI.php @@ -234,7 +234,7 @@ class CombinedAPI $loops = []; foreach ($this->instances as $path => $instance) { - $this->wait($instance->initAsync()); + $this->wait($instance->initAsynchronously()); if ($instance->API->authorized !== MTProto::LOGGED_IN) { continue; } diff --git a/src/danog/MadelineProto/Stream/Async/Buffer.php b/src/danog/MadelineProto/Stream/Async/Buffer.php index 5dfeaa3c..fc2c4cbd 100644 --- a/src/danog/MadelineProto/Stream/Async/Buffer.php +++ b/src/danog/MadelineProto/Stream/Async/Buffer.php @@ -31,11 +31,11 @@ trait Buffer { public function bufferRead(int $length): Promise { - return $this->call($this->bufferReadAsync($length)); + return $this->call($this->bufferReadGenerator($length)); } public function bufferWrite(string $data): Promise { - return $this->call($this->bufferWriteAsync($data)); + return $this->call($this->bufferWriteGenerator($data)); } } diff --git a/src/danog/MadelineProto/Stream/Async/BufferedStream.php b/src/danog/MadelineProto/Stream/Async/BufferedStream.php index 102e1b76..60a1eb36 100644 --- a/src/danog/MadelineProto/Stream/Async/BufferedStream.php +++ b/src/danog/MadelineProto/Stream/Async/BufferedStream.php @@ -40,7 +40,7 @@ trait BufferedStream */ public function getReadBuffer(&$length): Promise { - return $this->call($this->getReadBufferAsync($length)); + return $this->call($this->getReadBufferGenerator($length)); } /** @@ -53,6 +53,6 @@ trait BufferedStream */ public function getWriteBuffer(int $length, string $append = ''): Promise { - return $this->call($this->getWriteBufferAsync($length, $append)); + return $this->call($this->getWriteBufferGenerator($length, $append)); } } diff --git a/src/danog/MadelineProto/Stream/Async/RawStream.php b/src/danog/MadelineProto/Stream/Async/RawStream.php index 6001c06f..59b2ea98 100644 --- a/src/danog/MadelineProto/Stream/Async/RawStream.php +++ b/src/danog/MadelineProto/Stream/Async/RawStream.php @@ -33,16 +33,16 @@ trait RawStream public function read(): Promise { - return $this->call($this->readAsync()); + return $this->call($this->readGenerator()); } public function write(string $data): Promise { - return $this->call($this->writeAsync($data)); + return $this->call($this->writeGenerator($data)); } public function end(string $finalData = ''): Promise { - return $this->call($this->endAsync($finalData)); + return $this->call($this->endGenerator($finalData)); } } diff --git a/src/danog/MadelineProto/Stream/Async/Stream.php b/src/danog/MadelineProto/Stream/Async/Stream.php index 3d5f2f3e..181fbb59 100644 --- a/src/danog/MadelineProto/Stream/Async/Stream.php +++ b/src/danog/MadelineProto/Stream/Async/Stream.php @@ -35,6 +35,6 @@ trait Stream public function connect(ConnectionContext $ctx, string $header = ''): Promise { - return $this->call($this->connectAsync($ctx, $header)); + return $this->call($this->connectGenerator($ctx, $header)); } } diff --git a/src/danog/MadelineProto/Tools.php b/src/danog/MadelineProto/Tools.php index 5e1a4fa6..ecbf0fc1 100644 --- a/src/danog/MadelineProto/Tools.php +++ b/src/danog/MadelineProto/Tools.php @@ -380,7 +380,7 @@ trait Tools */ public static function flock(string $file, int $operation, $polling = 0.1): Promise { - return self::call(self::flockAsync($file, $operation, $polling)); + return self::call(self::flockGenerator($file, $operation, $polling)); } public static function noCache(int $status, string $message) { @@ -390,7 +390,7 @@ trait Tools \http_response_code($status); return self::echo($message); } - public static function flockAsync(string $file, int $operation, $polling) + public static function flockGenerator(string $file, int $operation, $polling) { if (!yield exists($file)) { yield \touch($file); @@ -419,9 +419,9 @@ trait Tools } public static function readLine($prompt = '') { - return self::call(Tools::readLineAsync($prompt)); + return self::call(Tools::readLineGenerator($prompt)); } - public static function readLineAsync($prompt = '') + public static function readLineGenerator($prompt = '') { $stdin = getStdin(); $stdout = getStdout(); diff --git a/tools/std.php b/tools/std.php new file mode 100644 index 00000000..87b497c2 --- /dev/null +++ b/tools/std.php @@ -0,0 +1,78 @@ +getMethods(), $methods); +} +$methods = array_unique($methods); + +function ssort($a, $b) +{ + return \strlen($b->getName())-\strlen($a->getName()); +} + +\usort($methods, 'ssort'); + +$find = []; +$replace = []; +foreach ($methods as $methodObj) { + $method = $methodObj->getName(); + if (\strpos($method, '__') === 0 || $method === 'async') { + continue; + } + $new = Tools::from_snake_case($method); + $new = \str_ireplace(['mtproto', 'api'], ['MTProto', 'API'], $new); + $new = preg_replace('/async$/i', '', $new); + + if (method_exists((string) $methodObj->getDeclaringClass(), preg_replace('/async$/i', '', $method))) { + var_dump("Skipping $method => $new"); + continue; + } + + if (!function_exists($method)) { + $find[] = "$method("; + $replace[] = "$new("; + continue; + } + $find[] = ">$method("; + $replace[] = ">$new("; + + $find[] = ":$method("; + $replace[] = ":$new("; + + $find[] = "function $method("; + $replace[] = "function $new("; +} + +foreach (new RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(\realpath('src'))), '/\.php$/') as $filename) { + $filename = (string) $filename; + $new = \str_replace($find, $replace, $old = \file_get_contents($filename)); + do { + \file_put_contents($filename, $new); + $new = \str_replace($find, $replace, $old = \file_get_contents($filename)); + } while ($old !== $new); +} +foreach (new RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(\realpath('docs'))), '/\.md$/') as $filename) { + $filename = (string) $filename; + $new = \str_replace($find, $replace, $old = \file_get_contents($filename)); + do { + \file_put_contents($filename, $new); + $new = \str_replace($find, $replace, $old = \file_get_contents($filename)); + } while ($old !== $new); +} +$filename = 'README.md'; + + $new = \str_replace($find, $replace, $old = \file_get_contents($filename)); + do { + \file_put_contents($filename, $new); + $new = \str_replace($find, $replace, $old = \file_get_contents($filename)); + } while ($old !== $new);