本文整理汇总了PHP中Doctrine\ODM\MongoDB\MongoDBException::identifierRequired方法的典型用法代码示例。如果您正苦于以下问题:PHP MongoDBException::identifierRequired方法的具体用法?PHP MongoDBException::identifierRequired怎么用?PHP MongoDBException::identifierRequired使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ODM\MongoDB\MongoDBException
的用法示例。
在下文中一共展示了MongoDBException::identifierRequired方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateIdentifier
/**
* Validates the identifier mapping.
*
* @param ClassMetadata $class
*/
protected function validateIdentifier($class)
{
if (!$class->identifier && !$class->isMappedSuperclass && !$class->isEmbeddedDocument) {
throw MongoDBException::identifierRequired($class->name);
}
}
示例2: loadMetadata
/**
* Loads the metadata of the class in question and all it's ancestors whose metadata
* is still not loaded.
*
* @param string $name The name of the class for which the metadata should get loaded.
* @param array $tables The metadata collection to which the loaded metadata is added.
*/
private function loadMetadata($className)
{
if (!$this->initialized) {
$this->initialize();
}
$loaded = array();
$parentClasses = $this->getParentClasses($className);
$parentClasses[] = $className;
// Move down the hierarchy of parent classes, starting from the topmost class
$parent = null;
$visited = array();
foreach ($parentClasses as $className) {
if (isset($this->loadedMetadata[$className])) {
$parent = $this->loadedMetadata[$className];
if (!$parent->isMappedSuperclass && !$parent->isEmbeddedDocument) {
array_unshift($visited, $className);
}
continue;
}
$class = $this->newClassMetadataInstance($className);
if ($parent) {
if (!$parent->isMappedSuperclass) {
$class->setInheritanceType($parent->inheritanceType);
$class->setDiscriminatorField($parent->discriminatorField);
$class->setDiscriminatorMap($parent->discriminatorMap);
}
$class->setIdGeneratorType($parent->generatorType);
$this->addInheritedFields($class, $parent);
$this->addInheritedIndexes($class, $parent);
$class->setIdentifier($parent->identifier);
$class->setVersioned($parent->isVersioned);
$class->setVersionField($parent->versionField);
$class->setLifecycleCallbacks($parent->lifecycleCallbacks);
$class->setChangeTrackingPolicy($parent->changeTrackingPolicy);
$class->setFile($parent->getFile());
}
// Invoke driver
try {
$this->driver->loadMetadataForClass($className, $class);
} catch (ReflectionException $e) {
throw MongoDBException::reflectionFailure($className, $e);
}
if (!$class->identifier && !$class->isMappedSuperclass && !$class->isEmbeddedDocument) {
throw MongoDBException::identifierRequired($className);
}
if ($parent && !$parent->isMappedSuperclass && !$class->isEmbeddedDocument) {
if ($parent->generatorType) {
$class->setIdGeneratorType($parent->generatorType);
}
if ($parent->generatorOptions) {
$class->setIdGeneratorOptions($parent->generatorOptions);
}
if ($parent->idGenerator) {
$class->setIdGenerator($parent->idGenerator);
}
} else {
$this->completeIdGeneratorMapping($class);
}
if ($parent && $parent->isInheritanceTypeSingleCollection()) {
$class->setDatabase($parent->getDatabase());
$class->setCollection($parent->getCollection());
}
$db = $class->getDatabase() ?: $this->config->getDefaultDB();
$class->setDatabase($this->dm->formatDBName($db));
$class->setParentClasses($visited);
if ($this->evm->hasListeners(Events::loadClassMetadata)) {
$eventArgs = new \Doctrine\ODM\MongoDB\Event\LoadClassMetadataEventArgs($class, $this->dm);
$this->evm->dispatchEvent(Events::loadClassMetadata, $eventArgs);
}
$this->loadedMetadata[$className] = $class;
$parent = $class;
if (!$class->isMappedSuperclass && !$class->isEmbeddedDocument) {
array_unshift($visited, $className);
}
$loaded[] = $className;
}
return $loaded;
}