# Payload

> Provides strict reads for DTO factories at the decoded-JSON boundary.

[API reference](/docs/api/index.md) › [Debug Core](/docs/extensions/debug-core/reference/index.md) › [Storage](/docs/extensions/debug-core/reference/storage/index.md) › Payload

| final readonly class | `PHPForge\Debug\Storage\Payload` |
| --- | --- |
| Source | [`src/Storage/Payload.php`](https://github.com/php-forge/debug-core/blob/main/src/Storage/Payload.php#L24) |

Provides strict reads for DTO factories at the decoded-JSON boundary.

It validates types and shapes without accepting numeric strings, casting values, or supplying implicit defaults.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`all()`](#method-all) | Returns every decoded field without conversion. | `Payload` |
| [`bool()`](#method-bool) | Returns a required boolean field. | `Payload` |
| [`debugArray()`](#method-debugArray) | Reads a tagged array value, keeping the path of the enclosing payload for error reporting. | `Payload` |
| [`int()`](#method-int) | Returns a required integer field. | `Payload` |
| [`list()`](#method-list) | Returns a required list field. | `Payload` |
| [`map()`](#method-map) | Returns a required JSON object as a `string`-keyed array. | `Payload` |
| [`mapList()`](#method-mapList) | Reads a list field and maps every element through a factory, passing the indexed element path for error reporting. | `Payload` |
| [`nullableBool()`](#method-nullableBool) | Returns a boolean field or `null`. | `Payload` |
| [`nullableInt()`](#method-nullableInt) | Returns an integer field or `null`. | `Payload` |
| [`nullableNumber()`](#method-nullableNumber) | Returns a numeric field as a float or `null`. | `Payload` |
| [`nullableString()`](#method-nullableString) | Returns a string field or `null`. | `Payload` |
| [`number()`](#method-number) | Returns a required numeric field as a float. | `Payload` |
| [`object()`](#method-object) static | Creates a strict reader for a decoded JSON object. | `Payload` |
| [`raw()`](#method-raw) | Returns a required field without conversion. | `Payload` |
| [`rows()`](#method-rows) | Reads a list of JSON objects, validating each element's shape but leaving its values untouched. | `Payload` |
| [`shape()`](#method-shape) | Validates required, optional, and undeclared fields. | `Payload` |
| [`string()`](#method-string) | Returns a required `string` field. | `Payload` |

## Method details

### all() <span id="method-all"></span>

```php
public function all(): array<string, mixed>
```

Returns every decoded field without conversion.

**Returns**

`array<string, mixed>`: Decoded object fields.

### bool() <span id="method-bool"></span>

```php
public function bool(string $key): bool
```

Returns a required boolean field.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `string` | Required field name. |

**Returns**

`bool`: Boolean field value.

### debugArray() <span id="method-debugArray"></span>

```php
public function debugArray(string $key): PHPForge\Debug\Storage\DebugArray
```

Reads a tagged array value, keeping the path of the enclosing payload for error reporting.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `string` | Required field name. |

**Returns**

[`DebugArray`](/docs/extensions/debug-core/reference/storage/debugarray/index.md): Hydrated tagged array.

### int() <span id="method-int"></span>

```php
public function int(string $key): int
```

Returns a required integer field.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `string` | Required field name. |

**Returns**

`int`: Integer field value.

### list() <span id="method-list"></span>

```php
public function list(string $key): list<mixed>
```

Returns a required list field.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `string` | Required field name. |

**Returns**

`list<mixed>`: List field value.

### map() <span id="method-map"></span>

```php
public function map(string $key): array<string, mixed>
```

Returns a required JSON object as a `string`-keyed array.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `string` | Required field name. |

**Returns**

`array<string, mixed>`: Object field value.

### mapList() <span id="method-mapList"></span>

```php
public function mapList(string $key, callable(mixed, string): PHPForge\Debug\Storage\T $factory): list<PHPForge\Debug\Storage\T>
```

Reads a list field and maps every element through a factory, passing the indexed element path for error
reporting.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `string` | Required field name. |
| `$factory` | `callable(mixed, string): PHPForge\Debug\Storage\T` | Element factory receiving the raw element and its indexed path. |

**Returns**

`list<PHPForge\Debug\Storage\T>`: Mapped elements in payload order.

### nullableBool() <span id="method-nullableBool"></span>

```php
public function nullableBool(string $key): bool|null
```

Returns a boolean field or `null`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `string` | Required field name. |

**Returns**

`bool|null`: Boolean field value or `null`.

### nullableInt() <span id="method-nullableInt"></span>

```php
public function nullableInt(string $key): int|null
```

Returns an integer field or `null`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `string` | Required field name. |

**Returns**

`int|null`: Integer field value or `null`.

### nullableNumber() <span id="method-nullableNumber"></span>

```php
public function nullableNumber(string $key): float|null
```

Returns a numeric field as a float or `null`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `string` | Required field name. |

**Returns**

`float|null`: Numeric field value or `null`.

### nullableString() <span id="method-nullableString"></span>

```php
public function nullableString(string $key): string|null
```

Returns a string field or `null`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `string` | Required field name. |

**Returns**

`string|null`: String field value or `null`.

### number() <span id="method-number"></span>

```php
public function number(string $key): float
```

Returns a required numeric field as a float.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `string` | Required field name. |

**Returns**

`float`: Numeric field value.

### object() <span id="method-object"></span>

```php
public static function object(mixed $value, string $path = '$'): self
```

Creates a strict reader for a decoded JSON object.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `mixed` | Decoded JSON value. |
| `$path` | `string` | Object path used in hydration errors. |

**Returns**

`self`: Strict object reader.

### raw() <span id="method-raw"></span>

```php
public function raw(string $key): mixed
```

Returns a required field without conversion.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `string` | Required field name. |

**Returns**

`mixed`: Unconverted field value.

### rows() <span id="method-rows"></span>

```php
public function rows(string $key): list<array<string, mixed>>
```

Reads a list of JSON objects, validating each element's shape but leaving its values untouched.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `string` | Required field name. |

**Returns**

`list<array<string, mixed>>`: Validated object rows.

### shape() <span id="method-shape"></span>

```php
public function shape(list<string> $required, list<string> $optional = []): self
```

Validates required, optional, and undeclared fields.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$required` | `list<string>` | Required field names. |
| `$optional` | `list<string>` | Optional field names. |

**Returns**

`self`: Validated object reader.

### string() <span id="method-string"></span>

```php
public function string(string $key): string
```

Returns a required `string` field.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$key` | `string` | Required field name. |

**Returns**

`string`: String field value.