To create stack trace use StackTraceFactory->create() or StackTraceFactory->createByThrowable().
Both methods have optional $limit parameter.
use Awesomite\StackTrace\StackTraceFactory;
/*
* Constructor of StackTraceFactory has two optional parameters:
*
* $varDumper - you can inject your own varDumper,
* otherwise new instance of Awesomite\VarDumper\LightVarDumper
* with default values will be used.
*
* $maxSerializableStringLen - this library
* serializes values for scalar types and null,
* for big strings you can set max length which can be serialized,
* default null (no limit).
*
* @see https://github.com/awesomite/var-dumper
*/
$factory = new StackTraceFactory();
// creates stack trace for current position
$currentStackTrace = $factory->create();
set_exception_handler(function ($exception) use ($factory) {
/** @var \Exception|\Throwable $exception */
// creates stack trace for \Exception or \Throwable
$exceptionStackTrace = $factory->createByThrowable($exception);
});Do not use @internal classes, methods and properties.
Almost all classes in project are @internal.
It means you should not use directly those classes in your project,
because backward compatibility is not supported for them and everything can change,
including constructor, class name and constants.
This project uses factories instead of public classes. Factory gives you object which implements proper interface, so you always have enough knowledge about object.
StackTraceInterface implements Traversable interface, it means $stackTrace is iterable.
foreach ($stackTrace as $step) {
// do something
}Before $step->getPlaceInCode(); you should check if place in code is available, method getPlaceInCode() will help you.
Otherwise method getPlaceInCode() can throw exception.
This principle is applied in almost all cases, except cases when returned value is always available.
$stackTrace = $factory->create();Awesomite\StackTrace\StackTraceInterfaceforeach ($stackTrace as $step) {}Awesomite\StackTrace\Steps\StepInterface$placeInCode = $step->getPlaceInCode();Awesomite\StackTrace\SourceCode\PlaceInCodeInterface$lines = $placeInCode->getAdjacentCode();Awesomite\StackTrace\SourceCode\Lines\LinesInterfaceforeach ($lines as $line) {}Awesomite\StackTrace\SourceCode\Lines\LineInterface$function = $step->getCalledFunction();Awesomite\StackTrace\Functions\FunctionInterface$arguments = $step->getArguments();Awesomite\StackTrace\Arguments\ArgumentsInterfaceforeach ($arguments as $argument) {}Awesomite\StackTrace\Arguments\ArgumentInterface$declaration = $argument->getDeclaration();Awesomite\StackTrace\Arguments\Declarations\DeclarationInterface$type = $declaration->getType();Awesomite\StackTrace\Types\TypeInterface$value = $argument->getValue();Awesomite\StackTrace\Arguments\Values\ValueInterface