Skip to content
PHP Ecosystem
Explore

UserCollector

API reference › Yii3 Debug › Collector › UserCollector

final classYii3\Debug\Collector\UserCollector
ImplementsCollectorInterface, RequestObserverInterface
Sourcesrc/Collector/UserCollector.php

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.

MethodDescriptionDefined 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
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

ParameterTypeDescription
$containerPsr\Container\ContainerInterfaceContainer resolving the current user and the optional RBAC manager.
$capturePolicyCapturePolicyPolicy naming the identity attributes, at any depth, stored as the redaction placeholder.
$identityDataClosure(Yiisoft\Auth\IdentityInterface): array<array-key, mixed>|nullReader 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.
public function capture(): array<string, mixed>|null

Encodes 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.
public function collectRequest(Psr\Http\Message\ServerRequestInterface $request): void

Ignores the incoming request, since the identity is only final once the application handled it.

Parameters

ParameterTypeDescription
$requestPsr\Http\Message\ServerRequestInterfaceRequest reaching the debugger middleware.
public function collectResponse(Psr\Http\Message\ResponseInterface $response): void

Reads 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

ParameterTypeDescription
$responsePsr\Http\Message\ResponseInterfaceResponse produced for the captured request.
public function id(): string

Returns the stable identifier of this collector.

Returns

string: Stable ID pairing this collector with its panel.

public function shutdown(): void

Stops capturing and discards the identity, or the failure, read for the request.

public function startup(): void

Starts capturing, discarding anything left from a previous request.