CompositeErrorReporter
in package
implements
ErrorReporterInterface, Countable
Aggregates multiple error reporters and delegates error reporting to all of them.
This class MUST be used when you want to ensure that all registered reporters are notified of an error. If any reporter throws an exception, this class SHALL log the failure using error_log and MUST continue reporting to the remaining reporters.
Table of Contents
Interfaces
- ErrorReporterInterface
- This interface MUST be implemented by any class that reports exceptions from deferred callbacks.
- Countable
Properties
- $reporters : array<string|int, ErrorReporterInterface>
- List of error reporters. This property MUST contain only valid ErrorReporterInterface implementations.
Methods
- __construct() : mixed
- Constructs a new CompositeErrorReporter instance.
- add() : self
- Adds a new reporter to the composite.
- count() : int
- Returns the number of registered reporters.
- isEmpty() : bool
- Determines if the composite contains no reporters.
- report() : void
- Reports a throwable to all registered reporters.
Properties
$reporters
List of error reporters. This property MUST contain only valid ErrorReporterInterface implementations.
private
array<string|int, ErrorReporterInterface>
$reporters
Methods
__construct()
Constructs a new CompositeErrorReporter instance.
public
__construct(ErrorReporterInterface ...$reporters) : mixed
This constructor SHALL accept any number of ErrorReporterInterface implementations. The reporters MUST be stored in the order provided.
Parameters
- $reporters : ErrorReporterInterface
-
One or more error reporters to aggregate.
add()
Adds a new reporter to the composite.
public
add(ErrorReporterInterface $reporter) : self
This method MUST append the reporter to the internal list. The reporter MUST implement ErrorReporterInterface.
Parameters
- $reporter : ErrorReporterInterface
-
the reporter to add
Return values
self —returns the current instance for chaining
count()
Returns the number of registered reporters.
public
count() : int
This method MUST return the count of reporters currently registered in the composite.
Return values
int —the number of reporters
isEmpty()
Determines if the composite contains no reporters.
public
isEmpty() : bool
This method MUST return true if no reporters are registered, and false otherwise.
Return values
bool —true if no reporters are registered; otherwise, false
report()
Reports a throwable to all registered reporters.
public
report(Throwable $throwable[, callable|null $callback = null ][, array<string|int, mixed> $args = [] ]) : void
This method MUST attempt to report the throwable to each reporter in sequence. If a reporter throws an exception, the failure MUST be logged using error_log, and reporting SHALL continue for the remaining reporters.
Parameters
- $throwable : Throwable
-
the exception or error to report
- $callback : callable|null = null
-
the related callback, if available
- $args : array<string|int, mixed> = []
-
arguments passed to the callback, if any