From 4b068a8e8b5cf6d90f566d283fd193f305f406fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?SIGUI=20Kess=C3=A9=20Emmanuel?= Date: Sat, 15 Jul 2023 14:50:36 +0100 Subject: [PATCH] :heavy_plus_sign: Use sikessem/debugger --- composer.json | 3 +- src/Exception/HasExceptionConstructor.php | 3 +- src/Support/Backtrace.php | 106 ---------------------- 3 files changed, 3 insertions(+), 109 deletions(-) delete mode 100644 src/Support/Backtrace.php diff --git a/composer.json b/composer.json index 0f8cc7e..ab5d1fe 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,8 @@ ], "require": { "php": "^8.1||^8.2", - "psr/container": "^2.0" + "psr/container": "^2.0", + "sikessem/debugger": "^0.0.0" }, "require-dev": { "sikessem/devtools": "^0.0.0" diff --git a/src/Exception/HasExceptionConstructor.php b/src/Exception/HasExceptionConstructor.php index bcacfe4..9a1c89a 100644 --- a/src/Exception/HasExceptionConstructor.php +++ b/src/Exception/HasExceptionConstructor.php @@ -2,7 +2,6 @@ namespace Sikessem\Capsule\Exception; -use Sikessem\Capsule\Support\Backtrace; use Throwable; trait HasExceptionConstructor @@ -19,7 +18,7 @@ public static function with(string $message = '', array $arguments = [], int $co } $super = new self($message, $code, $previous); - $trace = new Backtrace(limit: 3); + $trace = backtrace(limit: 3); $file = $trace->getFile(0); $line = $trace->getLine(0); diff --git a/src/Support/Backtrace.php b/src/Support/Backtrace.php deleted file mode 100644 index 9801f8c..0000000 --- a/src/Support/Backtrace.php +++ /dev/null @@ -1,106 +0,0 @@ -, object?: object}> - */ - private array $stack = []; - - public function __construct(int $flags = self::DEFAULT_FLAGS, int $limit = self::DEFAULT_LIMIT) - { - if ($limit !== 0) { - $limit++; - } - - $stack = debug_backtrace($flags, $limit); - array_shift($stack); - $this->stack = $stack; - } - - /** - * @return list, object?: object}> - */ - public function getStack(int $offset = null): array - { - return $this->stack; - } - - public function getDirectory(int $offset = self::DEFAULT_OFFSET): ?string - { - if ($file = $this->getFile($offset)) { - return dirname($file); - } - - return null; - } - - public function getFile(int $offset = self::DEFAULT_OFFSET): ?string - { - return $this->stack[$offset][self::FILE_FIELD] ?? null; - } - - public function getLine(int $offset = self::DEFAULT_OFFSET): ?int - { - return $this->stack[$offset][self::LINE_FIELD] ?? null; - } - - /** - * @return ?class-string - */ - public function getClass(int $offset = self::DEFAULT_OFFSET): ?string - { - return $this->stack[$offset][self::CLASS_FIELD] ?? null; - } - - public function getObject(int $offset = self::DEFAULT_OFFSET): ?object - { - return $this->stack[$offset][self::OBJECT_FIELD] ?? null; - } - - public function getFunction(int $offset = self::DEFAULT_OFFSET): ?string - { - return $this->stack[$offset][self::FUNCTION_FIELD] ?? null; - } - - public function getType(int $offset = self::DEFAULT_OFFSET): ?string - { - return $this->stack[$offset][self::FUNCTION_FIELD] ?? null; - } - - /** - * @return array|null - */ - public function getArgs(int $offset = self::DEFAULT_OFFSET): ?array - { - return $this->stack[$offset][self::ARGS_FIELD] ?? null; - } -}