An observer is any class wanting to receive updates whenever one of the Handler events are fired for a particular instance type. The interface only exposes one method serial.


For an observer class to receive events, it needs to implement one or more of the respective Handler interfaces. As some observers may only want to receive certain event types, the observer interface does not force you into implementing each event type.

For example, if you only want to be notified on destroy events, an observer class declaration may look like class OnBookDestroyObserver implements ObserverInterface, OnDestroyInterface {...}


Returns a unique snake_case string serial for this observer.

return 'on_book_destroy_observer';


The observatory is the orchestrator for one or many observers. When an event occurs, the observatory is notified which then dispatches the event and associated data to all its registered observers. This interface exposes the methods registerObserver, unregisterObserver, getObservers and a collection of event notifying methods following the signatures notifyOnXSucceeded and notifyOnXFailed where X is either Create, Update or Failed.


A concrete implementation comes supplied with Hive. Please see src/Concrete/Observers/Observatory


Registers the observer with the observatory.

$this->observers[$observer->serial()] = $observer;


Unregisters the observer from the observatory.

if (array_key_exists($observer->serial(), $this->observers)) {
    $this->observers = array_values($this->observers);


Returns an array/collection of registered observers.

return $this->observers;


Notify all registered observers that have implemented the OnXInterface that xSucceeded.

// In this example, we're using the notifyOnCreateSucceeded method.
foreach ($this->observers as $observer) {
    if ($observer instanceof OnCreateInterface) {


Notify all registered observers that have implemented the OnXInterface that xFailed.

// In this example, we're using the notifyOnDestroyFailed method.
foreach ($this->observers as $observer) {
    if ($observer instanceof OnDestroyInterface) {