# CapturePolicyFactory

> Builds the policy that redacts sensitive values and caps request bodies before the debugger persists a capture.

[API reference](/docs/api/index.md) › [Debug](/docs/extensions/debug/reference/index.md) › [service](/docs/extensions/debug/reference/service/index.md) › CapturePolicyFactory

| class | `yii\debug\service\CapturePolicyFactory` |
| --- | --- |
| Source | [`src/service/CapturePolicyFactory.php`](https://github.com/yii2-extensions/debug/blob/main/src/service/CapturePolicyFactory.php#L17) |

Builds the policy that redacts sensitive values and caps request bodies before the debugger persists a capture.

The global rules come from the module configuration; a collector adds its own exact keys on top of them without
weakening the shared rules.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-module"></span>`$module` protected readonly constructor | [`yii\debug\Module`](/docs/extensions/debug/reference/module/index.md) | Debug module read for the redaction configuration at call time. | `CapturePolicyFactory` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Binds capture-policy creation to the debug module. | `CapturePolicyFactory` |
| [`create()`](#method-create) | Creates the shared persistent-data policy, optionally extending its exact-key list for one collector. | `CapturePolicyFactory` |

## Method details

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

```php
public function __construct(yii\debug\Module $module)
```

Binds capture-policy creation to the debug module.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$module` | [`yii\debug\Module`](/docs/extensions/debug/reference/module/index.md) | Debug module read for the redaction configuration at call time. |

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

```php
public function create(list<string> $additionalSensitiveKeys = []): PHPForge\Debug\Capture\CapturePolicy
```

Creates the shared persistent-data policy, optionally extending its exact-key list for one collector.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$additionalSensitiveKeys` | `list<string>` | Collector-specific exact keys added without weakening global rules. |

**Returns**

[`CapturePolicy`](https://github.com/php-forge/debug-core/blob/b70459f033a1d7a1c5edf7951029aad2061986dd/src/Capture/CapturePolicy.php): Shared policy covering the global rules and the collector-specific keys.

**Throws**

- [`InvalidArgumentException`](https://www.php.net/manual/en/class.invalidargumentexception.php): when the configured keys, prefixes, patterns, or body limit are rejected.