azjezz/psl
PSL is a modern, well-typed standard library for PHP 8.4+, inspired by HHVM’s HSL. It offers safer, predictable APIs for async, collections, networking, I/O, crypto, terminal UI, and robust data validation—replacing brittle built-ins with consistent alternatives.
The Observer component provides two interfaces for the classic Observer design pattern. A subject maintains a list of observers and notifies them when something changes. PSL's interfaces are generic, so observers receive the concrete subject type rather than a vague base class.
SubjectInterface -- The object being watched. It can subscribe(), unsubscribe(), and notify() observers.ObserverInterface<T> -- The watcher. Its update() method receives the subject that triggered the notification, fully typed as T.The following example demonstrates a complete Subject/Observer implementation, including wiring them together:
@example('other/observer-pattern.php')
See src/Psl/Observer/ for the full API.
How can I help you explore Laravel packages today?