コード例 #1
0
 /**
  * Adds a entity listener for entities of this class.
  *
  * @param string $eventName The entity lifecycle event.
  * @param string $class     The listener class.
  * @param string $method    The listener callback method.
  *
  * @throws \Doctrine\ORM\Mapping\MappingException
  */
 public function addEntityListener($eventName, $class, $method)
 {
     $class = $this->fullyQualifiedClassName($class);
     $listener = array('class' => $class, 'method' => $method);
     if (!class_exists($class)) {
         throw MappingException::entityListenerClassNotFound($class, $this->name);
     }
     if (!method_exists($class, $method)) {
         throw MappingException::entityListenerMethodNotFound($class, $method, $this->name);
     }
     if (isset($this->entityListeners[$eventName]) && in_array($listener, $this->entityListeners[$eventName])) {
         throw MappingException::duplicateEntityListener($class, $method, $this->name);
     }
     $this->entityListeners[$eventName][] = $listener;
 }