2222
2323use Amp \Future \UnhandledFutureError ;
2424use Amp \SignalException ;
25- use InvalidArgumentException ;
2625use Revolt \EventLoop ;
2726
28- abstract class AbstractAPIFactory
27+ abstract class AbstractAPI extends InternalDoc
2928{
30- /**
31- * Namespace.
32- *
33- * @internal
34- */
35- private string $ namespace = '' ;
36-
37- /**
38- * API wrapper (to avoid circular references).
39- */
40- protected APIWrapper $ wrapper ;
41-
42- /**
43- * Export APIFactory instance with the specified namespace.
44- */
45- protected function exportNamespaces (): void
46- {
47- $ class = \array_reverse (\array_values (\class_parents (static ::class)))[1 ];
48-
49- foreach (\get_class_vars (APIFactory::class) as $ key => $ var ) {
50- if (\in_array ($ key , ['namespace ' , 'methods ' , 'wrapper ' ])) {
51- continue ;
52- }
53- $ instance = new $ class ;
54- $ instance ->namespace = $ key .'. ' ;
55- $ instance ->wrapper = $ this ->wrapper ;
56- $ this ->{$ key } = $ instance ;
57- }
58- }
5929 /**
6030 * Enable or disable async.
6131 *
@@ -64,29 +34,6 @@ protected function exportNamespaces(): void
6434 public function async (bool $ async ): void
6535 {
6636 }
67- /**
68- * Call async wrapper function.
69- *
70- * @param string $name Method name
71- * @param array $arguments Arguments
72- * @internal
73- */
74- public function __call (string $ name , array $ arguments )
75- {
76- if ($ arguments && !isset ($ arguments [0 ])) {
77- $ arguments = [$ arguments ];
78- }
79-
80- $ name = $ this ->namespace .$ name ;
81- $ aargs = isset ($ arguments [1 ]) && \is_array ($ arguments [1 ]) ? $ arguments [1 ] : [];
82- $ aargs ['apifactory ' ] = true ;
83- $ args = isset ($ arguments [0 ]) && \is_array ($ arguments [0 ]) ? $ arguments [0 ] : [];
84- if (isset ($ args [0 ]) && !isset ($ args ['multiple ' ])) {
85- throw new InvalidArgumentException ('Parameter names must be provided! ' );
86- }
87- return $ this ->wrapper ->getAPI ()->methodCallAsyncRead ($ name , $ args , $ aargs );
88- }
89-
9037 /**
9138 * Start MadelineProto and the event handler (enables async).
9239 *
@@ -130,6 +77,9 @@ protected function startAndLoopInternal(string $eventHandler): void
13077 }
13178 }
13279 }
80+
81+ abstract protected function reconnectFull (): bool ;
82+
13383 private function startAndLoopLogic (string $ eventHandler , bool &$ started ): void
13484 {
13585 $ this ->start ();
0 commit comments