Repository navigation
Expand file tree
/
Copy pathDebugArray.php
More file actions
75 lines (65 loc) · 1.83 KB
/
Copy pathDebugArray.php
File metadata and controls
75 lines (65 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
declare(strict_types=1);
namespace PHPForge\Debug\Storage;
use JsonSerializable;
use SensitiveParameter;
/**
* Represents a PHP array with arbitrary nested values as JSON-safe debug data.
*/
final readonly class DebugArray implements JsonSerializable
{
/**
* Creates an array facade over a tagged debug value.
*
* @param DebugValue $value Tagged array value.
*/
private function __construct(private DebugValue $value) {}
/**
* Captures an array as tagged debug data.
*
* @param array<array-key, mixed> $value PHP values to capture.
*
* @return self Tagged array facade.
*/
public static function capture(#[SensitiveParameter] array $value): self
{
return new self(DebugValue::capture($value));
}
/**
* Hydrates a tagged debug array from decoded JSON data.
*
* @param mixed $value Decoded tagged value.
* @param string $path Payload path used in hydration errors.
*
* @return self Hydrated array facade.
*/
public static function fromArray(mixed $value, string $path): self
{
$debugValue = DebugValue::fromArray($value, $path);
if ($debugValue->type !== 'array') {
throw HydrationException::at(
$path,
'a tagged array',
);
}
return new self($debugValue);
}
/**
* Returns the tagged array for JSON serialization.
*
* @return array<string, mixed> Tagged array payload.
*/
public function jsonSerialize(): array
{
return $this->value->jsonSerialize();
}
/**
* Returns captured entries as display-safe PHP values.
*
* @return array<array-key, mixed> Display-safe PHP values.
*/
public function values(): array
{
return $this->value->toDisplayEntries();
}
}