1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-26 23:14:38 +01:00
MadelineProto/tools/build_docs/layerUpgrade.php
2023-09-06 17:46:35 +02:00

42 lines
1.0 KiB
PHP

<?php declare(strict_types=1);
/**
* Upgrade layer number.
*
* @param integer $layer Layer number
* @internal
*/
function layerUpgrade(int $layer): void
{
$doc = file_get_contents('docs/docs/docs/USING_METHODS.md');
$doc = preg_replace('|here \(layer \d+\)|', "here (layer $layer)", $doc);
file_put_contents('docs/docs/docs/USING_METHODS.md', $doc);
array_map(unlink::class, glob('src/*.tl'));
foreach (['TL_mtproto_v1', "TL_telegram_v$layer", 'TL_secret'] as $schema) {
copy("schemas/$schema.tl", "src/$schema.tl");
}
$doc = file_get_contents('src/Settings/TLSchema.php');
preg_match("/layer = (\d+)/", $doc, $matches);
$prevLayer = (int) $matches[1];
if ($prevLayer === $layer) {
return;
}
$doc = str_replace(
[
"layer = $prevLayer",
"TL_telegram_v$prevLayer",
],
[
"layer = $layer",
"TL_telegram_v$layer",
],
$doc
);
file_put_contents('src/Settings/TLSchema.php', $doc);
}