# UserCollector

> Captures the authenticated identity for the User panel.

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

| class | `yii\debug\collectors\UserCollector` |
| --- | --- |
| Extends | [`Collector`](/docs/extensions/debug/reference/collectors/collector/index.md) |
| Implements | [`CollectorInterface`](https://github.com/php-forge/debug/blob/e4fbb8c3238a4d011ceef5e0094344abd50deaf4/src/CollectorInterface.php) |
| Source | [`src/collectors/UserCollector.php`](https://github.com/yii2-extensions/debug/blob/main/src/collectors/UserCollector.php#L31) |

Captures the authenticated identity for the User panel.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-module"></span>[`$module`](/docs/extensions/debug/reference/collectors/collector/index.md#property-module) | [`yii\debug\Module`](/docs/extensions/debug/reference/module/index.md)`\|null` | Debug module supplying the log target and sibling collectors, assigned by the module on registration. Default: `null`. | [`Collector`](/docs/extensions/debug/reference/collectors/collector/index.md) |
| <span id="property-userComponent"></span>`$userComponent` | `string\|`[`yii\web\User`](/docs/api/yii/web/user/index.md) | Component id of the user component, or a [`User`](/docs/api/yii/web/user/index.md) instance to operate on directly. Default: `'user'`. | `UserCollector` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-capture"></span>[`capture()`](/docs/extensions/debug/reference/collectors/collector/index.md#method-capture) final | Encodes the typed snapshot built by the subclass into the payload persisted for the panel. | [`Collector`](/docs/extensions/debug/reference/collectors/collector/index.md) |
| [`id()`](#method-id) | Returns the stable ID pairing this collector with the User panel. | `UserCollector` |
| <span id="method-instrument"></span>[`instrument()`](/docs/extensions/debug/reference/collectors/collector/index.md#method-instrument) | Installs low-level instrumentation as soon as the module registers the collector, before the panels are built. | [`Collector`](/docs/extensions/debug/reference/collectors/collector/index.md) |
| <span id="method-shutdown"></span>[`shutdown()`](/docs/extensions/debug/reference/collectors/collector/index.md#method-shutdown) final | Deactivates the collector once, releasing any subscription created by [`start()`](/docs/extensions/debug/reference/collectors/collector/index.md#method-start). | [`Collector`](/docs/extensions/debug/reference/collectors/collector/index.md) |
| <span id="method-startup"></span>[`startup()`](/docs/extensions/debug/reference/collectors/collector/index.md#method-startup) final | Activates the collector once at the start of the request lifecycle. | [`Collector`](/docs/extensions/debug/reference/collectors/collector/index.md) |
| [`dataToString()`](#method-dataToString) protected | Returns the value when it is already a string, otherwise renders it with [`VarDumper::export()`](/docs/api/yii/helpers/basevardumper/index.md#method-export). | `UserCollector` |
| <span id="method-getLogMessages"></span>[`getLogMessages()`](/docs/extensions/debug/reference/collectors/collector/index.md#method-getLogMessages) protected | Returns the accumulated log messages, optionally filtered by level, category, and exclusion lists. | [`Collector`](/docs/extensions/debug/reference/collectors/collector/index.md) |
| <span id="method-getLogTarget"></span>[`getLogTarget()`](/docs/extensions/debug/reference/collectors/collector/index.md#method-getLogTarget) protected | Returns the initialized log target of the owning debug module. | [`Collector`](/docs/extensions/debug/reference/collectors/collector/index.md) |
| [`getUser()`](#method-getUser) protected | Returns the user component bound to this collector, or `null` when the configured component id does not resolve to a [`User`](/docs/api/yii/web/user/index.md) instance. | `UserCollector` |
| [`identityData()`](#method-identityData) protected | Returns the identity attributes as a string-keyed map suitable for [`DetailView::$model`](/docs/api/yii/widgets/detailview/index.md#property-model). | `UserCollector` |
| <span id="method-isStarted"></span>[`isStarted()`](/docs/extensions/debug/reference/collectors/collector/index.md#method-isStarted) protected | Returns whether the collector is active for the current request. | [`Collector`](/docs/extensions/debug/reference/collectors/collector/index.md) |
| [`snapshot()`](#method-snapshot) protected | Snapshots the identity attributes, the RBAC roles, and the permissions for the active user. | `UserCollector` |
| <span id="method-start"></span>[`start()`](/docs/extensions/debug/reference/collectors/collector/index.md#method-start) protected | Hook invoked once when the collector activates; subclasses subscribe to framework events here. | [`Collector`](/docs/extensions/debug/reference/collectors/collector/index.md) |
| <span id="method-stop"></span>[`stop()`](/docs/extensions/debug/reference/collectors/collector/index.md#method-stop) protected | Hook invoked once when the collector deactivates; subclasses detach subscriptions and clear state here. | [`Collector`](/docs/extensions/debug/reference/collectors/collector/index.md) |

## Method details

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

```php
public function id(): string
```

Returns the stable ID pairing this collector with the User panel.

**Returns**

`string`: Stable collector ID.

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

```php
protected function dataToString(mixed $data): string
```

Returns the value when it is already a string, otherwise renders it with [`VarDumper::export()`](/docs/api/yii/helpers/basevardumper/index.md#method-export).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$data` | `mixed` | Captured identity value. |

**Returns**

`string`: Display string for the User panel.

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

```php
protected function getUser(): yii\web\User|null
```

Returns the user component bound to this collector, or `null` when the configured component id does not resolve
to a [`User`](/docs/api/yii/web/user/index.md) instance.

**Returns**

[`yii\web\User`](/docs/api/yii/web/user/index.md)`|null`: Bound user component, or `null` when the configured id does not resolve to one.

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

```php
protected function identityData(yii\web\IdentityInterface $identity): array<string, mixed>
```

Returns the identity attributes as a string-keyed map suitable for [`DetailView::$model`](/docs/api/yii/widgets/detailview/index.md#property-model).

Reads [`Model::getAttributes()`](/docs/api/yii/base/model/index.md#method-getAttributes) when the identity is a [`Model`](/docs/api/yii/base/model/index.md); otherwise keeps only
public object properties.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$identity` | [`yii\web\IdentityInterface`](/docs/api/yii/web/identityinterface/index.md) | Active identity object. |

**Returns**

`array<string, mixed>`: Attribute map ready to feed the detail view.

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

```php
protected function snapshot(): PHPForge\Debug\Panel\User\UserSnapshot|null
```

Snapshots the identity attributes, the RBAC roles, and the permissions for the active user.

**Returns**

`PHPForge\Debug\Panel\User\UserSnapshot|null`: Captured identity or Guest payload; `null` when the collector never started or the user component cannot be resolved.