| 1 |
<?php |
| 2 |
|
| 3 |
declare (strict_types=1); |
| 4 |
namespace WCPOS\Vendor\Sentry; |
| 5 |
|
| 6 |
use WCPOS\Vendor\Sentry\Serializer\RepresentationSerializerInterface; |
| 7 |
use WCPOS\Vendor\Sentry\Util\PHPConfiguration; |
| 8 |
/** |
| 9 |
* This class builds {@see Stacktrace} objects from an instance of an exception |
| 10 |
* or from a backtrace. |
| 11 |
* |
| 12 |
* @phpstan-import-type StacktraceFrame from FrameBuilder |
| 13 |
*/ |
| 14 |
final class StacktraceBuilder |
| 15 |
{ |
| 16 |
/** |
| 17 |
* @var FrameBuilder An instance of the builder of {@see Frame} objects |
| 18 |
*/ |
| 19 |
private $frameBuilder; |
| 20 |
/** |
| 21 |
* Constructor. |
| 22 |
* |
| 23 |
* @param Options $options The SDK client options |
| 24 |
* @param RepresentationSerializerInterface $representationSerializer The representation serializer |
| 25 |
*/ |
| 26 |
public function __construct(Options $options, RepresentationSerializerInterface $representationSerializer) |
| 27 |
{ |
| 28 |
$this->frameBuilder = new FrameBuilder($options, $representationSerializer); |
| 29 |
if (PHPConfiguration::isBooleanIniOptionEnabled('zend.exception_ignore_args')) { |
| 30 |
$options->getLoggerOrNullLogger()->warning('The "zend.exception_ignore_args" PHP setting is enabled which results in missing stack trace arguments, see: https://docs.sentry.io/platforms/php/troubleshooting/#missing-variables-in-stack-traces.'); |
| 31 |
} |
| 32 |
} |
| 33 |
/** |
| 34 |
* Builds a {@see Stacktrace} object from the given exception. |
| 35 |
* |
| 36 |
* @param \Throwable $exception The exception object |
| 37 |
*/ |
| 38 |
public function buildFromException(\Throwable $exception) : Stacktrace |
| 39 |
{ |
| 40 |
return $this->buildFromBacktrace($exception->getTrace(), $exception->getFile(), $exception->getLine()); |
| 41 |
} |
| 42 |
/** |
| 43 |
* Builds a {@see Stacktrace} object from the given backtrace. |
| 44 |
* |
| 45 |
* @param array<int, array<string, mixed>> $backtrace The backtrace |
| 46 |
* @param string $file The file where the backtrace originated from |
| 47 |
* @param int $line The line from which the backtrace originated from |
| 48 |
* |
| 49 |
* @phpstan-param list<StacktraceFrame> $backtrace |
| 50 |
*/ |
| 51 |
public function buildFromBacktrace(array $backtrace, string $file, int $line) : Stacktrace |
| 52 |
{ |
| 53 |
$frames = []; |
| 54 |
foreach ($backtrace as $backtraceFrame) { |
| 55 |
$frames[] = $this->frameBuilder->buildFromBacktraceFrame($file, $line, $backtraceFrame); |
| 56 |
$file = $backtraceFrame['file'] ?? Frame::INTERNAL_FRAME_FILENAME; |
| 57 |
$line = $backtraceFrame['line'] ?? 0; |
| 58 |
} |
| 59 |
// Add a final stackframe for the first method ever of this stacktrace |
| 60 |
$frames[] = $this->frameBuilder->buildFromBacktraceFrame($file, $line, []); |
| 61 |
return new Stacktrace(\array_reverse($frames)); |
| 62 |
} |
| 63 |
} |
| 64 |
|