Receiver
Contract for objects that receive and handle signal emissions.
This interface defines the standard method signature for objects that act as signal receivers (observers/listeners) in an event-driven system. Any class implementing this interface can be connected to a Signaler object and will automatically receive notifications when signals are emitted.
The Receiver pattern provides several advantages over raw callables:
- Type-safe receiver registration (enforced by type hints)
- Object-oriented encapsulation of handler logic
- Easier testing and mocking of event handlers
- Clear separation of concerns in complex event systems
- Self-documenting code (receiver intent is explicit)
Design patterns supported:
- Observer pattern: Receivers as observers of signal subjects
- Command pattern: Receivers as command executors
- Strategy pattern: Different receivers as interchangeable strategies
- Chain of Responsibility: Multiple receivers processing the same event
Tags
Table of Contents
Methods
- receive() : void
- Handles signal emissions by processing the provided values.
Methods
receive()
Handles signal emissions by processing the provided values.
public
receive(mixed ...$values) : void
This method is automatically invoked by the Signal system when a connected signal is emitted. Implementations should process the provided values according to their specific logic (logging, notifications, data processing, etc.).
Method characteristics:
- Called automatically when signal emits (no manual invocation)
- Receives all values passed to the signal's emit() method
- Values arrive in the same order they were emitted
- No return value expected (fire-and-forget pattern)
- Should handle missing or unexpected values gracefully
- Exceptions should be caught internally or allowed to propagate
Implementation guidelines:
- Keep processing fast to avoid blocking other receivers
- Validate input values before using them
- Handle edge cases (empty values, wrong types)
- Consider using variadic parameters destructuring for clarity
- Document expected value format in implementation
Parameters
- $values : mixed
-
Zero or more values emitted by the signal. The number and types of values depend on the signal source.
- Empty for signals that emit no data
- Single value for simple notifications
- Multiple values for complex events
Tags
Return values
void —No return value. Receivers perform side effects only.