2022-12-29 20:40:06 +01:00
|
|
|
<?php declare(strict_types=1);
|
2019-10-29 21:28:02 +01:00
|
|
|
|
|
|
|
use danog\MadelineProto\Tools;
|
|
|
|
use HaydenPierce\ClassFinder\ClassFinder;
|
|
|
|
|
2022-12-08 20:16:40 +01:00
|
|
|
chdir(__DIR__.'/../');
|
2019-10-29 21:28:02 +01:00
|
|
|
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
|
|
|
|
$classes = ClassFinder::getClassesInNamespace(danog\MadelineProto::class, ClassFinder::RECURSIVE_MODE);
|
|
|
|
$methods = [];
|
|
|
|
foreach ($classes as $class) {
|
|
|
|
$class = new \ReflectionClass($class);
|
2022-12-08 20:16:40 +01:00
|
|
|
$methods = array_merge($class->getMethods(), $methods);
|
2019-10-29 21:28:02 +01:00
|
|
|
}
|
2022-12-08 20:16:40 +01:00
|
|
|
$methods = array_unique($methods);
|
2019-10-29 21:28:02 +01:00
|
|
|
|
2023-11-11 16:55:29 +01:00
|
|
|
usort($methods, static fn ($a, $b) => strlen($b->getName())-strlen($a->getName()));
|
2019-10-29 21:28:02 +01:00
|
|
|
|
|
|
|
$find = [];
|
|
|
|
$replace = [];
|
2019-10-29 22:41:31 +01:00
|
|
|
$findDocs = [];
|
|
|
|
$replaceDocs = [];
|
2019-10-29 21:28:02 +01:00
|
|
|
foreach ($methods as $methodObj) {
|
|
|
|
$method = $methodObj->getName();
|
2023-11-11 16:55:29 +01:00
|
|
|
if (str_starts_with($method, '__') || $method === 'async') {
|
2019-10-29 21:28:02 +01:00
|
|
|
continue;
|
|
|
|
}
|
2019-10-29 22:41:31 +01:00
|
|
|
$method = Tools::fromCamelCase($method);
|
|
|
|
|
2019-10-29 22:06:51 +01:00
|
|
|
$new = Tools::fromSnakeCase($method);
|
2022-12-08 20:16:40 +01:00
|
|
|
$new = str_ireplace(['mtproto', 'api'], ['MTProto', 'API'], $new);
|
|
|
|
$new = preg_replace('/TL$/i', 'TL', $new);
|
2023-11-11 16:55:29 +01:00
|
|
|
if (!in_array($method, ['discardCallAsync', 'acceptCallAsync', 'requestCallAsync'], true)) {
|
2022-12-08 20:16:40 +01:00
|
|
|
$new = preg_replace('/async$/i', '', $new);
|
2019-10-29 22:00:21 +01:00
|
|
|
}
|
2019-10-29 21:28:02 +01:00
|
|
|
|
2019-10-29 22:41:31 +01:00
|
|
|
$findDocs []= Tools::fromCamelCase($new).'(';
|
|
|
|
$replaceDocs []= $new.'(';
|
|
|
|
|
|
|
|
$findDocs []= $method.'(';
|
|
|
|
$replaceDocs []= $new.'(';
|
|
|
|
|
|
|
|
$findDocs []= Tools::fromCamelCase($new).'.';
|
|
|
|
$replaceDocs []= $new.'.';
|
|
|
|
|
|
|
|
$findDocs []= $method.'.';
|
|
|
|
$replaceDocs []= $new.'.';
|
|
|
|
|
|
|
|
$findDocs []= Tools::fromCamelCase($new).']';
|
|
|
|
$replaceDocs []= $new.']';
|
|
|
|
|
|
|
|
$findDocs []= $method.']';
|
|
|
|
$replaceDocs []= $new.']';
|
|
|
|
|
2022-12-08 20:16:40 +01:00
|
|
|
if (method_exists((string) $methodObj->getDeclaringClass(), preg_replace('/async$/i', '', $method))) {
|
|
|
|
var_dump("Skipping $method => $new");
|
2019-10-29 21:28:02 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-12-08 20:16:40 +01:00
|
|
|
if (!function_exists($method)) {
|
2019-10-29 22:41:31 +01:00
|
|
|
$find[] = "$method";
|
|
|
|
$replace[] = "$new";
|
2019-10-29 21:28:02 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$find[] = ">$method(";
|
|
|
|
$replace[] = ">$new(";
|
|
|
|
|
|
|
|
$find[] = ":$method(";
|
|
|
|
$replace[] = ":$new(";
|
|
|
|
|
|
|
|
$find[] = "function $method(";
|
|
|
|
$replace[] = "function $new(";
|
|
|
|
}
|
|
|
|
|
2022-12-08 20:16:40 +01:00
|
|
|
foreach (new RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(realpath('.'))), '/\.php$/') as $filename) {
|
2019-10-29 21:28:02 +01:00
|
|
|
$filename = (string) $filename;
|
2022-12-08 20:16:40 +01:00
|
|
|
$new = str_replace($find, $replace, $old = file_get_contents($filename));
|
2019-10-29 21:28:02 +01:00
|
|
|
do {
|
2022-12-08 20:16:40 +01:00
|
|
|
file_put_contents($filename, $new);
|
|
|
|
$new = str_replace($find, $replace, $old = file_get_contents($filename));
|
2019-10-29 21:28:02 +01:00
|
|
|
} while ($old !== $new);
|
|
|
|
}
|
2019-10-29 21:33:23 +01:00
|
|
|
exit;
|
|
|
|
|
2022-12-08 20:16:40 +01:00
|
|
|
foreach (new RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(realpath('docs'))), '/\.md$/') as $filename) {
|
2019-10-29 21:28:02 +01:00
|
|
|
$filename = (string) $filename;
|
2022-12-08 20:16:40 +01:00
|
|
|
$new = str_replace($findDocs, $replaceDocs, $old = file_get_contents($filename));
|
2019-10-29 21:28:02 +01:00
|
|
|
do {
|
2022-12-08 20:16:40 +01:00
|
|
|
file_put_contents($filename, $new);
|
|
|
|
$new = str_replace($findDocs, $replaceDocs, $old = file_get_contents($filename));
|
2019-10-29 21:28:02 +01:00
|
|
|
} while ($old !== $new);
|
|
|
|
}
|
|
|
|
$filename = 'README.md';
|
|
|
|
|
2022-12-08 20:16:40 +01:00
|
|
|
$new = str_replace($findDocs, $replaceDocs, $old = file_get_contents($filename));
|
|
|
|
do {
|
|
|
|
file_put_contents($filename, $new);
|
|
|
|
$new = str_replace($findDocs, $replaceDocs, $old = file_get_contents($filename));
|
|
|
|
} while ($old !== $new);
|