Upgrade framework

This commit is contained in:
2023-11-14 16:54:35 +01:00
parent 1648a5cd42
commit 4fcf6fffcc
10548 changed files with 693138 additions and 466698 deletions

View File

@@ -0,0 +1,56 @@
<?php
namespace Spatie\FlareClient\FlareMiddleware;
use ArrayObject;
use Closure;
use Spatie\FlareClient\Report;
class AddDocumentationLinks implements FlareMiddleware
{
protected ArrayObject $documentationLinkResolvers;
public function __construct(ArrayObject $documentationLinkResolvers)
{
$this->documentationLinkResolvers = $documentationLinkResolvers;
}
public function handle(Report $report, Closure $next)
{
if (! $throwable = $report->getThrowable()) {
return $next($report);
}
$links = $this->getLinks($throwable);
if (count($links)) {
$report->addDocumentationLinks($links);
}
return $next($report);
}
/** @return array<int, string> */
protected function getLinks(\Throwable $throwable): array
{
$allLinks = [];
foreach ($this->documentationLinkResolvers as $resolver) {
$resolvedLinks = $resolver($throwable);
if (is_null($resolvedLinks)) {
continue;
}
if (is_string($resolvedLinks)) {
$resolvedLinks = [$resolvedLinks];
}
foreach ($resolvedLinks as $link) {
$allLinks[] = $link;
}
}
return array_values(array_unique($allLinks));
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Spatie\FlareClient\FlareMiddleware;
use Closure;
use Spatie\FlareClient\Report;
class AddEnvironmentInformation implements FlareMiddleware
{
public function handle(Report $report, Closure $next)
{
$report->group('env', [
'php_version' => phpversion(),
]);
return $next($report);
}
}

View File

@@ -0,0 +1,89 @@
<?php
namespace Spatie\FlareClient\FlareMiddleware;
use Closure;
use Spatie\FlareClient\Report;
use Symfony\Component\Process\Process;
use Throwable;
class AddGitInformation
{
protected ?string $baseDir = null;
public function handle(Report $report, Closure $next)
{
try {
$this->baseDir = $this->getGitBaseDirectory();
if (! $this->baseDir) {
return $next($report);
}
$report->group('git', [
'hash' => $this->hash(),
'message' => $this->message(),
'tag' => $this->tag(),
'remote' => $this->remote(),
'isDirty' => ! $this->isClean(),
]);
} catch (Throwable) {
}
return $next($report);
}
protected function hash(): ?string
{
return $this->command("git log --pretty=format:'%H' -n 1") ?: null;
}
protected function message(): ?string
{
return $this->command("git log --pretty=format:'%s' -n 1") ?: null;
}
protected function tag(): ?string
{
return $this->command('git describe --tags --abbrev=0') ?: null;
}
protected function remote(): ?string
{
return $this->command('git config --get remote.origin.url') ?: null;
}
protected function isClean(): bool
{
return empty($this->command('git status -s'));
}
protected function getGitBaseDirectory(): ?string
{
/** @var Process $process */
$process = Process::fromShellCommandline("echo $(git rev-parse --show-toplevel)")->setTimeout(1);
$process->run();
if (! $process->isSuccessful()) {
return null;
}
$directory = trim($process->getOutput());
if (! file_exists($directory)) {
return null;
}
return $directory;
}
protected function command($command)
{
$process = Process::fromShellCommandline($command, $this->baseDir)->setTimeout(1);
$process->run();
return trim($process->getOutput());
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace Spatie\FlareClient\FlareMiddleware;
namespace Spatie\FlareClient\FlareMiddleware;
use Closure;
use Spatie\FlareClient\Glows\GlowRecorder;
use Spatie\FlareClient\Report;
class AddGlows implements FlareMiddleware
{
protected GlowRecorder $recorder;
public function __construct(GlowRecorder $recorder)
{
$this->recorder = $recorder;
}
public function handle(Report $report, Closure $next)
{
foreach ($this->recorder->glows() as $glow) {
$report->addGlow($glow);
}
return $next($report);
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace Spatie\FlareClient\FlareMiddleware;
use Spatie\FlareClient\Report;
class AddNotifierName implements FlareMiddleware
{
public const NOTIFIER_NAME = 'Flare Client';
public function handle(Report $report, $next)
{
$report->notifierName(static::NOTIFIER_NAME);
return $next($report);
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace Spatie\FlareClient\FlareMiddleware;
use Closure;
use Spatie\FlareClient\Report;
use Spatie\Ignition\Contracts\SolutionProviderRepository;
class AddSolutions implements FlareMiddleware
{
protected SolutionProviderRepository $solutionProviderRepository;
public function __construct(SolutionProviderRepository $solutionProviderRepository)
{
$this->solutionProviderRepository = $solutionProviderRepository;
}
public function handle(Report $report, Closure $next)
{
if ($throwable = $report->getThrowable()) {
$solutions = $this->solutionProviderRepository->getSolutionsForThrowable($throwable);
foreach ($solutions as $solution) {
$report->addSolution($solution);
}
}
return $next($report);
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace Spatie\FlareClient\FlareMiddleware;
use Spatie\FlareClient\Report;
class CensorRequestBodyFields implements FlareMiddleware
{
protected array $fieldNames = [];
public function __construct(array $fieldNames)
{
$this->fieldNames = $fieldNames;
}
public function handle(Report $report, $next)
{
$context = $report->allContext();
foreach ($this->fieldNames as $fieldName) {
if (isset($context['request_data']['body'][$fieldName])) {
$context['request_data']['body'][$fieldName] = '<CENSORED>';
}
}
$report->userProvidedContext($context);
return $next($report);
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Spatie\FlareClient\FlareMiddleware;
use Spatie\FlareClient\Report;
class CensorRequestHeaders implements FlareMiddleware
{
protected array $headers = [];
public function __construct(array $headers)
{
$this->headers = $headers;
}
public function handle(Report $report, $next)
{
$context = $report->allContext();
foreach ($this->headers as $header) {
$header = strtolower($header);
if (isset($context['headers'][$header])) {
$context['headers'][$header] = '<CENSORED>';
}
}
$report->userProvidedContext($context);
return $next($report);
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace Spatie\FlareClient\FlareMiddleware;
use Closure;
use Spatie\FlareClient\Report;
interface FlareMiddleware
{
public function handle(Report $report, Closure $next);
}

View File

@@ -0,0 +1,19 @@
<?php
namespace Spatie\FlareClient\FlareMiddleware;
use Spatie\FlareClient\Report;
class RemoveRequestIp implements FlareMiddleware
{
public function handle(Report $report, $next)
{
$context = $report->allContext();
$context['request']['ip'] = null;
$report->userProvidedContext($context);
return $next($report);
}
}