915a0cd180
* I'll just leave this here * Threading fixes * Apply fixes from StyleCI * Composer fixes * Lots of threading fixes, included all RSA keys * Apply fixes from StyleCI * Updated phpseclib * fixes * Apply fixes from StyleCI * final fixes * git add -A * Apply fixes from StyleCI * bugfix * Fixes * Apply fixes from StyleCI * Small fixes * Final fixes * Speed improvements * speed fixes * Apply fixes from StyleCI * This is faster than sanic * Apply fixes from StyleCI * Final speed fixes * Apply fixes from StyleCI * Less logging * Speed+++ * Apply fixes from StyleCI * More fixes * Bug74586Exception * Apply fixes from StyleCI * Fixes * Lemme fix that dumb-ass bug that broke everything * Apply fixes from StyleCI * Updated rollbar token * Fixes for other tcp_* protocols * Apply fixes from StyleCI * No need for phpstruct anymore * Add a conflict (OH NOES pony warfare) * Less logs, beginning of clickable buttons * Apply fixes from StyleCI * Bugfixes, fixed clickable buttons * Apply fixes from StyleCI * Better errors * Apply fixes from StyleCI * You can now click text buttons * Apply fixes from StyleCI
91 lines
3.3 KiB
PHP
91 lines
3.3 KiB
PHP
<?php
|
|
/*
|
|
Copyright 2016-2017 Daniil Gentili
|
|
(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/>.
|
|
*/
|
|
|
|
namespace danog\MadelineProto\TL;
|
|
|
|
class TLConstructor extends \Volatile
|
|
{
|
|
use \danog\Serializable;
|
|
use \danog\MadelineProto\Tools;
|
|
use TLParams;
|
|
|
|
public $id = [];
|
|
public $predicate = [];
|
|
public $type = [];
|
|
public $params = [];
|
|
public $layer = [];
|
|
public $key = 0;
|
|
|
|
public function add($json_dict, $scheme_type)
|
|
{
|
|
$this->id[$this->key] = $json_dict['id'];
|
|
$this->predicate[$this->key] = (string) ((($scheme_type === 'mtproto' && $json_dict['predicate'] === 'message') ? 'MT' : '').$json_dict['predicate']);
|
|
$this->type[$this->key] = (($scheme_type === 'mtproto' && $json_dict['type'] === 'Message') ? 'MT' : '').$json_dict['type'];
|
|
$this->params[$this->key] = $json_dict['params'];
|
|
if ($scheme_type === 'secret') {
|
|
$this->layer[$this->key] = $json_dict['layer'];
|
|
}
|
|
$this->parse_params($this->key, $scheme_type === 'mtproto');
|
|
$this->key++;
|
|
}
|
|
|
|
public function find_by_type($type)
|
|
{
|
|
$key = array_search($type, (array) $this->type);
|
|
|
|
return ($key === false) ? false : [
|
|
'id' => $this->id[$key],
|
|
'predicate' => $this->predicate[$key],
|
|
'type' => $this->type[$key],
|
|
'params' => $this->array_cast_recursive($this->params[$key]),
|
|
];
|
|
}
|
|
|
|
public function find_by_predicate($predicate, $layer = -1)
|
|
{
|
|
if ($layer !== -1) {
|
|
$newlayer = -1;
|
|
$keys = array_keys((array) $this->predicate, $predicate);
|
|
foreach ($keys as $k) {
|
|
if ($this->layer[$k] <= $layer && $this->layer[$k] > $newlayer) {
|
|
$key = $k;
|
|
$newlayer = $this->layer[$k];
|
|
}
|
|
if (!isset($key)) {
|
|
$key = $keys[0];
|
|
}
|
|
}
|
|
} else {
|
|
$key = array_search($predicate, (array) $this->predicate);
|
|
}
|
|
|
|
return ($key === false) ? false : [
|
|
'id' => $this->id[$key],
|
|
'predicate' => $this->predicate[$key],
|
|
'type' => $this->type[$key],
|
|
'params' => $this->array_cast_recursive($this->params[$key]),
|
|
];
|
|
}
|
|
|
|
public function find_by_id($id)
|
|
{
|
|
$key = array_search($id, (array) $this->id);
|
|
|
|
return ($key === false) ? false : [
|
|
'id' => $this->id[$key],
|
|
'predicate' => $this->predicate[$key],
|
|
'type' => $this->type[$key],
|
|
'params' => $this->array_cast_recursive($this->params[$key]),
|
|
];
|
|
}
|
|
}
|