Skip to content
PHP Ecosystem
Explore

MailCollector

API reference › Debug › collectors › MailCollector

classyii\debug\collectors\MailCollector
ExtendsCollector
ImplementsCollectorInterface
Sourcesrc/collectors/MailCollector.php

Captures every mail message dispatched during the request for the Mail panel.

PropertyTypeDescriptionDefined by
$mailPathstringFilesystem path (Yii alias) where every captured message is persisted as a .eml file. Default: '@runtime/debug/mail'.MailCollector
$moduleyii\debug\Module|nullDebug module supplying the log target and sibling collectors, assigned by the module on registration. Default: null.Collector
MethodDescriptionDefined by
capture() finalEncodes the typed snapshot built by the subclass into the payload persisted for the panel.Collector
getMessagesFileName()Returns the file names of the captured .eml files persisted under $mailPath.MailCollector
id()Returns the stable ID pairing this collector with the Mail panel.MailCollector
instrument()Installs low-level instrumentation as soon as the module registers the collector, before the panels are built.Collector
reconcileFiles()Retries cleanup of aged .eml files no longer referenced by a retained snapshot.MailCollector
removeFiles()Removes safe captured files associated with snapshots that were not committed or have been evicted.MailCollector
shutdown() finalDeactivates the collector once, releasing any subscription created by start().Collector
startup() finalActivates the collector once at the start of the request lifecycle.Collector
getLogMessages() protectedReturns the accumulated log messages, optionally filtered by level, category, and exclusion lists.Collector
getLogTarget() protectedReturns the initialized log target of the owning debug module.Collector
isStarted() protectedReturns whether the collector is active for the current request.Collector
snapshot() protectedSnapshots the captured messages, with their metadata (time, reply, bcc, cc, from, to, subject, headers, etc.).MailCollector
start() protectedRegisters the mailer listener that persists each dispatched message and records its metadata.MailCollector
stop() protectedDetaches the mailer listener and clears the captured messages, so a reused worker process starts clean.MailCollector
public function getMessagesFileName(): array<int, string>

Returns the file names of the captured .eml files persisted under $mailPath.

Returns

array<int, string>: File names in send order.

public function id(): string

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

Returns

string: Stable collector ID.

public function reconcileFiles(iterable<string> $referencedFiles): void

Retries cleanup of aged .eml files no longer referenced by a retained snapshot.

The grace period prevents a concurrent request’s new mail from being deleted before its snapshot commits.

Parameters

ParameterTypeDescription
$referencedFilesiterable<string>File names referenced by the current manifest.
public function removeFiles(iterable<string> $files): void

Removes safe captured files associated with snapshots that were not committed or have been evicted.

Parameters

ParameterTypeDescription
$filesiterable<string>Captured file names.
protected function snapshot(): PHPForge\Debug\Panel\Mail\MailSnapshot|null

Snapshots the captured messages, with their metadata (time, reply, bcc, cc, from, to, subject, headers, etc.).

Returns

PHPForge\Debug\Panel\Mail\MailSnapshot|null: Captured mail payload; null when the collector never started.

protected function start(): void

Registers the mailer listener that persists each dispatched message and records its metadata.

protected function stop(): void

Detaches the mailer listener and clears the captured messages, so a reused worker process starts clean.