vendor and env first commit

This commit is contained in:
2025-03-28 08:52:46 +01:00
parent f8388bc81b
commit 8f26283832
10976 changed files with 1349952 additions and 2 deletions
@@ -0,0 +1,107 @@
<?php
namespace Spatie\LaravelIgnition\Support;
use InvalidArgumentException;
use Monolog\Handler\AbstractProcessingHandler;
use Monolog\Level;
use Monolog\Logger;
use Monolog\LogRecord;
use Spatie\FlareClient\Flare;
use Spatie\FlareClient\Report;
use Throwable;
class FlareLogHandler extends AbstractProcessingHandler
{
protected Flare $flare;
protected SentReports $sentReports;
protected int $minimumReportLogLevel;
public function __construct(Flare $flare, SentReports $sentReports, $level = Level::Debug, $bubble = true)
{
$this->flare = $flare;
$this->minimumReportLogLevel = Level::Error->value;
$this->sentReports = $sentReports;
parent::__construct($level, $bubble);
}
public function setMinimumReportLogLevel(int $level): void
{
if (! in_array($level, Level::VALUES)) {
throw new InvalidArgumentException('The given minimum log level is not supported.');
}
$this->minimumReportLogLevel = $level;
}
protected function write(LogRecord $record): void
{
if (! $this->shouldReport($record->toArray())) {
return;
}
if ($this->hasException($record->toArray())) {
$report = $this->flare->report($record['context']['exception']);
if ($report) {
$this->sentReports->add($report);
}
return;
}
if (config('flare.send_logs_as_events')) {
if ($this->hasValidLogLevel($record->toArray())) {
$this->flare->reportMessage(
$record['message'],
'Log ' . Logger::toMonologLevel($record['level'])->getName(),
function (Report $flareReport) use ($record) {
foreach ($record['context'] as $key => $value) {
$flareReport->context($key, $value);
}
}
);
}
}
}
/**
* @param array<string, mixed> $report
*
* @return bool
*/
protected function shouldReport(array $report): bool
{
if (! config('flare.key')) {
return false;
}
return $this->hasException($report) || $this->hasValidLogLevel($report);
}
/**
* @param array<string, mixed> $report
*
* @return bool
*/
protected function hasException(array $report): bool
{
$context = $report['context'];
return isset($context['exception']) && $context['exception'] instanceof Throwable;
}
/**
* @param array<string, mixed> $report
*
* @return bool
*/
protected function hasValidLogLevel(array $report): bool
{
return $report['level'] >= $this->minimumReportLogLevel;
}
}
@@ -0,0 +1,61 @@
<?php
namespace Spatie\LaravelIgnition\Support;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Spatie\LaravelIgnition\Exceptions\ViewException;
use Throwable;
class LaravelDocumentationLinkFinder
{
public function findLinkForThrowable(Throwable $throwable): ?string
{
if ($throwable instanceof ViewException) {
$throwable = $throwable->getPrevious();
}
$majorVersion = LaravelVersion::major();
if (str_contains($throwable->getMessage(), Collection::class)) {
return "https://laravel.com/docs/{$majorVersion}.x/collections#available-methods";
}
$type = $this->getType($throwable);
if (! $type) {
return null;
}
return match ($type) {
'Auth' => "https://laravel.com/docs/{$majorVersion}.x/authentication",
'Broadcasting' => "https://laravel.com/docs/{$majorVersion}.x/broadcasting",
'Container' => "https://laravel.com/docs/{$majorVersion}.x/container",
'Database' => "https://laravel.com/docs/{$majorVersion}.x/eloquent",
'Pagination' => "https://laravel.com/docs/{$majorVersion}.x/pagination",
'Queue' => "https://laravel.com/docs/{$majorVersion}.x/queues",
'Routing' => "https://laravel.com/docs/{$majorVersion}.x/routing",
'Session' => "https://laravel.com/docs/{$majorVersion}.x/session",
'Validation' => "https://laravel.com/docs/{$majorVersion}.x/validation",
'View' => "https://laravel.com/docs/{$majorVersion}.x/views",
default => null,
};
}
protected function getType(?Throwable $throwable): ?string
{
if (! $throwable) {
return null;
}
if (str_contains($throwable::class, 'Illuminate')) {
return Str::between($throwable::class, 'Illuminate\\', '\\');
}
if (str_contains($throwable->getMessage(), 'Illuminate')) {
return explode('\\', Str::between($throwable->getMessage(), 'Illuminate\\', '\\'))[0];
}
return null;
}
}
@@ -0,0 +1,11 @@
<?php
namespace Spatie\LaravelIgnition\Support;
class LaravelVersion
{
public static function major(): string
{
return explode('.', app()->version())[0];
}
}
@@ -0,0 +1,37 @@
<?php
namespace Spatie\LaravelIgnition\Support;
class RunnableSolutionsGuard
{
/**
* Check if runnable solutions are allowed based on the current
* environment and config.
*
* @return bool
*/
public static function check(): bool
{
if (! config('app.debug')) {
// Never run solutions in when debug mode is not enabled.
return false;
}
if (config('ignition.enable_runnable_solutions') !== null) {
// Allow enabling or disabling runnable solutions regardless of environment
// if the IGNITION_ENABLE_RUNNABLE_SOLUTIONS env var is explicitly set.
return config('ignition.enable_runnable_solutions');
}
if (! app()->environment('local') && ! app()->environment('development')) {
// Never run solutions on non-local environments. This avoids exposing
// applications that are somehow APP_ENV=production with APP_DEBUG=true.
return false;
}
return config('app.debug');
}
}
@@ -0,0 +1,54 @@
<?php
namespace Spatie\LaravelIgnition\Support;
use Illuminate\Support\Arr;
use Spatie\FlareClient\Report;
class SentReports
{
/** @var array<int, Report> */
protected array $reports = [];
public function add(Report $report): self
{
$this->reports[] = $report;
return $this;
}
/** @return array<int, Report> */
public function all(): array
{
return $this->reports;
}
/** @return array<int, string> */
public function uuids(): array
{
return array_map(fn (Report $report) => $report->trackingUuid(), $this->reports);
}
/** @return array<int, string> */
public function urls(): array
{
return array_map(function (string $trackingUuid) {
return "https://flareapp.io/tracked-occurrence/{$trackingUuid}";
}, $this->uuids());
}
public function latestUuid(): ?string
{
return Arr::last($this->reports)?->trackingUuid();
}
public function latestUrl(): ?string
{
return Arr::last($this->urls());
}
public function clear(): void
{
$this->reports = [];
}
}