本文整理汇总了PHP中Doctrine\Common\Persistence\Mapping\ClassMetadata::mapEmbedded方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::mapEmbedded方法的具体用法?PHP ClassMetadata::mapEmbedded怎么用?PHP ClassMetadata::mapEmbedded使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Persistence\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::mapEmbedded方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadMetadataForClass
//.........这里部分代码省略.........
$mapping['cascade'] = $manyToOneAnnot->cascade;
$mapping['inversedBy'] = $manyToOneAnnot->inversedBy;
$mapping['targetEntity'] = $manyToOneAnnot->targetEntity;
$mapping['fetch'] = $this->getFetchMode($className, $manyToOneAnnot->fetch);
$metadata->mapManyToOne($mapping);
} else {
if ($manyToManyAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\ManyToMany')) {
$joinTable = array();
if ($joinTableAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\JoinTable')) {
$joinTable = array('name' => $joinTableAnnot->name, 'schema' => $joinTableAnnot->schema);
foreach ($joinTableAnnot->joinColumns as $joinColumn) {
$joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumn);
}
foreach ($joinTableAnnot->inverseJoinColumns as $joinColumn) {
$joinTable['inverseJoinColumns'][] = $this->joinColumnToArray($joinColumn);
}
}
$mapping['joinTable'] = $joinTable;
$mapping['targetEntity'] = $manyToManyAnnot->targetEntity;
$mapping['mappedBy'] = $manyToManyAnnot->mappedBy;
$mapping['inversedBy'] = $manyToManyAnnot->inversedBy;
$mapping['cascade'] = $manyToManyAnnot->cascade;
$mapping['indexBy'] = $manyToManyAnnot->indexBy;
$mapping['orphanRemoval'] = $manyToManyAnnot->orphanRemoval;
$mapping['fetch'] = $this->getFetchMode($className, $manyToManyAnnot->fetch);
if ($orderByAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OrderBy')) {
$mapping['orderBy'] = $orderByAnnot->value;
}
$metadata->mapManyToMany($mapping);
} else {
if ($embeddedAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Embedded')) {
$mapping['class'] = $embeddedAnnot->class;
$mapping['columnPrefix'] = $embeddedAnnot->columnPrefix;
$metadata->mapEmbedded($mapping);
}
}
}
}
}
}
}
// Evaluate AssociationOverrides annotation
if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\AssociationOverrides'])) {
$associationOverridesAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\AssociationOverrides'];
foreach ($associationOverridesAnnot->value as $associationOverride) {
$override = array();
$fieldName = $associationOverride->name;
// Check for JoinColumn/JoinColumns annotations
if ($associationOverride->joinColumns) {
$joinColumns = array();
foreach ($associationOverride->joinColumns as $joinColumn) {
$joinColumns[] = $this->joinColumnToArray($joinColumn);
}
$override['joinColumns'] = $joinColumns;
}
// Check for JoinTable annotations
if ($associationOverride->joinTable) {
$joinTableAnnot = $associationOverride->joinTable;
$joinTable = array('name' => $joinTableAnnot->name, 'schema' => $joinTableAnnot->schema);
foreach ($joinTableAnnot->joinColumns as $joinColumn) {
$joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumn);
}
foreach ($joinTableAnnot->inverseJoinColumns as $joinColumn) {
$joinTable['inverseJoinColumns'][] = $this->joinColumnToArray($joinColumn);
}
$override['joinTable'] = $joinTable;
示例2: loadMetadataForClass
//.........这里部分代码省略.........
$metadata->setSequenceGeneratorDefinition($idElement['sequenceGenerator']);
} else {
if (isset($idElement['customIdGenerator'])) {
$customGenerator = $idElement['customIdGenerator'];
$metadata->setCustomGeneratorDefinition(array('class' => (string) $customGenerator['class']));
} else {
if (isset($idElement['tableGenerator'])) {
throw MappingException::tableIdGeneratorNotImplemented($className);
}
}
}
}
}
// Evaluate fields
if (isset($element['fields'])) {
foreach ($element['fields'] as $name => $fieldMapping) {
$mapping = $this->columnToArray($name, $fieldMapping);
if (isset($fieldMapping['id'])) {
$mapping['id'] = true;
if (isset($fieldMapping['generator']['strategy'])) {
$metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . strtoupper($fieldMapping['generator']['strategy'])));
}
}
if (isset($mapping['version'])) {
$metadata->setVersionMapping($mapping);
unset($mapping['version']);
}
$metadata->mapField($mapping);
}
}
if (isset($element['embedded'])) {
foreach ($element['embedded'] as $name => $embeddedMapping) {
$mapping = array('fieldName' => $name, 'class' => $embeddedMapping['class'], 'columnPrefix' => isset($embeddedMapping['columnPrefix']) ? $embeddedMapping['columnPrefix'] : null);
$metadata->mapEmbedded($mapping);
}
}
// Evaluate oneToOne relationships
if (isset($element['oneToOne'])) {
foreach ($element['oneToOne'] as $name => $oneToOneElement) {
$mapping = array('fieldName' => $name, 'targetEntity' => $oneToOneElement['targetEntity']);
if (isset($associationIds[$mapping['fieldName']])) {
$mapping['id'] = true;
}
if (isset($oneToOneElement['fetch'])) {
$mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . $oneToOneElement['fetch']);
}
if (isset($oneToOneElement['mappedBy'])) {
$mapping['mappedBy'] = $oneToOneElement['mappedBy'];
} else {
if (isset($oneToOneElement['inversedBy'])) {
$mapping['inversedBy'] = $oneToOneElement['inversedBy'];
}
$joinColumns = array();
if (isset($oneToOneElement['joinColumn'])) {
$joinColumns[] = $this->joinColumnToArray($oneToOneElement['joinColumn']);
} else {
if (isset($oneToOneElement['joinColumns'])) {
foreach ($oneToOneElement['joinColumns'] as $joinColumnName => $joinColumnElement) {
if (!isset($joinColumnElement['name'])) {
$joinColumnElement['name'] = $joinColumnName;
}
$joinColumns[] = $this->joinColumnToArray($joinColumnElement);
}
}
}
$mapping['joinColumns'] = $joinColumns;
示例3: loadMetadataForClass
//.........这里部分代码省略.........
$unique = array('columns' => explode(',', (string) $uniqueXml['columns']));
if (isset($uniqueXml->options)) {
$unique['options'] = $this->_parseOptions($uniqueXml->options->children());
}
if (isset($uniqueXml['name'])) {
$metadata->table['uniqueConstraints'][(string) $uniqueXml['name']] = $unique;
} else {
$metadata->table['uniqueConstraints'][] = $unique;
}
}
}
if (isset($xmlRoot->options)) {
$metadata->table['options'] = $this->_parseOptions($xmlRoot->options->children());
}
// The mapping assignment is done in 2 times as a bug might occurs on some php/xml lib versions
// The internal SimpleXmlIterator get resetted, to this generate a duplicate field exception
$mappings = array();
// Evaluate <field ...> mappings
if (isset($xmlRoot->field)) {
foreach ($xmlRoot->field as $fieldMapping) {
$mapping = $this->columnToArray($fieldMapping);
if (isset($mapping['version'])) {
$metadata->setVersionMapping($mapping);
unset($mapping['version']);
}
$metadata->mapField($mapping);
}
}
if (isset($xmlRoot->embedded)) {
foreach ($xmlRoot->embedded as $embeddedMapping) {
$columnPrefix = isset($embeddedMapping['column-prefix']) ? (string) $embeddedMapping['column-prefix'] : null;
$useColumnPrefix = isset($embeddedMapping['use-column-prefix']) ? $this->evaluateBoolean($embeddedMapping['use-column-prefix']) : true;
$mapping = array('fieldName' => (string) $embeddedMapping['name'], 'class' => (string) $embeddedMapping['class'], 'columnPrefix' => $useColumnPrefix ? $columnPrefix : false);
$metadata->mapEmbedded($mapping);
}
}
foreach ($mappings as $mapping) {
if (isset($mapping['version'])) {
$metadata->setVersionMapping($mapping);
}
$metadata->mapField($mapping);
}
// Evaluate <id ...> mappings
$associationIds = array();
foreach ($xmlRoot->id as $idElement) {
if (isset($idElement['association-key']) && $this->evaluateBoolean($idElement['association-key'])) {
$associationIds[(string) $idElement['name']] = true;
continue;
}
$mapping = array('id' => true, 'fieldName' => (string) $idElement['name']);
if (isset($idElement['type'])) {
$mapping['type'] = (string) $idElement['type'];
}
if (isset($idElement['length'])) {
$mapping['length'] = (string) $idElement['length'];
}
if (isset($idElement['column'])) {
$mapping['columnName'] = (string) $idElement['column'];
}
if (isset($idElement['column-definition'])) {
$mapping['columnDefinition'] = (string) $idElement['column-definition'];
}
if (isset($idElement->options)) {
$mapping['options'] = $this->_parseOptions($idElement->options->children());
}
$metadata->mapField($mapping);
示例4: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadata $class)
{
/** @var $class \Doctrine\ODM\CouchDB\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;
}
if ($element['type'] == 'document') {
$class->setCustomRepositoryClass(isset($element['repositoryClass']) ? $element['repositoryClass'] : null);
if (isset($element['indexed']) && $element['indexed'] == true) {
$class->indexed = true;
}
if (isset($element['inheritanceRoot']) && $element['inheritanceRoot']) {
$class->markInheritanceRoot();
}
} else {
if ($element['type'] == 'embedded') {
$class->isEmbeddedDocument = true;
if (isset($element['inheritanceRoot']) && $element['inheritanceRoot']) {
$class->markInheritanceRoot();
}
} else {
if (strtolower($element['type']) == "mappedsuperclass") {
$class->isMappedSuperclass = true;
} else {
throw MappingException::classIsNotAValidDocument($className);
}
}
}
if (isset($element['id'])) {
foreach ($element['id'] as $fieldName => $idElement) {
$class->mapField(array('fieldName' => $fieldName, 'indexed' => isset($idElement['index']) ? (bool) $idElement['index'] : false, 'type' => isset($idElement['type']) ? $idElement['type'] : null, 'id' => true, 'strategy' => isset($idElement['strategy']) ? $idElement['strategy'] : null));
}
}
if (isset($element['fields'])) {
foreach ($element['fields'] as $fieldName => $fieldElement) {
$class->mapField(array('fieldName' => $fieldName, 'jsonName' => isset($fieldElement['jsonName']) ? $fieldElement['jsonName'] : null, 'indexed' => isset($fieldElement['index']) ? (bool) $fieldElement['index'] : false, 'type' => isset($fieldElement['type']) ? $fieldElement['type'] : null, 'isVersionField' => isset($fieldElement['version']) ? true : null));
}
}
if (isset($element['referenceOne'])) {
foreach ($element['referenceOne'] as $field => $referenceOneElement) {
$class->mapManyToOne(array('cascade' => isset($referenceOneElement['cascade']) ? $this->getCascadeMode($referenceOneElement['cascade']) : 0, 'targetDocument' => (string) $referenceOneElement['targetDocument'], 'fieldName' => $field, 'jsonName' => isset($referenceOneElement['jsonName']) ? (string) $referenceOneElement['jsonName'] : null, 'indexed' => isset($referenceOneElement['index']) ? (bool) $referenceOneElement['index'] : false));
}
}
if (isset($element['referenceMany'])) {
foreach ($element['referenceMany'] as $field => $referenceManyElement) {
$class->mapManyToMany(array('cascade' => isset($referenceManyElement['cascade']) ? $this->getCascadeMode($referenceManyElement['cascade']) : 0, 'targetDocument' => (string) $referenceManyElement['targetDocument'], 'fieldName' => $field, 'jsonName' => isset($referenceManyElement['jsonName']) ? (string) $referenceManyElement['jsonName'] : null, 'mappedBy' => isset($referenceManyElement['mappedBy']) ? (string) $referenceManyElement['mappedBy'] : null));
}
}
if (isset($element['attachments'])) {
$class->mapAttachments($element['attachments']);
}
if (isset($element['embedOne'])) {
foreach ($element['embedOne'] as $field => $embedOneElement) {
$class->mapEmbedded(array('targetDocument' => (string) $embedOneElement['targetDocument'], 'fieldName' => $field, 'jsonName' => isset($embedOneElement['jsonName']) ? (string) $embedOneElement['jsonName'] : null, 'embedded' => 'one'));
}
}
if (isset($element['embedMany'])) {
foreach ($element['embedMany'] as $field => $embedManyElement) {
$class->mapEmbedded(array('targetDocument' => (string) $embedManyElement['targetDocument'], 'fieldName' => $field, 'jsonName' => isset($embedManyElement['jsonName']) ? (string) $embedManyElement['jsonName'] : null, 'embedded' => 'many'));
}
}
}
示例5: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadata $class)
{
$reflClass = $class->getReflectionClass();
$isValidDocument = false;
$classAnnotations = $this->reader->getClassAnnotations($reflClass);
foreach ($classAnnotations as $classAnnotation) {
if ($classAnnotation instanceof ODM\Document) {
if ($classAnnotation->indexed) {
$class->indexed = true;
}
$class->setCustomRepositoryClass($classAnnotation->repositoryClass);
$isValidDocument = true;
} elseif ($classAnnotation instanceof ODM\EmbeddedDocument) {
$class->isEmbeddedDocument = true;
$isValidDocument = true;
} else {
if ($classAnnotation instanceof ODM\MappedSuperclass) {
$class->isMappedSuperclass = true;
$isValidDocument = true;
} else {
if ($classAnnotation instanceof ODM\Index) {
$class->indexed = true;
} else {
if ($classAnnotation instanceof ODM\InheritanceRoot) {
$class->markInheritanceRoot();
}
}
}
}
}
if (!$isValidDocument) {
throw MappingException::classIsNotAValidDocument($className);
}
foreach ($reflClass->getProperties() as $property) {
if ($class->isInheritedAssociation($property->name) || $class->isInheritedField($property->name)) {
continue;
}
$mapping = array();
$mapping['fieldName'] = $property->name;
if ($this->reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\CouchDB\\Mapping\\Annotations\\Index')) {
$mapping['indexed'] = true;
}
foreach ($this->reader->getPropertyAnnotations($property) as $fieldAnnot) {
if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\Field) {
if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\Version) {
$mapping['isVersionField'] = true;
}
$mapping = array_merge($mapping, (array) $fieldAnnot);
unset($mapping['value']);
$class->mapField($mapping);
} else {
if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\ReferenceOne) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
unset($mapping['value']);
$class->mapManyToOne($mapping);
} else {
if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\ReferenceMany) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
unset($mapping['value']);
$class->mapManyToMany($mapping);
} else {
if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\Attachments) {
$class->mapAttachments($mapping['fieldName']);
} else {
if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\EmbedOne || $fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\EmbedMany) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
unset($mapping['value']);
$class->mapEmbedded($mapping);
}
}
}
}
}
}
}
}
示例6: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadata $class)
{
/** @var $class \Doctrine\ODM\CouchDB\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 ($xmlRoot->getName() == 'document') {
$class->setCustomRepositoryClass(isset($xmlRoot['repository-class']) ? (string) $xmlRoot['repository-class'] : null);
if (isset($xmlRoot['indexed']) && $xmlRoot['indexed'] == true) {
$class->indexed = true;
}
if (isset($xmlRoot['inheritance-root']) && $xmlRoot['inheritance-root']) {
$class->markInheritanceRoot();
}
} else {
if ($xmlRoot->getName() == "embedded-document") {
$class->isEmbeddedDocument = true;
if (isset($xmlRoot['inheritance-root']) && $xmlRoot['inheritance-root']) {
$class->markInheritanceRoot();
}
} else {
if ($xmlRoot->getName() == "mapped-superclass") {
$class->isMappedSuperclass = true;
} else {
throw MappingException::classIsNotAValidDocument($className);
}
}
}
// Evaluate <field ...> mappings
if (isset($xmlRoot->field)) {
foreach ($xmlRoot->field as $fieldMapping) {
$class->mapField(array('fieldName' => (string) $fieldMapping['name'], 'jsonName' => isset($fieldMapping['json-name']) ? (string) $fieldMapping['json-name'] : null, 'indexed' => isset($fieldMapping['index']) ? (bool) $fieldMapping['index'] : false, 'type' => isset($fieldMapping['type']) ? (string) $fieldMapping['type'] : null, 'isVersionField' => isset($fieldMapping['version']) ? true : null));
}
}
// Evaluate <id ..> mappings
foreach ($xmlRoot->id as $idElement) {
$class->mapField(array('fieldName' => (string) $idElement['name'], 'indexed' => isset($idElement['index']) ? (bool) $idElement['index'] : false, 'type' => isset($idElement['type']) ? (string) $idElement['type'] : null, 'id' => true, 'strategy' => isset($idElement['strategy']) ? (string) $idElement['strategy'] : null));
}
// Evaluate <version ..> mappings
foreach ($xmlRoot->version as $versionElement) {
$class->mapField(array('fieldName' => (string) $versionElement['name'], 'type' => 'string', 'isVersionField' => true, 'jsonName' => '_rev'));
}
// Evaluate <many-to-one ..> mappings
if (isset($xmlRoot->{"reference-one"})) {
foreach ($xmlRoot->{"reference-one"} as $referenceOneElement) {
$class->mapManyToOne(array('cascade' => isset($referenceOneElement->cascade) ? $this->getCascadeMode($referenceOneElement->cascade) : 0, 'targetDocument' => (string) $referenceOneElement['target-document'], 'fieldName' => (string) $referenceOneElement['field'], 'jsonName' => isset($referenceOneElement['json-name']) ? (string) $referenceOneElement['json-name'] : null, 'indexed' => isset($referenceOneElement['index']) ? (bool) $referenceOneElement['index'] : false));
}
}
// Evaluate <many-to-one ..> mappings
if (isset($xmlRoot->{"reference-many"})) {
foreach ($xmlRoot->{"reference-many"} as $referenceManyElement) {
$class->mapManyToMany(array('cascade' => isset($referenceManyElement->cascade) ? $this->getCascadeMode($referenceManyElement->cascade) : 0, 'targetDocument' => (string) $referenceManyElement['target-document'], 'fieldName' => (string) $referenceManyElement['field'], 'jsonName' => isset($referenceManyElement['json-name']) ? (string) $referenceManyElement['json-name'] : null, 'mappedBy' => isset($referenceManyElement['mapped-by']) ? (string) $referenceManyElement['mapped-by'] : null));
}
}
// Evaluate <attachments ..> mapping
if (isset($xmlRoot->{"attachments"})) {
$class->mapAttachments((string) $xmlRoot->{"attachments"}[0]['field']);
}
// Evaluate <embed-one />
if (isset($xmlRoot->{'embed-one'})) {
foreach ($xmlRoot->{'embed-one'} as $embedOneElement) {
$class->mapEmbedded(array('targetDocument' => (string) $embedOneElement['target-document'], 'fieldName' => (string) $embedOneElement['field'], 'jsonName' => isset($embedOneElement['json-name']) ? (string) $embedOneElement['json-name'] : null, 'embedded' => 'one'));
}
}
// Evaluate <embed-many />
if (isset($xmlRoot->{'embed-many'})) {
foreach ($xmlRoot->{'embed-many'} as $embedManyElement) {
$class->mapEmbedded(array('targetDocument' => (string) $embedManyElement['target-document'], 'fieldName' => (string) $embedManyElement['field'], 'jsonName' => isset($embedManyElement['json-name']) ? (string) $embedManyElement['json-name'] : null, 'embedded' => 'many'));
}
}
}