@param $documentClass

@return \Doctrine\ODM\MongoDB\Mapping\ClassMetadata
351130
protected function getDocumentMetadata($documentClass)
    {
        $factory = new \Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory();
        $factory->setDocumentManager($this->getDocumentManager());
        $factory->setConfiguration($this->getDocumentManager()->getConfiguration());

        $metadata = $factory->getMetadataFor($documentClass);

        return $metadata;
    }
841627
public function getDocumentPersister(string $documentClass): DocumentPersister
    {
        if (isset($this->documentPersisters[$documentClass])) {
            return $this->documentPersisters[$documentClass];
        }

        return $this->documentPersisters[$documentClass] = new DocumentPersister($this->manager, $this->manager->getClassMetadata($documentClass));
    }
163988
public function getObjectMapping(string $class): NormalizationObjectMappingInterface
    {
        $reflectionClass = new \ReflectionClass($class);

        if (in_array('Doctrine\Common\Persistence\Proxy', $reflectionClass->getInterfaceNames(), true)) {
            $class = $reflectionClass->getParentClass()->name;
        }

        if (isset($this->objectMappings[$class])) {
            return $this->objectMappings[$class];
        }

        throw SerializerLogicException::createMissingMapping($class);
    }
1035502
public function getBulkWriteBuilder(string $documentClass): BulkWriteBuilder
    {
        $metadata = $this->metadataFactory->getClassMetadata($documentClass);

        return $this->bulkWriteBuilderFactory->getBulkWriteBuilder($this, $metadata->getCollectionName());
    }
899094
public function getDocumentDatabase($className)
    {
        $className = ltrim($className, '\\');

        if (isset($this->documentDatabases[$className])) {
            return $this->documentDatabases[$className];
        }

        $metadata = $this->metadataFactory->getMetadataFor($className);
        $db = $metadata->getDatabase();
        $db = $db ? $db : $this->config->getDefaultDB();
        $db = $db ? $db : 'doctrine';
        $this->documentDatabases[$className] = $this->connection->selectDatabase($db);

        return $this->documentDatabases[$className];
    }
201322
public function getClassAnnotation($class)
    {
        $reflClass = new \ReflectionClass($class);
        $mappedDocumentClass = static::ANNOTATION_CLASS_CLASS;

        foreach ($this->annotationReader->getClassAnnotations($reflClass) as $annotation) {
            if ($annotation instanceof $mappedDocumentClass) {
                return $annotation;
            }
        }

        return null;
    }
1116623
private function persistNew(ClassMetadata $class, $document)
    {
        $this->lifecycleEventManager->prePersist($class, $document);

        $oid    = spl_object_hash($document);
        $upsert = false;
        $index  = $class->getIndex();

        if ($index) {
            $identifier = $class->createIdentifier($document);
            $upsert     = !$class->isEmbeddedDocument && !$identifier->isNull();

            if ($identifier->isNull()) {
                foreach ($identifier->getKeys() as $key) {
                    $property = $key->getPropertyMetadata();

                    if ($property->generator === null) {
                        throw new \InvalidArgumentException(sprintf(
                            '%s.%s uses NONE identifier generation strategy but no identifier was provided when persisting.',
                            get_class($document),
                            $property->name
                        ));
                    } else {
                        $property->generate($this->dm, $document);
                    }
                }

                //rebuild identifier with the generated values
                $identifier = $class->createIdentifier($document);

                $this->documentIdentifiers[$oid] = $identifier;
            }
        } else {
            // this is for embedded documents without identifiers
            $this->documentIdentifiers[$oid] = $oid;
        }

        $this->documentStates[$oid] = self::STATE_MANAGED;

        if ($upsert) {
            $this->scheduleForUpsert($class, $document);
        } else {
            $this->scheduleForInsert($class, $document);
        }
    }
294522
public function getMetadata($objectClass)
    {
        if (! $objectClass instanceof ObjectKey) {
            $objectClass = new ObjectKey($objectClass);
        }

        $key = $objectClass->getKey();

        return $this->classMetadataFactory->loadMetadata(
            $objectClass,
            LoadingCriteria::createFromConfiguration($this->configuration, $objectClass),
            $this->configuration
        );
    }
