diff --git a/src/Inspector/Traits/InspectorTrait.php b/src/Inspector/Traits/InspectorTrait.php index 9042308..77828d6 100644 --- a/src/Inspector/Traits/InspectorTrait.php +++ b/src/Inspector/Traits/InspectorTrait.php @@ -13,9 +13,9 @@ namespace Chevere\Xr\Inspector\Traits; -use Chevere\Xr\Exceptions\StopException; use Chevere\Xr\Interfaces\ClientInterface; use Chevere\Xr\Message; +use Throwable; trait InspectorTrait { @@ -25,26 +25,18 @@ public function __construct( } public function pause( + string $body = '', string $t = '', string $e = '', int $f = 0, ): void { - $backtrace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 1); - $message = (new Message( - backtrace: $backtrace, - )) - ->withTopic($t) - ->withEmote($e) - ->withFlags($f); - - try { - $this->client->sendPause($message); - } catch (StopException $e) { - if (PHP_SAPI === 'cli') { - echo '* ' . $e->getMessage() . PHP_EOL; - $this->client->exit(255); - } - } + $this->sendCommand( + command: 'sendPause', + body: $body, + topic: $t, + emote: $e, + flags: $f, + ); } public function memory( @@ -53,7 +45,8 @@ public function memory( int $f = 0, ): void { $memory = memory_get_usage(true); - $this->sendMessage( + $this->sendCommand( + command: 'sendMessage', body: sprintf('%.2F MB', $memory / 1000000), topic: $t, emote: $e, @@ -61,7 +54,8 @@ public function memory( ); } - private function sendMessage( + private function sendCommand( + string $command, string $body = '', string $topic = '', string $emote = '', @@ -77,6 +71,13 @@ private function sendMessage( ->withEmote($emote) ->withFlags($flags); - $this->client->sendMessage($message); + try { + $this->client->{$command}($message); + } catch (Throwable $e) { + if (PHP_SAPI === 'cli') { + echo '* ' . $e->getMessage() . PHP_EOL; + $this->client->exit(255); + } + } } } diff --git a/src/Interfaces/InspectorInterface.php b/src/Interfaces/InspectorInterface.php index c6456f5..2cf1245 100644 --- a/src/Interfaces/InspectorInterface.php +++ b/src/Interfaces/InspectorInterface.php @@ -19,6 +19,7 @@ interface InspectorInterface { public function pause( + string $body = '', string $t = '', string $e = '', int $f = 0,