🔧
This commit is contained in:
378
vendor/spatie/flare-client-php/README.md
vendored
378
vendor/spatie/flare-client-php/README.md
vendored
@@ -13,7 +13,383 @@ Using Laravel? You probably want to use [Ignition for Laravel](https://github.co
|
||||
|
||||
## Documentation
|
||||
|
||||
You can find the documentation of this package at [the docs of Flare](https://flareapp.io/docs/flare/general/welcome-to-flare).
|
||||
When creating a new project on Flare, we'll display installation instructions for your PHP app. Even though the default settings will work fine for all projects, we offer some customization options that you might like.
|
||||
|
||||
### Ignoring errors
|
||||
|
||||
The Flare client will always send all exceptions to Flare, you can change this behaviour by filtering the exceptions with a callable:
|
||||
|
||||
```php
|
||||
// Where you registered your client...
|
||||
$flare = Flare::make('YOUR-FLARE-API-KEY')
|
||||
->registerFlareHandlers();
|
||||
|
||||
$flare->filterExceptionsUsing(
|
||||
fn(Throwable $throwable) => !$throwable instanceof AuthorizationException
|
||||
);
|
||||
```
|
||||
|
||||
Additionally, you can provide a callable to the `Flare::filterReportsUsing` method to stop a report from being sent to Flare. Compared to `filterExceptionsCallable`, this can also prevent logs and errors from being sent.
|
||||
|
||||
```php
|
||||
use Spatie\FlareClient\Flare;
|
||||
|
||||
$flare = Flare::make('YOUR-API-KEY')
|
||||
->registerFlareHandlers();
|
||||
|
||||
Flare::filterReportsUsing(function(Report $report) {
|
||||
// return a boolean to control whether the report should be sent to Flare
|
||||
return true;
|
||||
});
|
||||
```
|
||||
|
||||
Finally, it is also possible to set the levels of errors reported to Flare as such:
|
||||
|
||||
```php
|
||||
$flare->reportErrorLevels(E_ALL & ~E_NOTICE); // Will send all errors except E_NOTICE errors
|
||||
```
|
||||
|
||||
### Controlling collected data
|
||||
|
||||
Just like the Laravel configuration, the generic PHP client allows you to configure which information should be sent to Flare.
|
||||
|
||||
#### Anonymizing IPs
|
||||
|
||||
By default, the Flare client collects information about the IP address of your application users. If you want to disable this information, you can call the `anonymizeIp()` method on your Flare client instance.
|
||||
|
||||
```php
|
||||
// Where you registered your client...
|
||||
$flare = Flare::make('YOUR-FLARE-API-KEY')
|
||||
->registerFlareHandlers();
|
||||
|
||||
$flare->anonymizeIp();
|
||||
```
|
||||
|
||||
#### Censoring request body fields
|
||||
|
||||
When an exception occurs in a web request, the Flare client will pass on any request fields that are present in the body.
|
||||
|
||||
In some cases, such as a login page, these request fields may contain a password that you don't want to send to Flare.
|
||||
|
||||
To censor out values of certain fields, you can use call `censorRequestBodyFields`. You should pass it the names of the fields you wish to censor.
|
||||
|
||||
```php
|
||||
// Where you registered your client...
|
||||
$flare = Flare::make('YOUR-FLARE-API-KEY')
|
||||
->registerFlareHandlers();
|
||||
|
||||
$flare->censorRequestBodyFields('password');
|
||||
```
|
||||
|
||||
This will replace the value of any sent fields named "password" with the value "<CENSORED>".
|
||||
|
||||
### Identifying users
|
||||
|
||||
When reporting an error to Flare, you can tell the Flare client, what information you have about the currently authenticated user. You can do this by providing a `user` group that holds all the information you want to share.
|
||||
|
||||
```php
|
||||
$user = YourAuthenticatedUserInstance();
|
||||
|
||||
$flare->group('user', [
|
||||
'email' => $user->email,
|
||||
'name' => $user->name,
|
||||
'additional_information' => $user->additional,
|
||||
]);
|
||||
```
|
||||
|
||||
### Linking to errors
|
||||
|
||||
When an error occurs in web request, your application will likely display a minimal error page when it's in production.
|
||||
|
||||
If a user sees this page and wants to report this error to you, the user usually only reports the URL and the time the error was seen.
|
||||
|
||||
To let your users pinpoint the exact error they saw, you can display the UUID of the error sent to Flare.
|
||||
|
||||
You can do this by displaying the UUID returned by `Flare::sentReports()->latestUuid()` in your view. Optionally, you can use `Flare::sentReports()->latestUrl()` to get a link to the error in Flare. That link isn't publicly accessible, it is only visible to Flare users that have access to the project on Flare.
|
||||
|
||||
In certain cases, multiple error can be reported to Flare in a single request. To get a hold of the UUIDs of all sent errors, you can call `Flare::sentReports()->uuids()`. You can get links to all sent errors with `Flare::sentReports()->urls()`.
|
||||
|
||||
It is possible to search for certain errors in Flare using the UUID, you can find more information about that [here](http://flareapp.io/docs/flare/general/searching-errors).
|
||||
|
||||
### Adding custom context
|
||||
|
||||
When you send an error to Flare within a non-Laravel application, we do not collect your application information - since we don't know about your specific application.
|
||||
In order to provide more information, you can add custom context to your application that will be sent along with every exception that happens in your application. This can be very useful if you want to provide key-value related information that furthermore helps you to debug a possible exception.
|
||||
|
||||
The Flare client allows you to set custom context items like this:
|
||||
|
||||
```php
|
||||
// Get access to your registered Flare client instance
|
||||
$flare->context('Tenant', 'My-Tenant-Identifier');
|
||||
```
|
||||
|
||||
This could for example be set automatically in a Laravel service provider or an event. So the next time an exception happens, this value will be sent along to Flare and you can find it on the "Context" tab.
|
||||
|
||||
#### Grouping multiple context items
|
||||
|
||||
Sometimes you may want to group your context items by a key that you provide to have an easier visual differentiation when you look at your custom context items.
|
||||
|
||||
The Flare client allows you to also provide your own custom context groups like this:
|
||||
|
||||
```php
|
||||
// Get access to your registered Flare client instance
|
||||
$flare->group('Custom information', [
|
||||
'key' => 'value',
|
||||
'another key' => 'another value',
|
||||
]);
|
||||
```
|
||||
|
||||
### Adding glows
|
||||
|
||||
In addition to custom context items, you can also add "Glows" to your application.
|
||||
Glows allow you to add little pieces of information, that can later be found in a chronological order in the "Debug" tab of your application.
|
||||
|
||||
You can think of glows as breadcrumbs that can help you track down which parts of your code an exception went through.
|
||||
|
||||
The Flare PHP client allows you to add a glows to your application like this:
|
||||
|
||||
|
||||
### Stacktrace arguments
|
||||
|
||||
|
||||
When an error occurs in your application, Flare will send the stacktrace of the error to Flare. This stacktrace contains the file and line number where the error occurred and the argument values passed to the function or method that caused the error.
|
||||
|
||||
These argument values have been significantly reduced to make them easier to read and reduce the amount of data sent to Flare, which means that the arguments are not always complete. To see the full arguments, you can always use a glow to send the whole parameter to Flare.
|
||||
|
||||
For example, let's say you have the following Carbon object:
|
||||
|
||||
```php
|
||||
new DateTime('2020-05-16 14:00:00', new DateTimeZone('Europe/Brussels'))
|
||||
```
|
||||
|
||||
Flare will automatically reduce this to the following:
|
||||
|
||||
```
|
||||
16 May 2020 14:00:00 +02:00
|
||||
```
|
||||
|
||||
It is possible to configure how these arguments are reduced. You can even implement your own reducers!
|
||||
|
||||
By default, the following reducers are used:
|
||||
|
||||
- BaseTypeArgumentReducer
|
||||
- ArrayArgumentReducer
|
||||
- StdClassArgumentReducer
|
||||
- EnumArgumentReducer
|
||||
- ClosureArgumentReducer
|
||||
- DateTimeArgumentReducer
|
||||
- DateTimeZoneArgumentReducer
|
||||
- SymphonyRequestArgumentReducer
|
||||
- StringableArgumentReducer
|
||||
|
||||
#### Implementing your reducer
|
||||
|
||||
Each reducer implements `Spatie\FlareClient\Arguments\Reducers\ArgumentReducer`. This interface contains a single method, `execute` which provides the original argument value:
|
||||
|
||||
```php
|
||||
interface ArgumentReducer
|
||||
{
|
||||
public function execute(mixed $argument): ReducedArgumentContract;
|
||||
}
|
||||
```
|
||||
|
||||
In the end, three types of values can be returned:
|
||||
|
||||
When the reducer could not reduce this type of argument value:
|
||||
|
||||
```php
|
||||
return UnReducedArgument::create();
|
||||
```
|
||||
|
||||
When the reducer could reduce the argument value, but a part was truncated due to the size:
|
||||
|
||||
```php
|
||||
return new TruncatedReducedArgument(
|
||||
array_slice($argument, 0, 25), // The reduced value
|
||||
'array' // The original type of the argument
|
||||
);
|
||||
```
|
||||
|
||||
When the reducer could reduce the full argument value:
|
||||
|
||||
```php
|
||||
return new TruncatedReducedArgument(
|
||||
$argument, // The reduced value
|
||||
'array' // The original type of the argument
|
||||
);
|
||||
```
|
||||
|
||||
For example, the `DateTimeArgumentReducer` from the example above looks like this:
|
||||
|
||||
```php
|
||||
class DateTimeArgumentReducer implements ArgumentReducer
|
||||
{
|
||||
public function execute(mixed $argument): ReducedArgumentContract
|
||||
{
|
||||
if (! $argument instanceof \DateTimeInterface) {
|
||||
return UnReducedArgument::create();
|
||||
}
|
||||
|
||||
return new ReducedArgument(
|
||||
$argument->format('d M Y H:i:s p'),
|
||||
get_class($argument),
|
||||
);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Configuring the reducers
|
||||
|
||||
Reducers can be added as such:
|
||||
|
||||
```php
|
||||
// Where you registered your client...
|
||||
$flare = Flare::make('YOUR-FLARE-API-KEY')
|
||||
->registerFlareHandlers();
|
||||
|
||||
$flare->argumentReducers([
|
||||
BaseTypeArgumentReducer::class,
|
||||
ArrayArgumentReducer::class,
|
||||
StdClassArgumentReducer::class,
|
||||
EnumArgumentReducer::class,
|
||||
ClosureArgumentReducer::class,
|
||||
DateTimeArgumentReducer::class,
|
||||
DateTimeZoneArgumentReducer::class,
|
||||
SymphonyRequestArgumentReducer::class,
|
||||
StringableArgumentReducer::class,
|
||||
])
|
||||
```
|
||||
|
||||
Reducers are executed from top to bottom. The first reducer which doesn't return an `UnReducedArgument` will be used. Always add the default reducers when you want to define your own reducer. Otherwise, a very rudimentary reduced argument value will be used.
|
||||
|
||||
#### Disabling stack frame arguments
|
||||
|
||||
If you don't want to send any arguments to Flare, you can turn off this behavior as such:
|
||||
|
||||
```php
|
||||
// Where you registered your client...
|
||||
$flare = Flare::make('YOUR-FLARE-API-KEY')
|
||||
->registerFlareHandlers();
|
||||
|
||||
$flare->withStackFrameArguments(false);
|
||||
```
|
||||
|
||||
#### Missing arguments?
|
||||
|
||||
- Make sure you've got the latest version of Flare / Ignition
|
||||
- Check that `withStackFrameArguments` is not disabled
|
||||
- Check your ini file whether `zend.exception_ignore_args` is enabled, it should be `0`
|
||||
|
||||
|
||||
```php
|
||||
use Spatie\FlareClient\Enums\MessageLevels;
|
||||
|
||||
// Get access to your registered Flare client instance
|
||||
$flare->glow('This is a message from glow!', MessageLevels::DEBUG, func_get_args());
|
||||
```
|
||||
|
||||
### Handling exceptions
|
||||
|
||||
When an exception is thrown in an application, the application stops executing and the exception is reported to Flare.
|
||||
However, there are cases where you might want to handle the exception so that the application can continue running. And
|
||||
the user isn't presented with an error message.
|
||||
|
||||
In such cases it might still be useful to report the exception to Flare, so you'll have a correct overview of what's
|
||||
going on within your application. We call such exceptions "handled exceptions".
|
||||
|
||||
When you've caught an exception in PHP it can still be reported to Flare:
|
||||
|
||||
```php
|
||||
try {
|
||||
// Code that might throw an exception
|
||||
} catch (Exception $exception) {
|
||||
$flare->reportHandled($exception);
|
||||
}
|
||||
```
|
||||
|
||||
In Flare, we'll show that the exception was handled, it is possible to filter these exceptions. You'll find more about filtering exceptions [here](https://flareapp.io/docs/flare/general/searching-errors).
|
||||
|
||||
### Writing custom middleware
|
||||
|
||||
Before Flare receives the data that was collected from your local exception, we give you the ability to call custom middleware methods.
|
||||
These methods retrieve the report that should be sent to Flare and allow you to add custom information to that report.
|
||||
|
||||
Just like with the Flare client itself, you can add custom context information to your report as well. This allows you to structure your code so that you have all context related changes in one place.
|
||||
|
||||
You can register a custom middleware by using the `registerMiddleware` method on the `Spatie\FlareClient\Flare` class, like this:
|
||||
|
||||
```php
|
||||
use Spatie\FlareClient\Report;
|
||||
|
||||
// Get access to your registered Flare client instance
|
||||
$flare->registerMiddleware(function (Report $report, $next) {
|
||||
// Add custom information to the report
|
||||
$report->context('key', 'value');
|
||||
|
||||
return $next($report);
|
||||
});
|
||||
```
|
||||
|
||||
To create a middleware that, for example, removes all the session data before your report gets sent to Flare, the middleware implementation might look like this:
|
||||
|
||||
```php
|
||||
use Spatie\FlareClient\Report;
|
||||
|
||||
class FlareMiddleware
|
||||
{
|
||||
public function handle(Report $report, $next)
|
||||
{
|
||||
$context = $report->allContext();
|
||||
|
||||
$context['session'] = null;
|
||||
|
||||
$report->userProvidedContext($context);
|
||||
|
||||
return $next($report);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Identifying users
|
||||
|
||||
When reporting an error to Flare, you can tell the Flare client, what information you have about the currently authenticated user. You can do this by providing a `user` group that holds all the information you want to share.
|
||||
|
||||
```php
|
||||
$user = YourAuthenticatedUserInstance();
|
||||
|
||||
$flare->group('user', [
|
||||
'email' => $user->email,
|
||||
'name' => $user->name,
|
||||
'additional_information' => $user->additional,
|
||||
]);
|
||||
```
|
||||
|
||||
### Customizing error grouping
|
||||
|
||||
Flare has a [special grouping](https://flareapp.io/docs/flare/general/error-grouping) algorithm that groups similar error occurrences into errors to make understanding what's going on in your application easier.
|
||||
|
||||
While the default grouping algorithm works for 99% of the cases, there are some cases where you might want to customize the grouping.
|
||||
|
||||
This can be done on an exception class base, you can tell Flare to group all exceptions of a specific class together:
|
||||
|
||||
```php
|
||||
use Spatie\FlareClient\Enums\OverriddenGrouping;
|
||||
|
||||
$flare->overrideGrouping(SomeExceptionClass::class, OverriddenGrouping::ExceptionClass);
|
||||
```
|
||||
|
||||
In this case every exception of the `SomeExceptionClass` will be grouped together no matter what the message or stack trace is.
|
||||
|
||||
It is also possible to group exceptions of the same class together, but also take the message into account:
|
||||
|
||||
```php
|
||||
use Spatie\FlareClient\Enums\OverriddenGrouping;
|
||||
|
||||
$flare->overrideGrouping(SomeExceptionClass::class, OverriddenGrouping::ExceptionMessageAndClass);
|
||||
```
|
||||
|
||||
Be careful when grouping by class and message, since every occurrence might have a slightly different message, this could lead to a lot of different errors.
|
||||
|
||||
|
||||
## Changelog
|
||||
|
||||
|
||||
9
vendor/spatie/flare-client-php/composer.json
vendored
9
vendor/spatie/flare-client-php/composer.json
vendored
@@ -11,20 +11,19 @@
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"php": "^8.0",
|
||||
"illuminate/pipeline": "^8.0|^9.0|^10.0|^11.0",
|
||||
"spatie/backtrace": "^1.5.2",
|
||||
"illuminate/pipeline": "^8.0|^9.0|^10.0|^11.0|^12.0",
|
||||
"spatie/backtrace": "^1.6.1",
|
||||
"symfony/http-foundation": "^5.2|^6.0|^7.0",
|
||||
"symfony/mime": "^5.2|^6.0|^7.0",
|
||||
"symfony/process": "^5.2|^6.0|^7.0",
|
||||
"symfony/var-dumper": "^5.2|^6.0|^7.0",
|
||||
"nesbot/carbon": "^2.62.1"
|
||||
"symfony/var-dumper": "^5.2|^6.0|^7.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"dms/phpunit-arraysubset-asserts": "^0.5.0",
|
||||
"phpstan/extension-installer": "^1.1",
|
||||
"phpstan/phpstan-deprecation-rules": "^1.0",
|
||||
"phpstan/phpstan-phpunit": "^1.0",
|
||||
"spatie/phpunit-snapshot-assertions": "^4.0|^5.0",
|
||||
"spatie/pest-plugin-snapshots": "^1.0|^2.0",
|
||||
"pestphp/pest": "^1.20|^2.0"
|
||||
},
|
||||
"autoload": {
|
||||
|
||||
@@ -4,6 +4,8 @@ namespace Spatie\FlareClient\Context;
|
||||
|
||||
use RuntimeException;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
use Symfony\Component\HttpFoundation\InputBag;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Mime\Exception\InvalidArgumentException;
|
||||
use Throwable;
|
||||
@@ -12,7 +14,7 @@ class RequestContextProvider implements ContextProvider
|
||||
{
|
||||
protected ?Request $request;
|
||||
|
||||
public function __construct(Request $request = null)
|
||||
public function __construct(?Request $request = null)
|
||||
{
|
||||
$this->request = $request ?? Request::createFromGlobals();
|
||||
}
|
||||
@@ -138,11 +140,26 @@ class RequestContextProvider implements ContextProvider
|
||||
{
|
||||
return [
|
||||
'queryString' => $this->request->query->all(),
|
||||
'body' => $this->request->request->all(),
|
||||
'body' => $this->getInputBag()->all() + $this->request->query->all(),
|
||||
'files' => $this->getFiles(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getInputBag(): InputBag|ParameterBag
|
||||
{
|
||||
$contentType = $this->request->headers->get('CONTENT_TYPE', 'text/html');
|
||||
|
||||
$isJson = str_contains($contentType, '/json') || str_contains($contentType, '+json');
|
||||
|
||||
if ($isJson) {
|
||||
return new InputBag((array) json_decode($this->request->getContent(), true));
|
||||
}
|
||||
|
||||
return in_array($this->request->getMethod(), ['GET', 'HEAD'])
|
||||
? $this->request->query
|
||||
: $this->request->request;
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function toArray(): array
|
||||
{
|
||||
|
||||
10
vendor/spatie/flare-client-php/src/Enums/OverriddenGrouping.php
vendored
Normal file
10
vendor/spatie/flare-client-php/src/Enums/OverriddenGrouping.php
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\FlareClient\Enums;
|
||||
|
||||
class OverriddenGrouping
|
||||
{
|
||||
const ExceptionClass = 'exception_class';
|
||||
const ExceptionMessage = 'exception_message';
|
||||
const ExceptionMessageAndClass = 'exception_message_and_class';
|
||||
}
|
||||
61
vendor/spatie/flare-client-php/src/Flare.php
vendored
Normal file → Executable file
61
vendor/spatie/flare-client-php/src/Flare.php
vendored
Normal file → Executable file
@@ -13,6 +13,7 @@ use Spatie\FlareClient\Concerns\HasContext;
|
||||
use Spatie\FlareClient\Context\BaseContextProviderDetector;
|
||||
use Spatie\FlareClient\Context\ContextProviderDetector;
|
||||
use Spatie\FlareClient\Enums\MessageLevels;
|
||||
use Spatie\FlareClient\Enums\OverriddenGrouping;
|
||||
use Spatie\FlareClient\FlareMiddleware\AddEnvironmentInformation;
|
||||
use Spatie\FlareClient\FlareMiddleware\AddGlows;
|
||||
use Spatie\FlareClient\FlareMiddleware\CensorRequestBodyFields;
|
||||
@@ -21,6 +22,7 @@ use Spatie\FlareClient\FlareMiddleware\RemoveRequestIp;
|
||||
use Spatie\FlareClient\Glows\Glow;
|
||||
use Spatie\FlareClient\Glows\GlowRecorder;
|
||||
use Spatie\FlareClient\Http\Client;
|
||||
use Spatie\FlareClient\Support\PhpStackFrameArgumentsFixer;
|
||||
use Throwable;
|
||||
|
||||
class Flare
|
||||
@@ -40,7 +42,7 @@ class Flare
|
||||
|
||||
protected ContextProviderDetector $contextDetector;
|
||||
|
||||
protected $previousExceptionHandler = null;
|
||||
protected mixed $previousExceptionHandler = null;
|
||||
|
||||
/** @var null|callable */
|
||||
protected $previousErrorHandler = null;
|
||||
@@ -67,9 +69,12 @@ class Flare
|
||||
|
||||
protected bool $withStackFrameArguments = true;
|
||||
|
||||
/** @var array<class-string, string> */
|
||||
protected array $overriddenGroupings = [];
|
||||
|
||||
public static function make(
|
||||
string $apiKey = null,
|
||||
ContextProviderDetector $contextDetector = null
|
||||
?string $apiKey = null,
|
||||
?ContextProviderDetector $contextDetector = null
|
||||
): self {
|
||||
$client = new Client($apiKey);
|
||||
|
||||
@@ -145,10 +150,28 @@ class Flare
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withStackFrameArguments(bool $withStackFrameArguments = true): self
|
||||
{
|
||||
public function withStackFrameArguments(
|
||||
bool $withStackFrameArguments = true,
|
||||
bool $forcePHPIniSetting = false,
|
||||
): self {
|
||||
$this->withStackFrameArguments = $withStackFrameArguments;
|
||||
|
||||
if ($forcePHPIniSetting) {
|
||||
(new PhpStackFrameArgumentsFixer())->enable();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string $exceptionClass
|
||||
*/
|
||||
public function overrideGrouping(
|
||||
string $exceptionClass,
|
||||
string $type = OverriddenGrouping::ExceptionMessageAndClass,
|
||||
): self {
|
||||
$this->overriddenGroupings[$exceptionClass] = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -168,7 +191,7 @@ class Flare
|
||||
*/
|
||||
public function __construct(
|
||||
Client $client,
|
||||
ContextProviderDetector $contextDetector = null,
|
||||
?ContextProviderDetector $contextDetector = null,
|
||||
array $middleware = [],
|
||||
) {
|
||||
$this->client = $client;
|
||||
@@ -211,15 +234,16 @@ class Flare
|
||||
|
||||
public function registerExceptionHandler(): self
|
||||
{
|
||||
/** @phpstan-ignore-next-line */
|
||||
$this->previousExceptionHandler = set_exception_handler([$this, 'handleException']);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function registerErrorHandler(): self
|
||||
public function registerErrorHandler(?int $errorLevels = null): self
|
||||
{
|
||||
$this->previousErrorHandler = set_error_handler([$this, 'handleError']);
|
||||
$this->previousErrorHandler = $errorLevels
|
||||
? set_error_handler([$this, 'handleError'], $errorLevels)
|
||||
: set_error_handler([$this, 'handleError']);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -294,8 +318,8 @@ class Flare
|
||||
if ($this->previousErrorHandler) {
|
||||
return call_user_func(
|
||||
$this->previousErrorHandler,
|
||||
$message,
|
||||
$code,
|
||||
$message,
|
||||
$file,
|
||||
$line
|
||||
);
|
||||
@@ -309,7 +333,7 @@ class Flare
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function report(Throwable $throwable, callable $callback = null, Report $report = null): ?Report
|
||||
public function report(Throwable $throwable, ?callable $callback = null, ?Report $report = null, ?bool $handled = null): ?Report
|
||||
{
|
||||
if (! $this->shouldSendReport($throwable)) {
|
||||
return null;
|
||||
@@ -317,6 +341,10 @@ class Flare
|
||||
|
||||
$report ??= $this->createReport($throwable);
|
||||
|
||||
if ($handled) {
|
||||
$report->handled();
|
||||
}
|
||||
|
||||
if (! is_null($callback)) {
|
||||
call_user_func($callback, $report);
|
||||
}
|
||||
@@ -328,6 +356,11 @@ class Flare
|
||||
return $report;
|
||||
}
|
||||
|
||||
public function reportHandled(Throwable $throwable): ?Report
|
||||
{
|
||||
return $this->report($throwable, null, null, true);
|
||||
}
|
||||
|
||||
protected function shouldSendReport(Throwable $throwable): bool
|
||||
{
|
||||
if (isset($this->reportErrorLevels) && $throwable instanceof Error) {
|
||||
@@ -345,7 +378,7 @@ class Flare
|
||||
return true;
|
||||
}
|
||||
|
||||
public function reportMessage(string $message, string $logLevel, callable $callback = null): void
|
||||
public function reportMessage(string $message, string $logLevel, ?callable $callback = null): void
|
||||
{
|
||||
$report = $this->createReportFromMessage($message, $logLevel);
|
||||
|
||||
@@ -420,7 +453,8 @@ class Flare
|
||||
$this->applicationPath,
|
||||
$this->version(),
|
||||
$this->argumentReducers,
|
||||
$this->withStackFrameArguments
|
||||
$this->withStackFrameArguments,
|
||||
$this->overriddenGroupings,
|
||||
);
|
||||
|
||||
return $this->applyMiddlewareToReport($report);
|
||||
@@ -449,6 +483,7 @@ class Flare
|
||||
: $singleMiddleware;
|
||||
}, $this->middleware);
|
||||
|
||||
|
||||
$report = (new Pipeline())
|
||||
->send($report)
|
||||
->through($middleware)
|
||||
|
||||
@@ -3,14 +3,15 @@
|
||||
namespace Spatie\FlareClient\FlareMiddleware;
|
||||
|
||||
use Closure;
|
||||
use Spatie\ErrorSolutions\Contracts\SolutionProviderRepository;
|
||||
use Spatie\FlareClient\Report;
|
||||
use Spatie\Ignition\Contracts\SolutionProviderRepository;
|
||||
use Spatie\Ignition\Contracts\SolutionProviderRepository as IgnitionSolutionProviderRepository;
|
||||
|
||||
class AddSolutions implements FlareMiddleware
|
||||
{
|
||||
protected SolutionProviderRepository $solutionProviderRepository;
|
||||
protected SolutionProviderRepository|IgnitionSolutionProviderRepository $solutionProviderRepository;
|
||||
|
||||
public function __construct(SolutionProviderRepository $solutionProviderRepository)
|
||||
public function __construct(SolutionProviderRepository|IgnitionSolutionProviderRepository $solutionProviderRepository)
|
||||
{
|
||||
$this->solutionProviderRepository = $solutionProviderRepository;
|
||||
}
|
||||
|
||||
48
vendor/spatie/flare-client-php/src/Report.php
vendored
48
vendor/spatie/flare-client-php/src/Report.php
vendored
@@ -7,14 +7,16 @@ use Spatie\Backtrace\Arguments\ArgumentReducers;
|
||||
use Spatie\Backtrace\Arguments\Reducers\ArgumentReducer;
|
||||
use Spatie\Backtrace\Backtrace;
|
||||
use Spatie\Backtrace\Frame as SpatieFrame;
|
||||
use Spatie\ErrorSolutions\Contracts\Solution;
|
||||
use Spatie\FlareClient\Concerns\HasContext;
|
||||
use Spatie\FlareClient\Concerns\UsesTime;
|
||||
use Spatie\FlareClient\Context\ContextProvider;
|
||||
use Spatie\FlareClient\Contracts\ProvidesFlareContext;
|
||||
use Spatie\FlareClient\Glows\Glow;
|
||||
use Spatie\FlareClient\Solutions\ReportSolution;
|
||||
use Spatie\Ignition\Contracts\Solution;
|
||||
use Spatie\LaravelIgnition\Exceptions\ViewException;
|
||||
use Spatie\Ignition\Contracts\Solution as IgnitionSolution;
|
||||
use Spatie\LaravelFlare\Exceptions\ViewException;
|
||||
use Spatie\LaravelIgnition\Exceptions\ViewException as IgnitionViewException;
|
||||
use Throwable;
|
||||
|
||||
class Report
|
||||
@@ -65,7 +67,14 @@ class Report
|
||||
|
||||
public static ?string $fakeTrackingUuid = null;
|
||||
|
||||
/** @param array<class-string<ArgumentReducer>|ArgumentReducer>|ArgumentReducers|null $argumentReducers */
|
||||
protected ?bool $handled = null;
|
||||
|
||||
protected ?string $overriddenGrouping = null;
|
||||
|
||||
/**
|
||||
* @param array<class-string<ArgumentReducer>|ArgumentReducer>|ArgumentReducers|null $argumentReducers
|
||||
* @param array<class-string, string> $overriddenGroupings
|
||||
*/
|
||||
public static function createForThrowable(
|
||||
Throwable $throwable,
|
||||
ContextProvider $context,
|
||||
@@ -73,27 +82,36 @@ class Report
|
||||
?string $version = null,
|
||||
null|array|ArgumentReducers $argumentReducers = null,
|
||||
bool $withStackTraceArguments = true,
|
||||
array $overriddenGroupings = [],
|
||||
): self {
|
||||
$stacktrace = Backtrace::createForThrowable($throwable)
|
||||
->withArguments($withStackTraceArguments)
|
||||
->reduceArguments($argumentReducers)
|
||||
->applicationPath($applicationPath ?? '');
|
||||
|
||||
return (new self())
|
||||
$exceptionClass = self::getClassForThrowable($throwable);
|
||||
|
||||
$report = (new self())
|
||||
->setApplicationPath($applicationPath)
|
||||
->throwable($throwable)
|
||||
->useContext($context)
|
||||
->exceptionClass(self::getClassForThrowable($throwable))
|
||||
->exceptionClass($exceptionClass)
|
||||
->message($throwable->getMessage())
|
||||
->stackTrace($stacktrace)
|
||||
->exceptionContext($throwable)
|
||||
->setApplicationVersion($version);
|
||||
|
||||
if (array_key_exists($exceptionClass, $overriddenGroupings)) {
|
||||
$report->overriddenGrouping($overriddenGroupings[$exceptionClass]);
|
||||
}
|
||||
|
||||
return $report;
|
||||
}
|
||||
|
||||
protected static function getClassForThrowable(Throwable $throwable): string
|
||||
{
|
||||
/** @phpstan-ignore-next-line */
|
||||
if ($throwable::class === ViewException::class) {
|
||||
if ($throwable::class === IgnitionViewException::class || $throwable::class === ViewException::class) {
|
||||
/** @phpstan-ignore-next-line */
|
||||
if ($previous = $throwable->getPrevious()) {
|
||||
return get_class($previous);
|
||||
@@ -257,7 +275,7 @@ class Report
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addSolution(Solution $solution): self
|
||||
public function addSolution(Solution|IgnitionSolution $solution): self
|
||||
{
|
||||
$this->solutions[] = ReportSolution::fromSolution($solution)->toArray();
|
||||
|
||||
@@ -300,6 +318,20 @@ class Report
|
||||
return array_merge_recursive_distinct($context, $this->userProvidedContext);
|
||||
}
|
||||
|
||||
public function handled(?bool $handled = true): self
|
||||
{
|
||||
$this->handled = $handled;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function overriddenGrouping(?string $overriddenGrouping): self
|
||||
{
|
||||
$this->overriddenGrouping = $overriddenGrouping;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function exceptionContext(Throwable $throwable): self
|
||||
{
|
||||
if ($throwable instanceof ProvidesFlareContext) {
|
||||
@@ -376,6 +408,8 @@ class Report
|
||||
'application_path' => $this->applicationPath,
|
||||
'application_version' => $this->applicationVersion,
|
||||
'tracking_uuid' => $this->trackingUuid,
|
||||
'handled' => $this->handled,
|
||||
'overridden_grouping' => $this->overriddenGrouping,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -2,19 +2,21 @@
|
||||
|
||||
namespace Spatie\FlareClient\Solutions;
|
||||
|
||||
use Spatie\Ignition\Contracts\RunnableSolution;
|
||||
use Spatie\Ignition\Contracts\Solution as SolutionContract;
|
||||
use Spatie\ErrorSolutions\Contracts\RunnableSolution;
|
||||
use Spatie\ErrorSolutions\Contracts\Solution;
|
||||
use Spatie\Ignition\Contracts\RunnableSolution as IgnitionRunnableSolution;
|
||||
use Spatie\Ignition\Contracts\Solution as IgnitionSolution;
|
||||
|
||||
class ReportSolution
|
||||
{
|
||||
protected SolutionContract $solution;
|
||||
protected Solution|IgnitionSolution $solution;
|
||||
|
||||
public function __construct(SolutionContract $solution)
|
||||
public function __construct(Solution|IgnitionSolution $solution)
|
||||
{
|
||||
$this->solution = $solution;
|
||||
}
|
||||
|
||||
public static function fromSolution(SolutionContract $solution): self
|
||||
public static function fromSolution(Solution|IgnitionSolution $solution): self
|
||||
{
|
||||
return new self($solution);
|
||||
}
|
||||
@@ -24,7 +26,7 @@ class ReportSolution
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$isRunnable = ($this->solution instanceof RunnableSolution);
|
||||
$isRunnable = ($this->solution instanceof RunnableSolution || $this->solution instanceof IgnitionRunnableSolution);
|
||||
|
||||
return [
|
||||
'class' => get_class($this->solution),
|
||||
|
||||
24
vendor/spatie/flare-client-php/src/Support/PhpStackFrameArgumentsFixer.php
vendored
Normal file
24
vendor/spatie/flare-client-php/src/Support/PhpStackFrameArgumentsFixer.php
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\FlareClient\Support;
|
||||
|
||||
class PhpStackFrameArgumentsFixer
|
||||
{
|
||||
public function enable(): void
|
||||
{
|
||||
if (! $this->isCurrentlyIgnoringStackFrameArguments()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ini_set('zend.exception_ignore_args', '0');
|
||||
}
|
||||
|
||||
protected function isCurrentlyIgnoringStackFrameArguments(): bool
|
||||
{
|
||||
return match (ini_get('zend.exception_ignore_args')) {
|
||||
'1' => true,
|
||||
'0' => false,
|
||||
default => false,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user