本文整理汇总了PHP中Doctrine\Common\Persistence\Mapping\ClassMetadata::setMixins方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::setMixins方法的具体用法?PHP ClassMetadata::setMixins怎么用?PHP ClassMetadata::setMixins使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Persistence\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::setMixins方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadata $class)
{
/** @var $class \Doctrine\ODM\PHPCR\Mapping\ClassMetadata */
try {
$element = $this->getElement($className);
} catch (DoctrineMappingException $e) {
// Convert Exception type for consistency with other drivers
throw new MappingException($e->getMessage(), $e->getCode(), $e);
}
if (!$element) {
return;
}
$element['type'] = isset($element['type']) ? $element['type'] : 'document';
if (isset($element['repositoryClass'])) {
$class->setCustomRepositoryClassName($element['repositoryClass']);
}
if (isset($element['translator'])) {
$class->setTranslator($element['translator']);
}
if (isset($element['versionable']) && $element['versionable']) {
$class->setVersioned($element['versionable']);
}
if (isset($element['referenceable']) && $element['referenceable']) {
$class->setReferenceable($element['referenceable']);
}
if (isset($element['uniqueNodeType']) && $element['uniqueNodeType']) {
$class->setUniqueNodeType($element['uniqueNodeType']);
}
if (isset($element['mixins'])) {
$mixins = array();
foreach ($element['mixins'] as $mixin) {
$mixins[] = $mixin;
}
$class->setMixins($mixins);
}
if (isset($element['inheritMixins'])) {
$class->setInheritMixins($element['inheritMixins']);
}
if (isset($element['nodeType'])) {
$class->setNodeType($element['nodeType']);
}
if ($element['type'] === 'mappedSuperclass') {
$class->isMappedSuperclass = true;
}
if (isset($element['fields'])) {
foreach ($element['fields'] as $fieldName => $mapping) {
if (is_string($mapping)) {
$type = $mapping;
$mapping = array();
$mapping['type'] = $type;
}
if (!isset($mapping['fieldName'])) {
$mapping['fieldName'] = $fieldName;
}
$class->mapField($mapping);
}
}
if (isset($element['uuid'])) {
$mapping = array('fieldName' => $element['uuid'], 'uuid' => true);
$class->mapField($mapping);
}
if (isset($element['id'])) {
if (is_array($element['id'])) {
if (!isset($element['id']['fieldName'])) {
throw new MappingException("Missing fieldName property for id field");
}
$fieldName = $element['id']['fieldName'];
} else {
$fieldName = $element['id'];
}
$mapping = array('fieldName' => $fieldName, 'id' => true);
if (isset($element['id']['generator']['strategy'])) {
$mapping['strategy'] = $element['id']['generator']['strategy'];
}
$class->mapId($mapping);
}
if (isset($element['node'])) {
$class->mapNode(array('fieldName' => $element['node']));
}
if (isset($element['nodename'])) {
$class->mapNodename(array('fieldName' => $element['nodename']));
}
if (isset($element['parentdocument'])) {
$mapping = array('fieldName' => $element['parentdocument'], 'cascade' => isset($element['cascade']) ? $this->getCascadeMode($element['cascade']) : 0);
$class->mapParentDocument($mapping);
}
if (isset($element['child'])) {
foreach ($element['child'] as $fieldName => $mapping) {
if (is_string($mapping)) {
$name = $mapping;
$mapping = array();
$mapping['nodeName'] = $name;
}
if (!isset($mapping['fieldName'])) {
$mapping['fieldName'] = $fieldName;
}
$mapping['cascade'] = isset($mapping['cascade']) ? $this->getCascadeMode($mapping['cascade']) : 0;
//.........这里部分代码省略.........
示例2: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
/** @var $metadata \Doctrine\ODM\PHPCR\Mapping\ClassMetadata */
$reflClass = $metadata->getReflectionClass();
$documentAnnots = array();
foreach ($this->reader->getClassAnnotations($reflClass) as $annot) {
foreach ($this->entityAnnotationClasses as $annotClass => $i) {
if ($annot instanceof $annotClass) {
$documentAnnots[$i] = $annot;
}
}
}
if (!$documentAnnots) {
throw MappingException::classIsNotAValidDocument($className);
}
// find the winning document annotation
ksort($documentAnnots);
$documentAnnot = reset($documentAnnots);
if ($documentAnnot instanceof ODM\MappedSuperclass) {
$metadata->isMappedSuperclass = true;
}
if (null !== $documentAnnot->referenceable) {
$metadata->setReferenceable($documentAnnot->referenceable);
}
if (null !== $documentAnnot->versionable) {
$metadata->setVersioned($documentAnnot->versionable);
}
if (null !== $documentAnnot->mixins) {
$metadata->setMixins($documentAnnot->mixins);
}
if (null !== $documentAnnot->inheritMixins) {
$metadata->setInheritMixins($documentAnnot->inheritMixins);
}
if (null !== $documentAnnot->nodeType) {
$metadata->setNodeType($documentAnnot->nodeType);
}
if (null !== $documentAnnot->repositoryClass) {
$metadata->setCustomRepositoryClassName($documentAnnot->repositoryClass);
}
if (null !== $documentAnnot->translator) {
$metadata->setTranslator($documentAnnot->translator);
}
foreach ($reflClass->getProperties() as $property) {
if ($metadata->isInheritedField($property->name) && $metadata->name !== $property->getDeclaringClass()->getName()) {
continue;
}
$mapping = array();
$mapping['fieldName'] = $property->getName();
foreach ($this->reader->getPropertyAnnotations($property) as $fieldAnnot) {
if ($fieldAnnot instanceof ODM\Property) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapField($mapping);
} elseif ($fieldAnnot instanceof ODM\Id) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapId($mapping);
} elseif ($fieldAnnot instanceof ODM\Node) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapNode($mapping);
} elseif ($fieldAnnot instanceof ODM\Nodename) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapNodename($mapping);
} elseif ($fieldAnnot instanceof ODM\ParentDocument) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
$metadata->mapParentDocument($mapping);
} elseif ($fieldAnnot instanceof ODM\Child) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
$metadata->mapChild($mapping);
} elseif ($fieldAnnot instanceof ODM\Children) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
$metadata->mapChildren($mapping);
} elseif ($fieldAnnot instanceof ODM\ReferenceOne) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
$metadata->mapManyToOne($mapping);
} elseif ($fieldAnnot instanceof ODM\ReferenceMany) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
$metadata->mapManyToMany($mapping);
} elseif ($fieldAnnot instanceof ODM\Referrers) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
$metadata->mapReferrers($mapping);
} elseif ($fieldAnnot instanceof ODM\MixedReferrers) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapMixedReferrers($mapping);
} elseif ($fieldAnnot instanceof ODM\Locale) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapLocale($mapping);
} elseif ($fieldAnnot instanceof ODM\Depth) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapDepth($mapping);
} elseif ($fieldAnnot instanceof ODM\VersionName) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapVersionName($mapping);
//.........这里部分代码省略.........
示例3: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadata $class)
{
/** @var $class \Doctrine\ODM\PHPCR\Mapping\ClassMetadata */
try {
$xmlRoot = $this->getElement($className);
} catch (DoctrineMappingException $e) {
// Convert Exception type for consistency with other drivers
throw new MappingException($e->getMessage(), $e->getCode(), $e);
}
if (!$xmlRoot) {
return;
}
if (isset($xmlRoot['repository-class'])) {
$class->setCustomRepositoryClassName((string) $xmlRoot['repository-class']);
}
if (isset($xmlRoot['translator'])) {
$class->setTranslator((string) $xmlRoot['translator']);
}
if (isset($xmlRoot['versionable']) && $xmlRoot['versionable'] !== 'false') {
$class->setVersioned(strtolower($xmlRoot['versionable']));
}
if (isset($xmlRoot['referenceable']) && $xmlRoot['referenceable'] !== 'false') {
$class->setReferenceable((bool) $xmlRoot['referenceable']);
}
if (isset($xmlRoot->mixins)) {
$mixins = array();
foreach ($xmlRoot->mixins->mixin as $mixin) {
$attributes = $mixin->attributes();
if (!isset($attributes['type'])) {
throw new MappingException('<mixin> missing mandatory type attribute');
}
$mixins[] = (string) $attributes['type'];
}
$class->setMixins($mixins);
}
if (isset($xmlRoot['node-type'])) {
$class->setNodeType((string) $xmlRoot['node-type']);
}
if ($xmlRoot->getName() === 'mapped-superclass') {
$class->isMappedSuperclass = true;
}
if (isset($xmlRoot->field)) {
foreach ($xmlRoot->field as $field) {
$mapping = array();
$attributes = $field->attributes();
foreach ($attributes as $key => $value) {
$mapping[$key] = (string) $value;
// convert bool fields
if (in_array($key, array('id', 'multivalue', 'assoc', 'translated', 'nullable'))) {
$mapping[$key] = 'true' === $mapping[$key] ? true : false;
}
}
if (!isset($mapping['name'])) {
throw new MappingException(sprintf('Missing name attribute for field of %s', $className));
}
$mapping['fieldName'] = $mapping['name'];
unset($mapping['name']);
$class->mapField($mapping);
}
}
if (isset($xmlRoot->id)) {
$mapping = array('fieldName' => (string) $xmlRoot->id->attributes()->name, 'id' => true);
if (isset($xmlRoot->id->generator) && isset($xmlRoot->id->generator->attributes()->strategy)) {
$mapping['strategy'] = (string) $xmlRoot->id->generator->attributes()->strategy;
}
$class->mapId($mapping);
}
if (isset($xmlRoot->node)) {
$class->mapNode(array('fieldName' => (string) $xmlRoot->node->attributes()->name));
}
if (isset($xmlRoot->nodename)) {
$class->mapNodename(array('fieldName' => (string) $xmlRoot->nodename->attributes()->name));
}
if (isset($xmlRoot->{'parent-document'})) {
$mapping = array('fieldName' => (string) $xmlRoot->{'parent-document'}->attributes()->name, 'cascade' => isset($xmlRoot->{'parent-document'}->cascade) ? $this->getCascadeMode($xmlRoot->{'parent-document'}->cascade) : 0);
$class->mapParentDocument($mapping);
}
if (isset($xmlRoot->child)) {
foreach ($xmlRoot->child as $child) {
$attributes = $child->attributes();
$mapping = array('fieldName' => (string) $attributes->name, 'cascade' => isset($child->cascade) ? $this->getCascadeMode($child->cascade) : 0);
if (isset($attributes['node-name'])) {
$mapping['nodeName'] = (string) $attributes->{'node-name'};
}
$class->mapChild($mapping);
}
}
if (isset($xmlRoot->children)) {
foreach ($xmlRoot->children as $children) {
$attributes = $children->attributes();
$mapping = array('fieldName' => (string) $attributes->name, 'cascade' => isset($children->cascade) ? $this->getCascadeMode($children->cascade) : 0, 'filter' => isset($attributes['filter']) ? (array) $attributes->filter : null, 'fetchDepth' => isset($attributes['fetch-depth']) ? (int) $attributes->{'fetch-depth'} : -1, 'ignoreUntranslated' => !empty($attributes['ignore-untranslated']));
$class->mapChildren($mapping);
}
}
if (isset($xmlRoot->{'reference-many'})) {
foreach ($xmlRoot->{'reference-many'} as $reference) {
$attributes = $reference->attributes();
//.........这里部分代码省略.........