original_string: private function cascadePreRemove(ClassMetadata $class, $document)
      {
          $hasPreRemoveListeners = $this->evm->hasListeners(Events::preRemove);
  
          foreach ($class->fieldMappings as $mapping) {
              if (isset($mapping['embedded'])) {
                  $value = $class->reflFields[$mapping['fieldName']]->getValue($document);
                  if ($value === null) {
                      continue;
                  }
                  if ($mapping['type'] === 'one') {
                      $value = array($value);
                  }
                  foreach ($value as $entry) {
                      $entryClass = $this->dm->getClassMetadata(get_class($entry));
                      if ( ! empty($entryClass->lifecycleCallbacks[Events::preRemove])) {
                          $entryClass->invokeLifecycleCallbacks(Events::preRemove, $entry);
                      }
                      if ($hasPreRemoveListeners) {
                          $this->evm->dispatchEvent(Events::preRemove, new LifecycleEventArgs($entry, $this->dm));
                      }
                      $this->cascadePreRemove($entryClass, $entry);
                  }
              }
          }
      }
code: private function cascadePreRemove(ClassMetadata $class, $document)
      {
          $hasPreRemoveListeners = $this->evm->hasListeners(Events::preRemove);
  
          foreach ($class->fieldMappings as $mapping) {
              if (isset($mapping['embedded'])) {
                  $value = $class->reflFields[$mapping['fieldName']]->getValue($document);
                  if ($value === null) {
                      continue;
                  }
                  if ($mapping['type'] === 'one') {
                      $value = array($value);
                  }
                  foreach ($value as $entry) {
                      $entryClass = $this->dm->getClassMetadata(get_class($entry));
                      if ( ! empty($entryClass->lifecycleCallbacks[Events::preRemove])) {
                          $entryClass->invokeLifecycleCallbacks(Events::preRemove, $entry);
                      }
                      if ($hasPreRemoveListeners) {
                          $this->evm->dispatchEvent(Events::preRemove, new LifecycleEventArgs($entry, $this->dm));
                      }
                      $this->cascadePreRemove($entryClass, $entry);
                  }
              }
          }
      }
code_tokens: private function cascadePreRemove ( ClassMetadata $ class , $ document ) { $ hasPreRemoveListeners = $ this -> evm -> hasListeners ( Events :: preRemove ) ; foreach ( $ class -> fieldMappings as $ mapping ) { if ( isset ( $ mapping [ 'embedded' ] ) ) { $ value = $ class -> reflFields [ $ mapping [ 'fieldName' ] ] -> getValue ( $ document ) ; if ( $ value === null ) { continue ; } if ( $ mapping [ 'type' ] === 'one' ) { $ value = array ( $ value ) ; } foreach ( $ value as $ entry ) { $ entryClass = $ this -> dm -> getClassMetadata ( get_class ( $ entry ) ) ; if ( ! empty ( $ entryClass -> lifecycleCallbacks [ Events :: preRemove ] ) ) { $ entryClass -> invokeLifecycleCallbacks ( Events :: preRemove , $ entry ) ; } if ( $ hasPreRemoveListeners ) { $ this -> evm -> dispatchEvent ( Events :: preRemove , new LifecycleEventArgs ( $ entry , $ this -> dm ) ) ; } $ this -> cascadePreRemove ( $ entryClass , $ entry ) ; } } } }
docstring: Cascades the preRemove event to embedded documents.
  
  @param ClassMetadata $class
  @param object $document
docstring_tokens: Cascades the preRemove event to embedded documents .