CapturePolicy
API reference › Debug Core › Capture › CapturePolicy
Applies the default redaction and size limits before debug data reaches persistent storage.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Creates a capture policy with redaction and size limits. | CapturePolicy |
isSensitiveKey() | Returns whether a key is denied by this policy. | CapturePolicy |
maxBodyBytes() | Returns the maximum number of body bytes that may reach persistent capture. | CapturePolicy |
redact() | Redacts sensitive keys throughout a bounded value tree. | CapturePolicy |
redactBody() | Redacts a decoded body, suppressing its raw representation whenever redaction was required and truncating it at the configured byte boundary otherwise. | CapturePolicy |
redactText() | Redacts common key=value and key: value secret fragments in diagnostic text. | CapturePolicy |
redactUrl() | Redacts sensitive values in a URL query string without changing the URL outside its query component. | CapturePolicy |
withAdditionalSensitiveKeys() | Returns a new instance whose exact-key list also covers the given keys. | CapturePolicy |
Constants
Section titled “Constants”| Constant | Value | Description | Defined by |
|---|---|---|---|
DEFAULT_MAX_BODY_BYTES | 65536 | Raw body bytes retained by persistent capture when no explicit limit is configured. | CapturePolicy |
Method details
Section titled “Method details”__construct()
Section titled “__construct() ”public function __construct(list<string> $sensitiveKeys = \PHPForge\Debug\Helper\SensitiveDataRedactor::DEFAULT_KEYS, int $maxBodyBytes = \self::DEFAULT_MAX_BODY_BYTES, list<string> $sensitiveKeyPrefixes = [], list<string>|null $sensitiveKeyPatterns = null)Creates a capture policy with redaction and size limits.
Parameters
| Parameter | Type | Description |
|---|---|---|
$sensitiveKeys | list<string> | Exact, case-insensitive keys to redact recursively. |
$maxBodyBytes | int | Maximum raw request or response body bytes to retain; must be positive. |
$sensitiveKeyPrefixes | list<string> | Literal, case-insensitive key prefixes to redact recursively. |
$sensitiveKeyPatterns | list<string>| | PCRE patterns applied to complete original keys. null uses segment-aware defaults only with the default exact-key list; [] explicitly disables pattern matching. |
isSensitiveKey()
Section titled “isSensitiveKey() ”public function isSensitiveKey(string $key): boolReturns whether a key is denied by this policy.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | Original key to check case-insensitively. |
Returns
bool: true when the key matches an exact name, a prefix, or a pattern rule; false otherwise.
maxBodyBytes()
Section titled “maxBodyBytes() ”public function maxBodyBytes(): intReturns the maximum number of body bytes that may reach persistent capture.
Returns
int: Configured body byte limit.
redact()
Section titled “redact() ”public function redact(array<PHPForge\Debug\Capture\TKey, mixed> $value): array<PHPForge\Debug\Capture\TKey, mixed>Redacts sensitive keys throughout a bounded value tree.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | array<PHPForge\ | Value tree to sanitize. |
Returns
array<PHPForge\Debug\Capture\TKey, mixed>: Sanitized value tree.
redactBody()
Section titled “redactBody() ”public function redactBody(string $raw, mixed $decoded): array{decoded: mixed, raw: string}Redacts a decoded body, suppressing its raw representation whenever redaction was required and truncating it at the configured byte boundary otherwise.
Parameters
| Parameter | Type | Description |
|---|---|---|
$raw | string | Raw body exactly as received. |
$decoded | mixed | Decoded body, or null when the body could not be decoded. |
Returns
array{decoded: mixed, raw: string}: Sanitized decoded body and its bounded raw representation.
redactText()
Section titled “redactText() ”public function redactText(string $text): stringRedacts common key=value and key: value secret fragments in diagnostic text.
Parameters
| Parameter | Type | Description |
|---|---|---|
$text | string | Diagnostic text to sanitize. |
Returns
string: Text with every sensitive assignment value replaced.
redactUrl()
Section titled “redactUrl() ”public function redactUrl(string $url): stringRedacts sensitive values in a URL query string without changing the URL outside its query component.
Parameters
| Parameter | Type | Description |
|---|---|---|
$url | string | URL to sanitize. |
Returns
string: URL with every sensitive query value replaced.
withAdditionalSensitiveKeys()
Section titled “withAdditionalSensitiveKeys() ”public function withAdditionalSensitiveKeys(list<string> $sensitiveKeys): selfReturns a new instance whose exact-key list also covers the given keys.
The already resolved pattern rules are carried over, so extending the default key list keeps the segment-aware defaults active instead of silently dropping them.
Parameters
| Parameter | Type | Description |
|---|---|---|
$sensitiveKeys | list<string> | Extra exact, case-insensitive keys to redact recursively. |
Returns
self: New instance denying both the configured and the additional keys.