/** * Adds a document listener for documents of this class. * * @param string $eventName The document lifecycle event. * @param string $class The listener class. * @param string $method The listener callback method. * * @throws MappingException */ public function addDocumentListener($eventName, $class, $method) { $class = $this->fullyQualifiedClassName($class); $listener = ['class' => $class, 'method' => $method]; if (!class_exists($class)) { throw MappingException::documentListenerClassNotFound($class, $this->name); } if (!method_exists($class, $method)) { throw MappingException::documentListenerMethodNotFound($class, $method, $this->name); } if (isset($this->documentListeners[$eventName]) && in_array($listener, $this->documentListeners[$eventName])) { throw MappingException::duplicateDocumentListener($class, $method, $this->name); } $this->documentListeners[$eventName][] = $listener; }