Repository navigation
Expand file tree
/
Copy pathTLMethods.php
More file actions
88 lines (84 loc) · 3.12 KB
/
Copy pathTLMethods.php
File metadata and controls
88 lines (84 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
declare(strict_types=1);
/**
* TLMethods module.
*
* 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/>.
*
* @author Daniil Gentili <daniil@daniil.it>
* @copyright 2016-2025 Daniil Gentili <daniil@daniil.it>
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/
namespace danog\MadelineProto\TL;
/**
* @internal
*/
final class TLMethods
{
use TLParams;
public array $by_id = [];
public array $by_method = [];
public array $method_namespace = [];
/**
* @psalm-pure
*/
public function __sleep(): array
{
return ['by_id', 'by_method', 'method_namespace'];
}
public function add(array $json_dict, string $scheme_type): void
{
$this->by_id[$json_dict['id']] = [
'method' => $json_dict['method'],
'type' => $json_dict['type'],
'params' => $json_dict['params'],
'flags' => [],
'encrypted' => $scheme_type !== 'mtproto'
|| $json_dict['method'] === 'ping_delay_disconnect'
|| $json_dict['method'] === 'ping'
|| $json_dict['method'] === 'destroy_session'
|| $json_dict['method'] === 'rpc_drop_answer'
|| $json_dict['method'] === 'get_future_salts',
];
if (preg_match('/^(v|V)ector\\<(.*)\\>$/', $json_dict['type'], $matches)) {
$this->by_id[$json_dict['id']]['type'] = $matches[1] === 'v' ? 'vector' : 'Vector t';
$this->by_id[$json_dict['id']]['subtype'] = $matches[2];
}
$this->by_method[$json_dict['method']] = $json_dict['id'];
$namespace = explode('.', $json_dict['method']);
if (isset($namespace[1])) {
$this->method_namespace[] = [$namespace[0] => $namespace[1]];
}
$this->parseParams($json_dict['id'], false, $json_dict['method']);
}
/**
* @psalm-mutation-free
*/
public function findById(string $id)
{
if (isset($this->by_id[$id])) {
$method = $this->by_id[$id];
$method['id'] = $id;
return $method;
}
return false;
}
/**
* @psalm-mutation-free
*/
public function findByMethod(string $method_name)
{
if (isset($this->by_method[$method_name])) {
$method = $this->by_id[$this->by_method[$method_name]];
$method['id'] = $this->by_method[$method_name];
return $method;
}
return false;
}
}