Subiendo proyecto completo sin restricciones de git ignore
This commit is contained in:
13
vendor/spatie/flare-client-php/src/Truncation/AbstractTruncationStrategy.php
vendored
Normal file
13
vendor/spatie/flare-client-php/src/Truncation/AbstractTruncationStrategy.php
vendored
Normal 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;
|
||||
}
|
||||
}
|
||||
53
vendor/spatie/flare-client-php/src/Truncation/ReportTrimmer.php
vendored
Normal file
53
vendor/spatie/flare-client-php/src/Truncation/ReportTrimmer.php
vendored
Normal 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;
|
||||
}
|
||||
}
|
||||
58
vendor/spatie/flare-client-php/src/Truncation/TrimContextItemsStrategy.php
vendored
Normal file
58
vendor/spatie/flare-client-php/src/Truncation/TrimContextItemsStrategy.php
vendored
Normal 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;
|
||||
}
|
||||
}
|
||||
15
vendor/spatie/flare-client-php/src/Truncation/TrimStackFrameArgumentsStrategy.php
vendored
Normal file
15
vendor/spatie/flare-client-php/src/Truncation/TrimStackFrameArgumentsStrategy.php
vendored
Normal 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;
|
||||
}
|
||||
}
|
||||
49
vendor/spatie/flare-client-php/src/Truncation/TrimStringsStrategy.php
vendored
Normal file
49
vendor/spatie/flare-client-php/src/Truncation/TrimStringsStrategy.php
vendored
Normal 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;
|
||||
}
|
||||
}
|
||||
13
vendor/spatie/flare-client-php/src/Truncation/TruncationStrategy.php
vendored
Normal file
13
vendor/spatie/flare-client-php/src/Truncation/TruncationStrategy.php
vendored
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user