1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-27 05:54:41 +01:00
MadelineProto/tools/asyncify.php

54 lines
1.7 KiB
PHP
Raw Normal View History

2019-05-11 20:38:26 +02:00
<?php
2019-06-04 14:55:58 +02:00
2019-05-11 20:38:26 +02:00
$not_subbing = [];
2019-10-28 19:48:59 +01:00
foreach (\explode("\n", \shell_exec("find src -type f -name '*.php'")) as $file) {
2019-06-04 14:55:58 +02:00
if (!$file) {
continue;
}
2019-10-28 19:48:59 +01:00
if (\in_array(\basename($file, '.php'), ['APIFactory', 'API', 'Connection', 'Coroutine', 'ReferenceDatabase', 'ProxySocketPool'])) {
2019-06-04 14:55:58 +02:00
continue;
}
2019-10-28 19:48:59 +01:00
if (\strpos($file, 'Loop/')) {
2019-06-04 14:55:58 +02:00
continue;
}
2019-10-28 19:48:59 +01:00
if (\strpos($file, 'Stream/')) {
2019-06-04 14:55:58 +02:00
continue;
}
2019-10-28 19:48:59 +01:00
if (\strpos($file, 'Server/')) {
2019-06-04 14:55:58 +02:00
continue;
}
2019-10-28 19:48:59 +01:00
if (\strpos($file, 'Async/')) {
2019-06-04 14:55:58 +02:00
continue;
}
2019-05-11 20:38:26 +02:00
$to_sub = [];
$last_match = null;
2019-10-28 19:48:59 +01:00
foreach (\explode("\n", $filec = \file_get_contents($file)) as $number => $line) {
if (\preg_match("/public function (\w*)[(]/", $line, $matches)) {
$last_match = \stripos($matches[1], 'async') === false ? $matches[1] : null;
2019-05-11 20:38:26 +02:00
}
2019-10-28 19:48:59 +01:00
if (\preg_match('/function [(]/', $line) && \stripos($line, 'public function') === false) {
2019-05-11 20:38:26 +02:00
$last_match = 0;
}
2019-10-28 19:48:59 +01:00
if (\strpos($line, 'yield') !== false) {
2019-05-11 20:38:26 +02:00
if ($last_match) {
2019-06-04 14:55:58 +02:00
echo "subbing $last_match for $line at $number in $file".PHP_EOL;
$to_sub[] = $last_match;
} elseif ($last_match === 0) {
echo "============\nNOT SUBBING $last_match for $line at $number in $file\n============".PHP_EOL;
2019-05-11 20:38:26 +02:00
$not_subbing[$file] = $file;
}
}
}
$input = [];
$output = [];
foreach ($to_sub as $func) {
2019-06-04 14:55:58 +02:00
$input[] = "public function $func(";
$output[] = "public function $func".'_async(';
}
if ($input) {
2019-10-28 19:48:59 +01:00
\file_put_contents($file, \str_replace($input, $output, $filec));
2019-05-11 20:38:26 +02:00
}
}
2019-10-28 19:48:59 +01:00
\var_dump(\array_values($not_subbing));