Advertisement
Guest User

CombinedEventHandler

a guest
Jan 28th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1. namespace danog\MadelineProto;
  2.  
  3. abstract class CombinedEventHandler
  4. {
  5.     private $CombinedAPI;
  6.  
  7.     public function __construct($CombinedAPI)
  8.     {
  9.         $this->CombinedAPI = $CombinedAPI;
  10.         foreach ($CombinedAPI->instances as $path => $instance) {
  11.             $this->referenceInstance($path);
  12.         }
  13.     }
  14.  
  15.     final public function __sleep()
  16.     {
  17.         $keys = \method_exists($this, '__magic_sleep') ? $this->__magic_sleep() : \get_object_vars($this);
  18.         unset($keys['CombinedAPI']);
  19.         if (isset($this->CombinedAPI) && $this->CombinedAPI instanceof CombinedAPI) {
  20.             foreach ($this->CombinedAPI->instance_paths as $path) {
  21.                 unset($keys[$path]);
  22.             }
  23.         } else {
  24.             foreach ($keys as $key => $value) {
  25.                 if ($value instanceof API && $key === $value->session) {
  26.                     unset($keys[$key]);
  27.                 }
  28.             }
  29.         }
  30.  
  31.         return \array_keys($keys);
  32.     }
  33.  
  34.     final public function referenceInstance($path)
  35.     {
  36.         $this->{$path} = $this->CombinedAPI->instances[$path];
  37.     }
  38.  
  39.     final public function removeInstance($path)
  40.     {
  41.         if (isset($this->{$path})) {
  42.             unset($this->{$path});
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement