Loads the metadata for the specified class into the provided container.

@param string $className
@param ClassMetadata $metadata
437078
function loadMetadataForClass($className, ClassMetadata $metadata)
    {
        $moduleOptions = \SoliantEntityAudit\Module::getModuleOptions();
        $entityManager = $moduleOptions->getEntityManager();
        $metadataFactory = $entityManager->getMetadataFactory();
        $builder = new ClassMetadataBuilder($metadata);

        if ($className == 'SoliantEntityAudit\\Entity\RevisionEntity') {
            $builder->createField('id', 'integer')->isPrimaryKey()->generatedValue()->build();
            $builder->addManyToOne('revision', 'SoliantEntityAudit\\Entity\\Revision', 'revisionEntities');
            $builder->addField('entityKeys', 'string');
            $builder->addField('auditEntityClass', 'string');
            $builder->addField('targetEntityClass', 'string');
            $builder->addField('revisionType', 'string');
            $builder->addField('title', 'string', array('nullable' => true));

            $metadata->setTableName($moduleOptions->getRevisionEntityTableName());
            return;
        }

        // Revision is managed here rather than a separate namespace and driver
        if ($className == 'SoliantEntityAudit\\Entity\\Revision') {
            $builder->createField('id', 'integer')->isPrimaryKey()->generatedValue()->build();
            $builder->addField('comment', 'text', array('nullable' => true));
            $builder->addField('timestamp', 'datetime');

            // Add association between RevisionEntity and Revision
            $builder->addOneToMany('revisionEntities', 'SoliantEntityAudit\\Entity\\RevisionEntity', 'revision');

            // Add assoication between User and Revision
            $userMetadata = $metadataFactory->getMetadataFor($moduleOptions->getUserEntityClassName());
            $builder
                ->createManyToOne('user', $userMetadata->getName())
                ->addJoinColumn('user_id', $userMetadata->getSingleIdentifierColumnName())
                ->build();

            $metadata->setTableName($moduleOptions->getRevisionTableName());
            return;
        }

#        $builder->createField('audit_id', 'integer')->isPrimaryKey()->generatedValue()->build();
        $identifiers = array();
#        $metadata->setIdentifier(array('audit_id'));

        //  Build a discovered many to many join class
        $joinClasses = $moduleOptions->getJoinClasses();
        if (in_array($className, array_keys($joinClasses))) {

            $builder->createField('id', 'integer')->isPrimaryKey()->generatedValue()->build();

            $builder->addManyToOne('targetRevisionEntity', 'SoliantEntityAudit\\Entity\\RevisionEntity');
            $builder->addManyToOne('sourceRevisionEntity', 'SoliantEntityAudit\\Entity\\RevisionEntity');

            $metadata->setTableName($moduleOptions->getTableNamePrefix() . $joinClasses[$className]['joinTable']['name'] . $moduleOptions->getTableNameSuffix());
//            $metadata->setIdentifier($identifiers);
            return;
        }


        // Get the entity this entity audits
        $metadataClassName = $metadata->getName();
        $metadataClass = new $metadataClassName();

        $auditedClassMetadata = $metadataFactory->getMetadataFor($metadataClass->getAuditedEntityClass());

        $builder->addManyToOne($moduleOptions->getRevisionEntityFieldName(), 'SoliantEntityAudit\\Entity\\RevisionEntity');
# Compound keys removed in favor of auditId (audit_id)
        $identifiers[] = $moduleOptions->getRevisionEntityFieldName();

        // Add fields from target to audit entity
        foreach ($auditedClassMetadata->getFieldNames() as $fieldName) {
            $builder->addField($fieldName, $auditedClassMetadata->getTypeOfField($fieldName), array('nullable' => true, 'quoted' => true));
            if ($auditedClassMetadata->isIdentifier($fieldName)) $identifiers[] = $fieldName;
        }

        foreach ($auditedClassMetadata->getAssociationMappings() as $mapping) {
            if (!$mapping['isOwningSide']) continue;

            if (isset($mapping['joinTable'])) {
                continue;
            }

            if (isset($mapping['joinTableColumns'])) {
                foreach ($mapping['joinTableColumns'] as $field) {
                    $builder->addField($mapping['fieldName'], 'integer', array('nullable' => true, 'columnName' => $field));
                }
            } elseif (isset($mapping['joinColumnFieldNames'])) {
                foreach ($mapping['joinColumnFieldNames'] as $field) {
                    $builder->addField($mapping['fieldName'], 'integer', array('nullable' => true, 'columnName' => $field));
                }
            } else {
                throw new \Exception('Unhandled association mapping');
            }

        }

        $metadata->setTableName($moduleOptions->getTableNamePrefix() . $auditedClassMetadata->getTableName() . $moduleOptions->getTableNameSuffix());
        $metadata->setIdentifier($identifiers);

        return;
    }
1353850
private function addConfigFields(ClassMetadata $metadata, $className)
    {
        foreach ($metadata->getFieldNames() as $field) {
            if (!$metadata->isIdentifier($field)) {
                $this->configs[$className][0][$field] = $metadata->getTypeOfField($field);
            }
        }
    }
1215001
public function loadMetadataForClass($className, ClassMetadataInterface $class)
    {
        /** @var $class ClassMetadata */
        $reflection     = $class->getReflectionClass();
        $documentAnnots = [];
        $indexes        = [];

        //class annotations
        $classAnnotations = $this->reader->getClassAnnotations($reflection);
        foreach ($classAnnotations as $annot) {
            //document annotations
            $classAnnotations[get_class($annot)] = $annot;

            foreach ($this->entityAnnotationClasses as $annotClass => $i) {
                if ($annot instanceof $annotClass) {
                    $documentAnnots[$i] = $annot;
                    continue 2;
                }
            }

            //non-document class annotations
            if ($annot instanceof ODM\Discriminator) {
                if ($annot->attribute !== null) {
                    $class->setDiscriminatorAttribute($annot->attribute);
                }
                if ($annot->map !== null) {
                    $class->setDiscriminatorMap($annot->map);
                }
                if ($annot->defaultValue !== null) {
                    $class->setDiscriminatorDefaultValue($annot->defaultValue);
                }
            } elseif ($annot instanceof ODM\InheritanceType) {
                $class->setInheritanceType(constant(ClassMetadata::class . '::INHERITANCE_TYPE_' . $annot->value));
            } elseif ($annot instanceof ODM\Index) {
                $indexes[$annot->name]['projectionType'] = $annot->projectionType;
                $indexes[$annot->name]['readCapacity']   = $annot->readCapacity;
                $indexes[$annot->name]['writeCapacity']  = $annot->writeCapacity;
            } elseif ($annot instanceof ODM\ChangeTrackingPolicy) {
                $class->setChangeTrackingPolicy(constant(ClassMetadata::class . '::CHANGETRACKING_' . $annot->value));
            }
        }

        if (!$documentAnnots) {
            throw new MappingExceptionClassNotMapped($className);
        }

        //find the winning document annotation
        ksort($documentAnnots);
        $documentAnnot = reset($documentAnnots);

        if ($documentAnnot instanceof ODM\MappedSuperclass) {
            $class->isMappedSuperclass = true;
        } elseif ($documentAnnot instanceof ODM\EmbeddedDocument) {
            $class->isEmbeddedDocument = true;
        }
        if (isset($documentAnnot->table)) {
            $class->setTable($documentAnnot->table);
        }
        if (isset($documentAnnot->repositoryClass) && !$class->isEmbeddedDocument) {
            $class->setCustomRepositoryClass($documentAnnot->repositoryClass);
        }
        if (isset($documentAnnot->requireIndexes)) {
            $class->setRequireIndexes($documentAnnot->requireIndexes);
        }
        if (!empty($documentAnnot->readOnly)) {
            $class->markReadOnly();
        }

        //property annotations
        $propertyFactory = new PropertyMetadataFactory($class);
        foreach ($reflection->getProperties() as $property) {
            if (!$this->propertyNeedsMapping($class, $property)) {
                continue;
            }

            $mapping        = $propertyFactory->create($property->getName());
            $attributeAnnot = null;

            foreach ($this->reader->getPropertyAnnotations($property) as $annot) {
                if ($annot instanceof ODM\AbstractAttribute) {
                    $attributeAnnot         = true;
                    $mapping->attributeName = $annot->name;

                    if ($annot instanceof ODM\NotSaved) {
                        $mapping->notSaved = true;
                        continue;
                    }

                    $mapping->nullable = $annot->nullable;
                    $mapping->strategy = $annot->strategy;
                    $mapping->type     = $annot->type;

                    if ($class->isEmbeddedDocument && $mapping->strategy === PropertyMetadata::STORAGE_STRATEGY_ADD_TO_SET) {
                        throw MappingException::addToSetOnEmbeddedDocument($class->name, $property->getName());
                    }

                    if ($annot instanceof ODM\AbstractEmbed) {
                        $mapping->embedded       = $annot->embedded;
                        $mapping->targetDocument = $annot->targetDocument;

                        if ($annot instanceof ODM\EmbedMany) {
                            $mapping->collectionClass = $annot->collectionClass;
                        }
                    } elseif ($annot instanceof ODM\AbstractReference) {
                        $mapping->criteria         = $annot->criteria;
                        $mapping->inversedBy       = $annot->inversedBy;
                        $mapping->mappedBy         = $annot->mappedBy;
                        $mapping->mappedIndex      = $annot->mappedIndex;
                        $mapping->orphanRemoval    = $annot->orphanRemoval;
                        $mapping->reference        = $annot->reference;
                        $mapping->requireIndexes   = $annot->requireIndexes;
                        $mapping->repositoryMethod = $annot->repositoryMethod;
                        $mapping->storeAs          = $annot->storeAs;
                        $mapping->targetDocument   = $annot->targetDocument;

                        if ($annot instanceof ODM\ReferenceMany) {
                            $mapping->limit           = $annot->limit;
                            $mapping->prime           = $annot->prime;
                            $mapping->collectionClass = $annot->collectionClass;

                            if ($annot->order === PropertyMetadata::ORDER_REVERSE) {
                                $mapping->reverse = true;
                            }
                        }

                        $mapping->setCascades((array)$annot->cascade);
                    }
                } elseif ($annot instanceof ODM\HashKey) {
                    $indexes[$annot->index]['hashKey'] = new HashKey($mapping);
                } elseif ($annot instanceof ODM\RangeKey) {
                    $indexes[$annot->index]['rangeKey'] = new RangeKey($mapping);
                } elseif ($annot instanceof ODM\Project) {
                    $value = (array)$annot->value;

                    if (count($value) === 0) {
                        //if no name is specified the primary index is assumed
                        $indexes[null]['projectionAttributes'][] = $property->getName();
                    } else {
                        foreach ($value as $indexName) {
                            $indexes[$indexName]['projectionAttributes'][] = $property->getName();
                        }
                    }
                } elseif ($annot instanceof ODM\GeneratedValue) {
                    $mapping->generatorStrategy = $annot->strategy;
                    $mapping->generatorOptions  = $annot->options;
                } elseif ($annot instanceof ODM\Discriminator) {
                    $mapping->discriminatorAttribute    = $annot->attribute;
                    $mapping->discriminatorMap          = $annot->map;
                    $mapping->discriminatorDefaultValue = $annot->defaultValue;
                } elseif ($annot instanceof ODM\AlsoLoad) {
                    $mapping->alsoLoadAttributes = (array)$annot->value;
                } elseif ($annot instanceof ODM\Version) {
                    $mapping->version = true;
                } elseif ($annot instanceof ODM\Lock) {
                    $mapping->lock = true;
                } elseif ($annot instanceof ODM\ChangeTrackingPolicy) {
                    $class->setChangeTrackingPolicy(constant(ClassMetadata::class . '::CHANGETRACKING_' . $annot->value));
                }
            }

            if ($attributeAnnot) {
                $mapping->mapAttribute($class);
            }
        }

        //method annotations
        foreach ($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
            /* Filter for the declaring class only. Callbacks from parent
             * classes will already be registered.
             */
            if ($method->getDeclaringClass()->name !== $reflection->name) {
                continue;
            }

            foreach ($this->reader->getMethodAnnotations($method) as $annot) {
                if ($annot instanceof ODM\AlsoLoad) {
                    $class->registerAlsoLoadMethod($method->getName(), $annot->value);
                }

                if (!isset($classAnnotations[ODM\HasLifecycleCallbacks::class])) {
                    continue;
                }

                if ($annot instanceof ODM\PrePersist) {
                    $class->addLifecycleCallback($method->getName(), Event::prePersist);
                } elseif ($annot instanceof ODM\PostPersist) {
                    $class->addLifecycleCallback($method->getName(), Event::postPersist);
                } elseif ($annot instanceof ODM\PreUpdate) {
                    $class->addLifecycleCallback($method->getName(), Event::preUpdate);
                } elseif ($annot instanceof ODM\PostUpdate) {
                    $class->addLifecycleCallback($method->getName(), Event::postUpdate);
                } elseif ($annot instanceof ODM\PreRemove) {
                    $class->addLifecycleCallback($method->getName(), Event::preRemove);
                } elseif ($annot instanceof ODM\PostRemove) {
                    $class->addLifecycleCallback($method->getName(), Event::postRemove);
                } elseif ($annot instanceof ODM\PreLoad) {
                    $class->addLifecycleCallback($method->getName(), Event::preLoad);
                } elseif ($annot instanceof ODM\PostLoad) {
                    $class->addLifecycleCallback($method->getName(), Event::postLoad);
                } elseif ($annot instanceof ODM\PreFlush) {
                    $class->addLifecycleCallback($method->getName(), Event::preFlush);
                }
            }
        }

        //indexes
        $indexFactory = new IndexFactory($class);
        foreach ($indexes as $name => $annot) {
            $primary = $name === '';

            //create index, merging values collected from annotations with defaults
            $opts                  = array_fill_keys(['hashKey', 'rangeKey', 'projectionType', 'projectionAttributes'], null);
            $opts['readCapacity']  = IndexFactory::DEFAULT_READ_CAPACITY;
            $opts['writeCapacity'] = IndexFactory::DEFAULT_WRITE_CAPACITY;
            $opts                  = array_merge($opts, $annot);

            $index = $indexFactory->create(
                $primary ? null : $name,
                $opts['hashKey'],
                $opts['rangeKey'],
                $opts['projectionType'],
                $opts['projectionAttributes'],
                $opts['readCapacity'],
                $opts['writeCapacity']
            );

            if ($primary === true) {
                $class->setIndex($index);
            } else {
                $class->addSecondaryIndex($index);
            }
        }
    }
1031704
protected function loadMetadata($className)
    {
        $resource = new ResourceMetadata($className);

        $this->driver->loadMetadataForClass($className, $resource);

        $this->loadedMetadata[$className] = $resource;
        $this->resourceClassMap[$resource->getName()] = $className;
    }
817647
private function convertToClassMetadataInfo($className, $mappingInformation)
    {
        $metadata = new ClassMetadataInfo($className);

        $this->convertTableName($className, $mappingInformation, $metadata);
        $this->convertColumns($className, $mappingInformation, $metadata);
        $this->convertIndexes($className, $mappingInformation, $metadata);
        $this->convertRelations($className, $mappingInformation, $metadata);

        return $metadata;
    }
152868
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
    {
        $classMetadata = $eventArgs->getClassMetadata();
        if (MetadataLayer::isAlreadyProcessed($classMetadata)) {
            // we can skip it
            return;
        }

        $fieldNames = array_flip($classMetadata->getFieldNames());
        $reflectionClass = $classMetadata->getReflectionClass();

        foreach ($reflectionClass->getProperties() as $reflectionProperty) {
            if (isset($fieldNames[$reflectionProperty->getName()])) {
                $this->loadHubProperty($reflectionProperty, $classMetadata);
            } else {
                $this->loadMaskProperty($reflectionProperty, $classMetadata);
            }
        }
    }
224804
public function loadMetadataForClass(\ReflectionClass $class)
    {
        foreach ($this->drivers as $driver) {
            if (null !== $metadata = $driver->loadMetadataForClass($class)) {
                return $metadata;
            }
        }
    }
1326270
public function loadMetadataForClass($className, ClassMetadata $metadata)
    {
        $class = $metadata->getReflectionClass();

        if (!$class) {
            $class = new \ReflectionClass((string) $className);
        }

        $classAnnotations = $this->reader->getClassAnnotations($class);
        
        $classMapping = array();
        $validMapping = false;
        foreach ($classAnnotations as $annotation) {
            switch(get_class($annotation)) {
                case 'Doctrine\Search\Mapping\Annotations\ElasticSearchable':
                    $classMapping = (array) $annotation;
                    $classMapping['class'] = 'ElasticSearchable';
                    $validMapping = true;
                    break;
                case 'Doctrine\Search\Mapping\Annotations\Searchable':
                    $classMapping = (array) $annotation;
                    $classMapping['class'] = 'Searchable';
                    $validMapping = true;
                    break;
                case 'Doctrine\Search\Mapping\Annotations\ElasticRoot':
                    $rootMapping = (array) $annotation;
                    $metadata->mapRoot($this->rootToArray($rootMapping));
                    break;
            }
        }
        
        if (!$validMapping) {
            throw MappingException::classIsNotAValidDocument($className);
        }
        
        $this->annotateClassMetadata($classMapping, $metadata);

        $properties = $class->getProperties();
        foreach ($properties as $property) {
            $propertyAnnotations = $this->reader->getPropertyAnnotations($property);
            foreach ($propertyAnnotations as $annotation) {
                switch (get_class($annotation)) {
                    case 'Doctrine\Search\Mapping\Annotations\Id':
                        $metadata->identifier = $property->getName();
                        break;
                    case 'Doctrine\Search\Mapping\Annotations\Parameter':
                        $mapping = $this->parameterToArray($property->getName(), (array) $annotation);
                        $metadata->mapParameter($mapping);
                        break;
                    case 'Doctrine\Search\Mapping\Annotations\Field':
                    case 'Doctrine\Search\Mapping\Annotations\ElasticField':
                    case 'Doctrine\Search\Mapping\Annotations\SolrField':
                        $mapping = $this->fieldToArray($property->getName(), (array) $annotation);
                        $metadata->mapField($mapping);
                        break;
                }
            }
        }
    }
127859
protected function doLoadMetadata(
        string $className,
        ?ClassMetadata $parent,
        ClassMetadataBuildingContext $metadataBuildingContext
    ) : ClassMetadata {
        $classMetadata = new ClassMetadata($className, $metadataBuildingContext);

        if ($parent) {
            $classMetadata->setParent($parent);

            foreach ($parent->getDeclaredPropertiesIterator() as $fieldName => $property) {
                $classMetadata->addInheritedProperty($property);
            }

            $classMetadata->setInheritanceType($parent->inheritanceType);
            $classMetadata->setIdentifier($parent->identifier);

            if ($parent->discriminatorColumn) {
                $classMetadata->setDiscriminatorColumn($parent->discriminatorColumn);
                $classMetadata->setDiscriminatorMap($parent->discriminatorMap);
            }

            $classMetadata->setLifecycleCallbacks($parent->lifecycleCallbacks);
            $classMetadata->setChangeTrackingPolicy($parent->changeTrackingPolicy);

            if ($parent->isMappedSuperclass) {
                $classMetadata->setCustomRepositoryClassName($parent->getCustomRepositoryClassName());
            }
        }

        // Invoke driver
        try {
            $this->driver->loadMetadataForClass($classMetadata->getClassName(), $classMetadata, $metadataBuildingContext);
        } catch (ReflectionException $e) {
            throw MappingException::reflectionFailure($classMetadata->getClassName(), $e);
        }

        $this->completeIdentifierGeneratorMappings($classMetadata);

        if ($parent) {
            if ($parent->getCache()) {
                $classMetadata->setCache(clone $parent->getCache());
            }

            if (! empty($parent->entityListeners) && empty($classMetadata->entityListeners)) {
                $classMetadata->entityListeners = $parent->entityListeners;
            }
        }

        $this->completeRuntimeMetadata($classMetadata, $parent);

        if ($this->evm->hasListeners(Events::loadClassMetadata)) {
            $eventArgs = new LoadClassMetadataEventArgs($classMetadata, $this->em);

            $this->evm->dispatchEvent(Events::loadClassMetadata, $eventArgs);
        }

        $this->buildValueGenerationPlan($classMetadata);
        $this->validateRuntimeMetadata($classMetadata, $parent);

        return $classMetadata;
    }
754659
public static function loadValidatorMetadata(ClassMetadata $metadata)
    {
        $metadata->addPropertyConstraint('ref', new Assert\Blank());

        $metadata->addPropertyConstraint('alert', new Assert\NotBlank());
        $metadata->addPropertyConstraint('alert', new Assert\Choice(array(
            'callback' => array('\WSColissimo\WSColiPosteLetterService\Request\ValueObject\Choice\AlertType', 'getChoices')
        )));

        $metadata->addPropertyConstraint('addressVO', new Assert\NotBlank());
        $metadata->addPropertyConstraint('addressVO', new Assert\Valid());
    }
98882
public function loadMetadataForClass(
        string $className,
        Mapping\ClassMetadata $metadata,
        Mapping\ClassMetadataBuildingContext $metadataBuildingContext
    ) {
        // IMPORTANT: We're handling $metadata as "parent" metadata here, while building the $className ClassMetadata.
        $reflectionClass = new ReflectionClass($className);

        // Evaluate annotations on class metadata
        $classAnnotations = $this->getClassAnnotations($reflectionClass);
        $classMetadata    = $this->convertClassAnnotationsToClassMetadata(
            $classAnnotations,
            $reflectionClass,
            $metadata
        );

        // Evaluate @Cache annotation
        if (isset($classAnnotations[Annotation\Cache::class])) {
            $cacheAnnot = $classAnnotations[Annotation\Cache::class];
            $cache      = $this->convertCacheAnnotationToCacheMetadata($cacheAnnot, $classMetadata);

            $classMetadata->setCache($cache);
        }

        // Evaluate annotations on properties/fields
        /** @var ReflectionProperty $reflectionProperty */
        foreach ($reflectionClass->getProperties() as $reflectionProperty) {
            if ($reflectionProperty->getDeclaringClass()->getClassName() !== $reflectionClass->getName()) {
                continue;
            }

            $propertyAnnotations = $this->getPropertyAnnotations($reflectionProperty);
            $property            = $this->convertReflectionPropertyAnnotationsToProperty(
                $reflectionProperty,
                $propertyAnnotations,
                $classMetadata
            );

            $classMetadata->addDeclaredProperty($property);
        }

        return $classMetadata;
    }
