UserCollector
API reference › Yii3 Debug › Collector › UserCollector
Captures the current yiisoft/user identity and its yiisoft/rbac roles and permissions for the User panel.
The payload has the shape the Yii2 collector produces, so a capture written by either host renders through the same
UserPanel. The identity is read when the response leaves the application, while
the session that restores it is still readable; the capture itself runs after the response was sent.
Both packages stay optional: CurrentUser and ManagerInterface are resolved from the container only when
it defines them, so an application without RBAC still captures the identity, and one without yiisoft/user
captures nothing.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Creates a user collector that resolves identity and RBAC data through the container. | UserCollector |
capture() | Encodes the identity into the User panel payload. | UserCollector |
collectRequest() | Ignores the incoming request, since the identity is only final once the application handled it. | UserCollector |
collectResponse() | Reads the identity before the response is sent and the session is closed. | UserCollector |
id() | Returns the stable identifier of this collector. | UserCollector |
shutdown() | Stops capturing and discards the identity, or the failure, read for the request. | UserCollector |
startup() | Starts capturing, discarding anything left from a previous request. | UserCollector |
Method details
Section titled “Method details”__construct()
Section titled “__construct() ”public function __construct(Psr\Container\ContainerInterface $container, PHPForge\Debug\Capture\CapturePolicy $capturePolicy = new \PHPForge\Debug\Capture\CapturePolicy(), Closure(Yiisoft\Auth\IdentityInterface): array<array-key, mixed>|null $identityData = null)Creates a user collector that resolves identity and RBAC data through the container.
Parameters
| Parameter | Type | Description |
|---|---|---|
$container | Psr\ | Container resolving the current user and the optional RBAC manager. |
$capturePolicy | CapturePolicy | Policy naming the identity attributes, at any depth, stored as the redaction placeholder. |
$identityData | Closure(Yiisoft\ | Reader returning the attributes of an identity the default rule cannot see, such as one wrapping an entity; null reads toArray(), then jsonSerialize(), then the public properties. |
capture()
Section titled “capture() ”public function capture(): array<string, mixed>|nullEncodes the identity into the User panel payload.
A capture finalized without a response, such as one written when the application exits early, reads the identity now. A failure kept from the response is thrown here, so the capture records it as a panel failure.
Returns
array<string, mixed>|null: Encoded User panel payload; null when the collector never started or the container defines no current user.
Throws
Throwable: when the current user cannot be resolved, or its identity cannot be restored or read.
collectRequest()
Section titled “collectRequest() ”public function collectRequest(Psr\Http\Message\ServerRequestInterface $request): voidIgnores the incoming request, since the identity is only final once the application handled it.
Parameters
| Parameter | Type | Description |
|---|---|---|
$request | Psr\ | Request reaching the debugger middleware. |
collectResponse()
Section titled “collectResponse() ”public function collectResponse(Psr\Http\Message\ResponseInterface $response): voidReads the identity before the response is sent and the session is closed.
A failure never reaches the application, which already produced its response; it is kept for capture().
Parameters
| Parameter | Type | Description |
|---|---|---|
$response | Psr\ | Response produced for the captured request. |
public function id(): stringReturns the stable identifier of this collector.
Returns
string: Stable ID pairing this collector with its panel.
shutdown()
Section titled “shutdown() ”public function shutdown(): voidStops capturing and discards the identity, or the failure, read for the request.
startup()
Section titled “startup() ”public function startup(): voidStarts capturing, discarding anything left from a previous request.