diff --git a/src/Client.php b/src/Client.php index 62f7c33..5959146 100644 --- a/src/Client.php +++ b/src/Client.php @@ -23,10 +23,10 @@ class Client public static function getInstance(): Client { - if (empty(static::$self)) { - static::$self = new static(); + if (empty(self::$self)) { + self::$self = new static(); } - return static::$self; + return self::$self; } public function connect(array $sessionFiles) diff --git a/src/Config.php b/src/Config.php index 27d2ad7..d2e4845 100644 --- a/src/Config.php +++ b/src/Config.php @@ -11,11 +11,11 @@ class Config public static function getInstance(): Config { - if (null === static::$instance) { - static::$instance = new static(); + if (null === self::$instance) { + self::$instance = new static(); } - return static::$instance; + return self::$instance; } /** diff --git a/src/EventObservers/EventHandler.php b/src/EventObservers/EventHandler.php index 7a045d9..9f3565a 100644 --- a/src/EventObservers/EventHandler.php +++ b/src/EventObservers/EventHandler.php @@ -12,8 +12,8 @@ class EventHandler extends \danog\MadelineProto\EventHandler public function onStart() { $this->sessionName = Files::getSessionName($this->wrapper->getSession()->getSessionPath()); - if (empty(static::$instances[$this->sessionName])) { - static::$instances[$this->sessionName] = true; + if (empty(self::$instances[$this->sessionName])) { + self::$instances[$this->sessionName] = true; warning("Event observer CONSTRUCTED: {$this->sessionName}"); } } @@ -23,7 +23,7 @@ class EventHandler extends \danog\MadelineProto\EventHandler if (empty($this->sessionName)) { return; } - unset(static::$instances[$this->sessionName]); + unset(self::$instances[$this->sessionName]); warning("Event observer DESTRUCTED: {$this->sessionName}"); } diff --git a/src/EventObservers/EventObserver.php b/src/EventObservers/EventObserver.php index 47b42bc..70a2112 100644 --- a/src/EventObservers/EventObserver.php +++ b/src/EventObservers/EventObserver.php @@ -18,7 +18,7 @@ class EventObserver public static function notify(array $update, string $sessionName) { - foreach (static::$subscribers as $clientId => $callback) { + foreach (self::$subscribers as $clientId => $callback) { notice("Pass update to callback. ClientId: {$clientId}"); $callback($update, $sessionName); } @@ -26,16 +26,16 @@ class EventObserver private static function addSessionClient(string $session): void { - if (empty(static::$sessionClients[$session])) { - static::$sessionClients[$session] = 0; + if (empty(self::$sessionClients[$session])) { + self::$sessionClients[$session] = 0; } - ++static::$sessionClients[$session]; + ++self::$sessionClients[$session]; } private static function removeSessionClient(string $session): void { - if (!empty(static::$sessionClients[$session])) { - --static::$sessionClients[$session]; + if (!empty(self::$sessionClients[$session])) { + --self::$sessionClients[$session]; } } @@ -49,8 +49,8 @@ class EventObserver } foreach ($sessions as $session) { - static::addSessionClient($session); - if (static::$sessionClients[$session] === 1) { + self::addSessionClient($session); + if (self::$sessionClients[$session] === 1) { warning("Start EventHandler: {$session}"); try { $instance = Client::getInstance()->getSession($session); @@ -60,7 +60,7 @@ class EventObserver EventHandler::cachePlugins(EventHandler::class); $wrapper->getAPI()->setEventHandler(EventHandler::class); } catch (Throwable $e) { - static::removeSessionClient($session); + self::removeSessionClient($session); error('Cant set EventHandler', [ 'session' => $session, 'exception' => Logger::getExceptionAsArray($e), @@ -79,11 +79,11 @@ class EventObserver $sessions[] = $requestedSession; } foreach ($sessions as $session) { - static::removeSessionClient($session); - if (empty(static::$sessionClients[$session]) || $force) { + self::removeSessionClient($session); + if (empty(self::$sessionClients[$session]) || $force) { warning("Stopping EventHandler: {$session}"); Client::getInstance()->instances[$session]->unsetEventHandler(); - unset(EventHandler::$instances[$session], static::$sessionClients[$session]); + unset(EventHandler::$instances[$session], self::$sessionClients[$session]); } } diff --git a/src/EventObservers/LogObserver.php b/src/EventObservers/LogObserver.php index e6b08f3..dd71990 100644 --- a/src/EventObservers/LogObserver.php +++ b/src/EventObservers/LogObserver.php @@ -11,7 +11,7 @@ class LogObserver public static function notify(string $level, string $message, array $context = []): void { - foreach (static::$subscribers as $clientId => $callback) { + foreach (self::$subscribers as $clientId => $callback) { $callback($level, $message, $context); } } diff --git a/src/EventObservers/ObserverTrait.php b/src/EventObservers/ObserverTrait.php index b02b3c5..a595b9e 100644 --- a/src/EventObservers/ObserverTrait.php +++ b/src/EventObservers/ObserverTrait.php @@ -11,17 +11,17 @@ trait ObserverTrait public static function addSubscriber($clientId, callable $callback): void { notice("Add event listener. ClientId: {$clientId}"); - static::$subscribers[$clientId] = $callback; + self::$subscribers[$clientId] = $callback; } public static function removeSubscriber($clientId): void { notice("Removing listener: {$clientId}"); - unset(static::$subscribers[$clientId]); - $listenersCount = count(static::$subscribers); + unset(self::$subscribers[$clientId]); + $listenersCount = count(self::$subscribers); notice("Event listeners left: {$listenersCount}"); if ($listenersCount === 0) { - static::$subscribers = []; + self::$subscribers = []; } } } \ No newline at end of file diff --git a/src/Files.php b/src/Files.php index c98956e..30cfdb4 100644 --- a/src/Files.php +++ b/src/Files.php @@ -29,7 +29,7 @@ class Files } preg_match( - '~' . static::SESSION_FOLDER . "/(?'sessionName'.*?)" . static::SESSION_EXTENSION . '~', + '~' . self::SESSION_FOLDER . "/(?'sessionName'.*?)" . self::SESSION_EXTENSION . '~', $sessionFile, $matches ); @@ -50,14 +50,14 @@ class Files return null; } $session = trim(trim($session), '/'); - $session = static::SESSION_FOLDER . '/' . $session . $extension; + $session = self::SESSION_FOLDER . '/' . $session . $extension; $session = str_replace('//', '/', $session); return $session; } public static function getSessionSettings(string $session): array { - $settingsFile = static::getSessionFile($session, static::SETTINGS_EXTENSION); + $settingsFile = self::getSessionFile($session, self::SETTINGS_EXTENSION); $settings = []; if (file_exists($settingsFile)) { $settings = json_decode( @@ -73,7 +73,7 @@ class Files public static function saveSessionSettings(string $session, array $settings = []): void { - $settingsFile = static::getSessionFile($session, static::SETTINGS_EXTENSION); + $settingsFile = self::getSessionFile($session, self::SETTINGS_EXTENSION); file_put_contents( $settingsFile, json_encode( @@ -91,7 +91,7 @@ class Files { $files = glob($pattern, $flags) ?: []; foreach (glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) { - $files = [...$files, ...static::globRecursive($dir . '/' . basename($pattern), $flags)]; + $files = [...$files, ...self::globRecursive($dir . '/' . basename($pattern), $flags)]; } return $files; } diff --git a/src/Logger.php b/src/Logger.php index 5545913..3cfd1f5 100644 --- a/src/Logger.php +++ b/src/Logger.php @@ -111,14 +111,14 @@ class Logger extends AbstractLogger public static function getInstance(): Logger { - if (!static::$instanse) { + if (!self::$instanse) { $settings = Config::getInstance()->get('telegram'); - $loggerLevel = static::$madelineLevels[$settings['logger']['level']]; - static::$instanse = new static($loggerLevel); + $loggerLevel = self::$madelineLevels[$settings['logger']['level']]; + self::$instanse = new static($loggerLevel); } - return static::$instanse; + return self::$instanse; } /** @@ -168,7 +168,7 @@ class Logger extends AbstractLogger $replacements["{{$key}}"] = $val; } else { if ($val instanceof DateTimeInterface) { - $replacements["{{$key}}"] = $val->format(static::$dateTimeFormat); + $replacements["{{$key}}"] = $val->format(self::$dateTimeFormat); } else { if (is_object($val)) { $replacements["{{$key}}"] = '[object ' . get_class($val) . ']'; @@ -184,7 +184,7 @@ class Logger extends AbstractLogger return sprintf( '[%s] [%s] %s %s', - date(static::$dateTimeFormat), + date(self::$dateTimeFormat), $level, $message, $context ? diff --git a/src/MadelineProtoExtensions/ApiExtensions.php b/src/MadelineProtoExtensions/ApiExtensions.php index c0c8b73..874bf17 100644 --- a/src/MadelineProtoExtensions/ApiExtensions.php +++ b/src/MadelineProtoExtensions/ApiExtensions.php @@ -96,7 +96,7 @@ class ApiExtensions $textFormated = sprintf($template, $text); } - $message = static::substringReplace($message, $textFormated, $entity['offset'], $entity['length']); + $message = self::substringReplace($message, $textFormated, $entity['offset'], $entity['length']); //Увеличим оффсеты всех следующих entity foreach ($entities as $nextKey => &$nextEntity) { @@ -167,7 +167,7 @@ class ApiExtensions 'peer' => $data['to_peer'], 'entities' => $message['entities'] ?? [], ]; - if (static::hasMedia($message, false)) { + if (self::hasMedia($message, false)) { $messageData['media'] = $message; //MadelineProto сама достанет все media из сообщения. $result[] = $this->madelineProto->messages->sendMedia(...$messageData); } else { @@ -203,7 +203,7 @@ class ApiExtensions throw new NoMediaException('Empty message'); } - if (!static::hasMedia($message, true)) { + if (!self::hasMedia($message, true)) { throw new NoMediaException('Message has no media'); } @@ -246,7 +246,7 @@ class ApiExtensions throw new NoMediaException('Empty message'); } - if (!static::hasMedia($message, true)) { + if (!self::hasMedia($message, true)) { throw new NoMediaException('Message has no media'); }