571168
private function newInstance($class)
    {
        $entity = $class->newInstance();

        if ($entity instanceof \Doctrine\Common\Persistence\ObjectManagerAware) {
            $entity->injectObjectManager($this->em, $class);
        }

        return $entity;
    }
989946
public function getHydrator($class)
    {
        $metadata = $this->classMetadataFactory->getMetadataForClass($class);
        return new Hydrator($this->classMetadataFactory, $metadata, $this->documentManager, $this->repositoryFactory);
    }
732548
private function executeDeletions(ClassMetadata $class, array $documents)
    {
        $persister = $this->getDocumentPersister($class->name);

        foreach ($documents as $oid => $document) {
            if (!$class->isEmbeddedDocument) {
                $persister->delete($document);
            }
            unset(
                $this->documentDeletions[$oid],
                $this->documentIdentifiers[$oid],
                $this->originalDocumentData[$oid]
            );

            // Clear snapshot information for any referenced PersistentCollection
            // http://www.doctrine-project.org/jira/browse/MODM-95
            foreach ($class->associationMetadata as $attributeMapping) {
                if (!$attributeMapping->isMany()) {
                    continue;
                }

                $value = $class->getPropertyMetadata($attributeMapping->name)->getValue($document);
                if (!($value instanceof PersistentCollectionInterface)) {
                    continue;
                }

                $value->clearSnapshot();
            }

            // Document with this $oid after deletion treated as NEW, even if the $oid
            // is obtained by a new document because the old one went out of scope.
            $this->documentStates[$oid] = self::STATE_NEW;

            $this->lifecycleEventManager->postRemove($class, $document);
        }
    }
476070
public function newInstance(ClassMetadata $class)
    {
        $entity = $this->instantiator->instantiate($class->getClassName());

        if ($entity instanceof EntityManagerAware) {
            $entity->injectEntityManager($this->em, $class);
        }

        return $entity;
    }
816663
public function getRepository($entityClass)
    {
        $container = $this->getContainer();

        $em = $container->get('doctrine')->getManager();

        /* @var EntityRepository $repository */
        return $em->getRepository($entityClass);
    }
1284596
private function cascadePreUpdate(ClassMetadata $class, $document)
    {
        foreach ($class->getEmbeddedAttributesMappings() as $mapping) {
            $value = $class->getPropertyMetadata($mapping->attributeName)->getValue($document);
            if ($value === null) {
                continue;
            }
            $values = $mapping->isOne() ? [$value] : $value;

            foreach ($values as $entry) {
                if ($this->uow->isScheduledForInsert($entry) || empty($this->uow->getDocumentChangeSet($entry))) {
                    continue;
                }
                $this->preUpdate($this->dm->getClassMetadata(get_class($entry)), $entry);
            }
        }
    }
317912
protected function getEntityMapInstanceFromCache(string $entityClass)
    {
        if ($this->cache == null) {
            return;
        }

        if ($this->cache->has($entityClass)) {
            return unserialize($this->cache->get($entityClass));
        }
    }
1152553
public function create($documentClass, array $initializeArgs = array())
    {
        $document = new $documentClass($this);
        if (method_exists($document, 'initialize')) {
            call_user_func_array(array($document, 'initialize'), $initializeArgs);
        }

        return $document;
    }
526320
public function getDocumentCollection(string $className) : Collection
    {
        $className = $this->classNameResolver->getRealClass($className);

        /** @var ClassMetadata $metadata */
        $metadata = $this->metadataFactory->getMetadataFor($className);
        assert($metadata instanceof ClassMetadata);
        if ($metadata->isFile) {
            return $this->getDocumentBucket($className)->getFilesCollection();
        }

        $collectionName = $metadata->getCollection();

        if (! $collectionName) {
            throw MongoDBException::documentNotMappedToCollection($className);
        }

        if (! isset($this->documentCollections[$className])) {
            $db = $this->getDocumentDatabase($className);

            $options = [];
            if ($metadata->readPreference !== null) {
                $options['readPreference'] = new ReadPreference($metadata->readPreference, $metadata->readPreferenceTags);
            }

            $this->documentCollections[$className] = $db->selectCollection($collectionName, $options);
        }

        return $this->documentCollections[$className];
    }