Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Spatie\FlareClient\Truncation;
4
 
5
class TrimStringsStrategy extends AbstractTruncationStrategy
6
{
7
    /**
8
     * @return array<int, int>
9
     */
10
    public static function thresholds(): array
11
    {
12
        return [1024, 512, 256];
13
    }
14
 
15
    /**
16
     * @param array<int|string, mixed> $payload
17
     *
18
     * @return array<int|string, mixed>
19
     */
20
    public function execute(array $payload): array
21
    {
22
        foreach (static::thresholds() as $threshold) {
23
            if (! $this->reportTrimmer->needsToBeTrimmed($payload)) {
24
                break;
25
            }
26
 
27
            $payload = $this->trimPayloadString($payload, $threshold);
28
        }
29
 
30
        return $payload;
31
    }
32
 
33
    /**
34
     * @param array<int|string, mixed> $payload
35
     * @param int $threshold
36
     *
37
     * @return array<int|string, mixed>
38
     */
39
    protected function trimPayloadString(array $payload, int $threshold): array
40
    {
41
        array_walk_recursive($payload, function (&$value) use ($threshold) {
42
            if (is_string($value) && strlen($value) > $threshold) {
43
                $value = substr($value, 0, $threshold);
44
            }
45
        });
46
 
47
        return $payload;
48
    }
49
}