Subiendo proyecto completo sin restricciones de git ignore

This commit is contained in:
Jose Sanchez
2023-08-17 11:44:02 -04:00
parent a0d4f5ba3b
commit 20f1c60600
19921 changed files with 2509159 additions and 45 deletions

View File

@@ -0,0 +1,13 @@
<?php
namespace Spatie\FlareClient\Truncation;
abstract class AbstractTruncationStrategy implements TruncationStrategy
{
protected ReportTrimmer $reportTrimmer;
public function __construct(ReportTrimmer $reportTrimmer)
{
$this->reportTrimmer = $reportTrimmer;
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace Spatie\FlareClient\Truncation;
class ReportTrimmer
{
protected static int $maxPayloadSize = 524288;
/** @var array<int, class-string<\Spatie\FlareClient\Truncation\TruncationStrategy>> */
protected array $strategies = [
TrimStringsStrategy::class,
TrimStackFrameArgumentsStrategy::class,
TrimContextItemsStrategy::class,
];
/**
* @param array<int|string, mixed> $payload
*
* @return array<int|string, mixed>
*/
public function trim(array $payload): array
{
foreach ($this->strategies as $strategy) {
if (! $this->needsToBeTrimmed($payload)) {
break;
}
$payload = (new $strategy($this))->execute($payload);
}
return $payload;
}
/**
* @param array<int|string, mixed> $payload
*
* @return bool
*/
public function needsToBeTrimmed(array $payload): bool
{
return strlen((string)json_encode($payload)) > self::getMaxPayloadSize();
}
public static function getMaxPayloadSize(): int
{
return self::$maxPayloadSize;
}
public static function setMaxPayloadSize(int $maxPayloadSize): void
{
self::$maxPayloadSize = $maxPayloadSize;
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace Spatie\FlareClient\Truncation;
class TrimContextItemsStrategy extends AbstractTruncationStrategy
{
/**
* @return array<int, int>
*/
public static function thresholds(): array
{
return [100, 50, 25, 10];
}
/**
* @param array<int|string, mixed> $payload
*
* @return array<int|string, mixed>
*/
public function execute(array $payload): array
{
foreach (static::thresholds() as $threshold) {
if (! $this->reportTrimmer->needsToBeTrimmed($payload)) {
break;
}
$payload['context'] = $this->iterateContextItems($payload['context'], $threshold);
}
return $payload;
}
/**
* @param array<int|string, mixed> $contextItems
* @param int $threshold
*
* @return array<int|string, mixed>
*/
protected function iterateContextItems(array $contextItems, int $threshold): array
{
array_walk($contextItems, [$this, 'trimContextItems'], $threshold);
return $contextItems;
}
protected function trimContextItems(mixed &$value, mixed $key, int $threshold): mixed
{
if (is_array($value)) {
if (count($value) > $threshold) {
$value = array_slice($value, $threshold * -1, $threshold);
}
array_walk($value, [$this, 'trimContextItems'], $threshold);
}
return $value;
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace Spatie\FlareClient\Truncation;
class TrimStackFrameArgumentsStrategy implements TruncationStrategy
{
public function execute(array $payload): array
{
for ($i = 0; $i < count($payload['stacktrace']); $i++) {
$payload['stacktrace'][$i]['arguments'] = null;
}
return $payload;
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace Spatie\FlareClient\Truncation;
class TrimStringsStrategy extends AbstractTruncationStrategy
{
/**
* @return array<int, int>
*/
public static function thresholds(): array
{
return [1024, 512, 256];
}
/**
* @param array<int|string, mixed> $payload
*
* @return array<int|string, mixed>
*/
public function execute(array $payload): array
{
foreach (static::thresholds() as $threshold) {
if (! $this->reportTrimmer->needsToBeTrimmed($payload)) {
break;
}
$payload = $this->trimPayloadString($payload, $threshold);
}
return $payload;
}
/**
* @param array<int|string, mixed> $payload
* @param int $threshold
*
* @return array<int|string, mixed>
*/
protected function trimPayloadString(array $payload, int $threshold): array
{
array_walk_recursive($payload, function (&$value) use ($threshold) {
if (is_string($value) && strlen($value) > $threshold) {
$value = substr($value, 0, $threshold);
}
});
return $payload;
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace Spatie\FlareClient\Truncation;
interface TruncationStrategy
{
/**
* @param array<int|string, mixed> $payload
*
* @return array<int|string, mixed>
*/
public function execute(array $payload): array;
}