### Install Spatie Backtrace Source: https://github.com/spatie/backtrace/blob/main/README.md Instructions for installing the Spatie Backtrace package using Composer. ```bash composer require spatie/backtrace ``` -------------------------------- ### Custom Argument Reduction with DateTime Source: https://github.com/spatie/backtrace/blob/main/README.md Provides an example of a custom argument reducer for `DateTimeInterface` objects, formatting them to 'd/m/y H:i'. It demonstrates how to integrate custom reducers with default ones. ```php class DateTimeWithOtherFormatArgumentReducer implements \Spatie\Backtrace\Arguments\ArgumentReducer { public function execute($argument): \Spatie\Backtrace\Arguments\ReducedArgumentContract { if (! $argument instanceof \DateTimeInterface) { return \Spatie\Backtrace\Arguments\UnReducedArgument::create(); } return new \Spatie\Backtrace\Arguments\ReducedArgument( $argument->format('d/m/y H:i'), get_class($argument) ); } } $backtrace = Spatie\Backtrace\Backtrace::create()->withArguments()->reduceArguments( Spatie\Backtrace\Arguments\ArgumentReducers::default([ new DateTimeWithOtherFormatArgumentReducer() ]) ); ``` -------------------------------- ### Create and Get Backtrace Frames Source: https://github.com/spatie/backtrace/blob/main/README.md Demonstrates how to create a backtrace instance and retrieve an array of Frame objects. Each Frame object provides details about a specific point in the execution stack. ```php $frames = Spatie\Backtrace\Backtrace::create()->frames(); $firstFrame = $frames[0]; $firstFrame->file; // returns the file name $firstFrame->lineNumber; // returns the line number $firstFrame->class; // returns the class name ``` -------------------------------- ### Get All Backtrace Frames Source: https://github.com/spatie/backtrace/blob/main/README.md Retrieves all frames from a Backtrace instance. The result is an array of `Spatie\Backtrace\Frame` objects. ```php $frames = $backtrace->frames(); ``` -------------------------------- ### Get Backtrace for a Throwable Source: https://github.com/spatie/backtrace/blob/main/README.md Generates a backtrace for a given `Throwable` object. The resulting frames may include arguments if `zend.exception_ignore_args` is disabled before the exception is thrown. Objects are never included as arguments. ```php $frames = Spatie\Backtrace\Backtrace::createForThrowable($throwable); ``` -------------------------------- ### Filter Frames Starting From a Specific Frame Source: https://github.com/spatie/backtrace/blob/main/README.md Retrieves frames from a backtrace starting from a frame that matches a given condition. The condition is defined by a callback function that receives a `Frame` object. Frames before the matching frame are excluded. ```php use Spatie\Backtrace\Backtrace; use Spatie\Backtrace\Frame; $frames = Backtrace::create() ->startingFromFrame(function (Frame $frame) { return $frame->class === MyClass::class; }) ->frames(); ``` -------------------------------- ### Create Backtrace Instance Source: https://github.com/spatie/backtrace/blob/main/README.md Shows the basic usage of creating a new Backtrace instance. ```php $backtrace = Spatie\Backtrace\Backtrace::create(); ``` -------------------------------- ### Run Tests Source: https://github.com/spatie/backtrace/blob/main/README.md Command to execute the project's test suite. ```bash composer test ``` -------------------------------- ### Set Application Path Source: https://github.com/spatie/backtrace/blob/main/README.md Specifies the application's base path to help differentiate between application frames and vendor frames in the backtrace. ```php $backtrace = Spatie\Backtrace\Backtrace::create()->applicationPath(base_path()); ``` -------------------------------- ### Collect Arguments and Objects in Frames Source: https://github.com/spatie/backtrace/blob/main/README.md Enables the inclusion of function arguments and object context within each frame for more detailed analysis. This can impact performance. ```php $backtrace = Spatie\Backtrace\Backtrace::create()->withArguments()->withObject(); ``` -------------------------------- ### Reduce Arguments to String Source: https://github.com/spatie/backtrace/blob/main/README.md Configures the backtrace to reduce complex arguments to their string representation for easier viewing. Custom reduction logic can be applied. ```php $backtrace = Spatie\Backtrace\Backtrace::create()->withArguments()->reduceArguments(); ``` -------------------------------- ### Trim Application Path from File Names Source: https://github.com/spatie/backtrace/blob/main/README.md Removes the application's base path from file names in the backtrace using the `trimFilePaths` method. This requires the `applicationPath` method to be set beforehand. Ensures the `Frame` object has the `trimmedFilePath` property. ```php $backtrace = Backtrace::create()->applicationPath(base_path())->trimFilePaths()); ``` -------------------------------- ### Skip Frames Using Offset Source: https://github.com/spatie/backtrace/blob/main/README.md Skips a specified number of frames from the beginning of the backtrace. The `offset` method takes an integer representing the number of frames to ignore. ```php $frames = Spatie\Backtrace\Backtrace::create() ->offset(2) ->frames(); ``` -------------------------------- ### Limit the Number of Frames Source: https://github.com/spatie/backtrace/blob/main/README.md Restricts the backtrace to a specific number of frames from the beginning. The `limit` method accepts an integer to define the maximum number of frames to retrieve. ```php $frames = Spatie\Backtrace\Backtrace::create() ->limit(2) ->frames(); ``` -------------------------------- ### TestClass Definition Source: https://github.com/spatie/backtrace/blob/main/tests/__snapshots__/CodeSnippetTest__it_can_get_a_file_code_snippet_as_a_string__1.txt Defines the `TestClass` used for testing the Spatie Backtrace functionality. It includes properties to control the surrounding lines and snippet line count for backtrace generation. ```php namespace Spatie\Backtrace\Tests\TestClasses; use RuntimeException; class TestClass { /** @var int */ protected $surroundingLine = 1; /** @var int */ protected $snippetLineCount = 9; public function surroundingLine(int $surroundingLine): self { $this->surroundingLine = $surroundingLine; return $this; } public function snippetLineCount(int $snippetLineCount): self { $this->snippetLineCount = $snippetLineCount; return $this; } public function getSurroundingLine(): int { return $this->surroundingLine; } public function getSnippetLineCount(): int { return $this->snippetLineCount; } public function throwException(): void { throw new RuntimeException('Something went wrong'); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.