86955
public function getMetadataFor(string $className) : ClassMetadata
    {
        if (isset($this->loadedMetadata[$className])) {
            return $this->loadedMetadata[$className];
        }

        // Check for namespace alias
        if (strpos($className, ':') !== false) {
            [$namespaceAlias, $simpleClassName] = explode(':', $className, 2);

            $realClassName = $this->getFqcnFromAlias($namespaceAlias, $simpleClassName);
        } else {
            $realClassName = $this->getRealClass($className);
        }

        if (isset($this->loadedMetadata[$realClassName])) {
            // We do not have the alias name in the map, include it
            return $this->loadedMetadata[$className] = $this->loadedMetadata[$realClassName];
        }

        $loadingException = null;

        try {
            if ($this->cacheDriver !== null) {
                $cached = $this->cacheDriver->fetch($realClassName . $this->cacheSalt);

                if ($cached instanceof ClassMetadata) {
                    $this->loadedMetadata[$realClassName] = $cached;

                    $this->wakeupReflection($cached, $this->getReflectionService());
                } else {
                    foreach ($this->loadMetadata($realClassName) as $loadedClassName) {
                        $this->cacheDriver->save(
                            $loadedClassName . $this->cacheSalt,
                            $this->loadedMetadata[$loadedClassName]
                        );
                    }
                }
            } else {
                $this->loadMetadata($realClassName);
            }
        } catch (MappingException $loadingException) {
            $fallbackMetadataResponse = $this->onNotFoundMetadata($realClassName);

            if ($fallbackMetadataResponse === null) {
                throw $loadingException;
            }

            $this->loadedMetadata[$realClassName] = $fallbackMetadataResponse;
        }

        if ($className !== $realClassName) {
            // We do not have the alias name in the map, include it
            $this->loadedMetadata[$className] = $this->loadedMetadata[$realClassName];
        }

        return $this->loadedMetadata[$className];
    }
1007828
public function load($className) {
    // search under baseDir assuming that namespaces match directories
    $filename = $this->baseDir.str_replace("\\", "/", $className).'.php';
    if (file_exists($filename)) {
      include($filename);
    }
  }
869296
public function loadClassMetadata(LoadClassMetadataEventArgs $event)
    {
        /** @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */
        $metadata = $event->getClassMetadata();

        if ( ! isset($this->entityListeners[$metadata->name])) {
            return;
        }

        foreach ($this->entityListeners[$metadata->name] as $listener) {
            $metadata->addEntityListener($listener['event'], $listener['class'], $listener['method']);
        }

        unset($this->entityListeners[$metadata->name]);
    }
601850
protected function getInstance(ClassMetadata $metadata)
    {
        $reflection = new ReflectionClass($metadata->getName());
        $instance   = $reflection->newInstanceWithoutConstructor();

        return $instance;
    }
403374
protected function loadMetadataFromFile(\ReflectionClass $class, $file)
    {
        $config = Yaml::parse(file_get_contents($file));

        if (!isset($config[$name = $class->name])) {
            throw new RuntimeException(sprintf('Expected metadata for class %s to be defined in %s.', $class->name, $file));
        }


        $config = $config[$name];
        $metadata = new ClassMetadata($name);
        $metadata->fileResources[] = $file;
        $metadata->fileResources[] = $class->getFileName();

        foreach ($config as $type => $value) {
            if (!array_key_exists('name', $value)) {
                throw new RuntimeException('Could not find key "type" inside yaml element.');
            }
            $metadata->addRoute($type, $value['name'], array_key_exists('params', $value) ? $value['params'] : array());
        }

        return $metadata;

    }
1118845
public function getMetadataFor($className)
    {
        $metadata = parent::getMetadataFor($className);
        if ($metadata) {
            return $metadata;
        }

        throw MappingException::classNotMapped($className);
    }