CompositeErrorReporter

Class
implements ErrorReporterInterface Countable
Final: Yes

Aggregates multiple error reporters and delegates error reporting to all of them.

Description

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.

Properties

$reporters

List of error reporters. This property MUST contain only valid ErrorReporterInterface implementations.

 : array<string|int, ErrorReporterInterface>

Methods

__construct()

Constructs a new CompositeErrorReporter instance.

 : mixed
add()

Adds a new reporter to the composite.

 : self
count()

Returns the number of registered reporters.

 : int
isEmpty()

Determines if the composite contains no reporters.

 : bool
report()

Reports a throwable to all registered reporters.

 : void
Properties
Methods

__construct()

Public

Constructs a new CompositeErrorReporter instance.

public __construct(ErrorReporterInterface  ...$reporters) : mixed

Description

This constructor SHALL accept any number of ErrorReporterInterface implementations. The reporters MUST be stored in the order provided.

Parameters
$reporters : ErrorReporterInterface

Description

One or more error reporters to aggregate.

add()

Public

Adds a new reporter to the composite.

public add(ErrorReporterInterface  $reporter) : self

Description

This method MUST append the reporter to the internal list. The reporter MUST implement ErrorReporterInterface.

Parameters

Description

the reporter to add

Return values
self

Description

returns the current instance for chaining

count()

Public

Returns the number of registered reporters.

public count() : int

Description

This method MUST return the count of reporters currently registered in the composite.

Return values
int

Description

the number of reporters

isEmpty()

Public

Determines if the composite contains no reporters.

public isEmpty() : bool

Description

This method MUST return true if no reporters are registered, and false otherwise.

Return values
bool

Description

true if no reporters are registered; otherwise, false

report()

Public

Reports a throwable to all registered reporters.

public report(Throwable  $throwable[, callable|null  $callback = null][, array<string|int, mixed>  $args = []]) : void

Description

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

Description

the exception or error to report

$callback : callable|null = null

Description

the related callback, if available

$args : array<string|int, mixed> = []

Description

arguments passed to the callback, if any