1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-30 06:39:01 +01:00
MadelineProto/tools/std.php

101 lines
3.1 KiB
PHP
Raw Normal View History

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-08-13 15:47:21 +02:00
usort($methods, fn ($a, $b) => strlen($b->getName())-strlen($a->getName()));
2019-10-29 21:28:02 +01:00
$find = [];
$replace = [];
$findDocs = [];
$replaceDocs = [];
2019-10-29 21:28:02 +01:00
foreach ($methods as $methodObj) {
$method = $methodObj->getName();
2022-12-08 20:16:40 +01:00
if (strpos($method, '__') === 0 || $method === 'async') {
2019-10-29 21:28:02 +01:00
continue;
}
$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);
if (!in_array($method, ['discardCallAsync', 'acceptCallAsync', 'requestCallAsync'])) {
$new = preg_replace('/async$/i', '', $new);
2019-10-29 22:00:21 +01:00
}
2019-10-29 21:28:02 +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)) {
$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);