Events and observers
Magento
implements the observer pattern through \Magento\Framework\Event\ManagerInterface
. In app/etc/di.xml
, there is a preference for ManagerInterface
that points to the Magento\Framework\Event\Manager\Proxy
class type. The Proxy
class further extends the \Magento\Framework\Event\Manager
class that implements the actual event dispatch method.
Events are dispatched by calling a dispatch method on the instance of the Event\Manager
class and passing the name and some data, which is optional, to it. Here's an example of a Magento
core event:
$this->eventManager->dispatch( 'customer_customer_authenticated', ['model' => $this->getFullCustomerObject($customer), 'password' => $password] );
The $this->eventManager
is an instance of the previously mentioned Event\Manager
class. In this case, the event name equals to customer_customer_authenticated
, while the data passed to the event is the array with two elements. The preceding event is fired when the...