Skip to content
PHP Ecosystem
Explore

CapturePolicy

API reference › Debug Core › Capture › CapturePolicy

final readonly classPHPForge\Debug\Capture\CapturePolicy
Sourcesrc/Capture/CapturePolicy.php

Applies the default redaction and size limits before debug data reaches persistent storage.

MethodDescriptionDefined 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
ConstantValueDescriptionDefined by
DEFAULT_MAX_BODY_BYTES65536Raw body bytes retained by persistent capture when no explicit limit is configured.CapturePolicy
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

ParameterTypeDescription
$sensitiveKeyslist<string>Exact, case-insensitive keys to redact recursively.
$maxBodyBytesintMaximum raw request or response body bytes to retain; must be positive.
$sensitiveKeyPrefixeslist<string>Literal, case-insensitive key prefixes to redact recursively.
$sensitiveKeyPatternslist<string>|nullPCRE patterns applied to complete original keys. null uses segment-aware defaults only with the default exact-key list; [] explicitly disables pattern matching.
public function isSensitiveKey(string $key): bool

Returns whether a key is denied by this policy.

Parameters

ParameterTypeDescription
$keystringOriginal key to check case-insensitively.

Returns

bool: true when the key matches an exact name, a prefix, or a pattern rule; false otherwise.

public function maxBodyBytes(): int

Returns the maximum number of body bytes that may reach persistent capture.

Returns

int: Configured body byte limit.

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

ParameterTypeDescription
$valuearray<PHPForge\Debug\Capture\TKey, mixed>Value tree to sanitize.

Returns

array<PHPForge\Debug\Capture\TKey, mixed>: Sanitized value tree.

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

ParameterTypeDescription
$rawstringRaw body exactly as received.
$decodedmixedDecoded body, or null when the body could not be decoded.

Returns

array{decoded: mixed, raw: string}: Sanitized decoded body and its bounded raw representation.

public function redactText(string $text): string

Redacts common key=value and key: value secret fragments in diagnostic text.

Parameters

ParameterTypeDescription
$textstringDiagnostic text to sanitize.

Returns

string: Text with every sensitive assignment value replaced.

public function redactUrl(string $url): string

Redacts sensitive values in a URL query string without changing the URL outside its query component.

Parameters

ParameterTypeDescription
$urlstringURL to sanitize.

Returns

string: URL with every sensitive query value replaced.

public function withAdditionalSensitiveKeys(list<string> $sensitiveKeys): self

Returns 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

ParameterTypeDescription
$sensitiveKeyslist<string>Extra exact, case-insensitive keys to redact recursively.

Returns

self: New instance denying both the configured and the additional keys.