MadelineProto/tools/layerdiff.php

116 lines
3.8 KiB
PHP
Raw Normal View History

2019-05-31 13:17:29 +02:00
<?php
2019-06-04 14:55:58 +02:00
2019-05-31 13:17:29 +02:00
use danog\MadelineProto\Logger;
use danog\MadelineProto\TL\TL;
/*
2020-02-17 14:13:46 +01:00
Copyright 2016-2020 Daniil Gentili
2019-05-31 13:17:29 +02:00
(https://daniil.it)
This file is part of MadelineProto.
MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU General Public License along with MadelineProto.
If not, see <http://www.gnu.org/licenses/>.
*/
require 'vendor/autoload.php';
$param = 1;
\danog\MadelineProto\Logger::constructor($param);
$logger = \danog\MadelineProto\Logger::$default;
2019-10-28 19:48:59 +01:00
\set_error_handler(['\danog\MadelineProto\Exception', 'ExceptionErrorHandler']);
2019-05-31 13:17:29 +02:00
if ($argc !== 3) {
die("Usage: {$argv[0]} layernumberold layernumbernew\n");
}
/**
2019-06-04 14:55:58 +02:00
* Get TL info of layer.
2019-05-31 13:17:29 +02:00
*
* @param int $layer Layer number
2019-06-04 14:55:58 +02:00
*
2019-05-31 13:17:29 +02:00
* @return void
*/
function getTL($layer)
{
2020-04-05 22:22:47 +02:00
$layer = __DIR__."/../schemas/TL_telegram_v$layer.tl";
2019-06-04 14:55:58 +02:00
$layer = new class($layer) {
2019-05-31 13:17:29 +02:00
use TL;
2019-06-04 14:55:58 +02:00
2019-05-31 13:17:29 +02:00
public function __construct($layer)
{
$this->logger = Logger::$default;
$this->construct_TL(['telegram' => $layer]);
}
};
2019-06-04 14:55:58 +02:00
2019-05-31 13:17:29 +02:00
return ['methods' => $layer->methods, 'constructors' => $layer->constructors];
}
function getUrl($constructor, $type)
{
2019-10-28 19:48:59 +01:00
$changed = \str_replace('.', '_', $constructor);
2019-06-04 14:55:58 +02:00
2019-09-13 18:32:43 +02:00
//return "[$constructor](https://github.com/danog/MadelineProtoDocs/blob/geochats/docs/API_docs/$type/$changed.md)";
2019-05-31 13:17:29 +02:00
return "[$constructor](https://docs.madelineproto.xyz/API_docs/$type/$changed.html)";
}
$old = getTL($argv[1]);
$new = getTL($argv[2]);
$res = '';
foreach (['methods', 'constructors'] as $type) {
$finder = $type === 'methods' ? 'findByMethod' : 'findByPredicate';
2019-05-31 13:17:29 +02:00
$key = $type === 'methods' ? 'method' : 'predicate';
// New constructors
2019-10-28 19:48:59 +01:00
$res .= "\n\nNew ".\ucfirst($type)."\n";
2019-05-31 13:17:29 +02:00
foreach ($new[$type]->by_id as $constructor) {
$name = $constructor[$key];
if (!$old[$type]->$finder($name)) {
$name = getUrl($name, $type);
$res .= "Added $name\n";
}
}
// Changed constructors
2019-10-28 19:48:59 +01:00
$res .= "\n\nChanged ".\ucfirst($type)."\n";
2019-05-31 13:17:29 +02:00
foreach ($new[$type]->by_id as $constructor) {
$name = $constructor[$key];
$constructor['id'] = $new[$type]->$finder($name)['id'];
if ($old[$type]->$finder($name)) {
2019-05-31 13:17:29 +02:00
$new_args = $constructor['params'];
$old_args = $old[$type]->$finder($name)['params'];
$final_new_args = [];
$final_old_args = [];
foreach ($new_args as $arg) {
$final_new_args[$arg['name']] = $arg['type'];
}
foreach ($old_args as $arg) {
$final_old_args[$arg['name']] = $arg['type'];
}
$url = getUrl($name, $type);
foreach ($final_new_args as $name => $ttype) {
2019-06-22 20:34:15 +02:00
if (!isset($final_old_args[$name]) && $name !== 'flags') {
2019-05-31 13:17:29 +02:00
$res .= "Added $name param to $url\n";
}
}
foreach ($final_old_args as $name => $ttype) {
2019-06-22 20:34:15 +02:00
if (!isset($final_new_args[$name]) && $name !== 'flags') {
2019-05-31 13:17:29 +02:00
$res .= "Removed $name param from $url\n";
}
}
}
}
// Deleted constructors
2019-10-28 19:48:59 +01:00
$res .= "\n\nDeleted ".\ucfirst($type)."\n";
2019-05-31 13:17:29 +02:00
foreach ($old[$type]->by_id as $constructor) {
$name = $constructor[$key];
if (!$new[$type]->$finder($name)) {
$res .= "Removed $name\n";
}
}
}
2019-06-04 14:55:58 +02:00
echo $res;