本文整理汇总了PHP中Doctrine\Common\Persistence\Mapping\ClassMetadata::mapManyToOne方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::mapManyToOne方法的具体用法?PHP ClassMetadata::mapManyToOne怎么用?PHP ClassMetadata::mapManyToOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Persistence\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::mapManyToOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mapTranslation
/**
* {@inheritDoc}
*/
public function mapTranslation(ClassMetadata $meta, $translatableClassName)
{
$rc = $meta->getReflectionClass();
if (!$rc->hasProperty('object') || $meta->hasAssociation('object') || !$rc->isSubclassOf($this->personalTranslation)) {
return;
}
$namingStrategy = $this->getObjectManager()->getConfiguration()->getNamingStrategy();
$meta->mapManyToOne(['targetEntity' => $translatableClassName, 'fieldName' => 'object', 'inversedBy' => 'translations', 'isOwningSide' => true, 'joinColumns' => [['name' => $namingStrategy->joinColumnName('object'), 'referencedColumnName' => $namingStrategy->referenceColumnName(), 'onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']]]);
}
示例2: testLoadClassMetadata
public function testLoadClassMetadata()
{
$this->loadClassMetadataEvent->getClassMetadata()->willReturn($this->classMetadata->reveal());
$this->classMetadata->getReflectionClass()->willReturn($this->refl->reveal());
$this->refl->implementsInterface('Sulu\\Component\\Persistence\\Model\\UserBlameInterface')->willReturn(true);
$this->classMetadata->hasAssociation('creator')->shouldBeCalled();
$this->classMetadata->hasAssociation('changer')->shouldBeCalled();
$this->classMetadata->mapManyToOne(Argument::any())->shouldBeCalled();
$this->subscriber->loadClassMetadata($this->loadClassMetadataEvent->reveal());
}
示例3: mapManyToMany
private function mapManyToMany(ClassMetadata $metadata)
{
foreach ($this->variables as $variable => $class) {
if ($class['variant']['model'] !== $metadata->getName()) {
continue;
}
$metadata->mapManyToOne(array('fieldName' => 'object', 'targetEntity' => $class['variable'], 'inversedBy' => 'variants', 'joinColumns' => array(array('name' => $variable . '_id', 'referencedColumnName' => 'id', 'nullable' => false, 'onDelete' => 'CASCADE'))));
$metadata->mapManyToMany(array('fieldName' => 'options', 'type' => ClassMetadataInfo::MANY_TO_MANY, 'targetEntity' => $class['option_value']['model'], 'joinTable' => array('name' => sprintf('sylius_%s_variant_option_value', $variable), 'joinColumns' => array(array('name' => 'variant_id', 'referencedColumnName' => 'id', 'unique' => false, 'nullable' => false, 'onDelete' => 'CASCADE')), 'inverseJoinColumns' => array(array('name' => 'option_value_id', 'referencedColumnName' => 'id', 'unique' => false, 'nullable' => false, 'onDelete' => 'CASCADE')))));
}
}
示例4: mapHierarchy
/**
* {@inheritDoc}
*/
public function mapHierarchy(ClassMetadata $meta)
{
if ($meta->isMappedSuperclass || !$meta->isRootEntity()) {
return;
}
$rc = $meta->getReflectionClass();
if ($rc->hasProperty('parent') && !$meta->hasAssociation('parent')) {
$meta->mapManyToOne(['targetEntity' => $meta->getName(), 'fieldName' => 'parent', 'inversedBy' => 'children', 'cascade' => ['persist']]);
}
if ($rc->hasProperty('children') && !$meta->hasAssociation('children')) {
$meta->mapOneToMany(['targetEntity' => $meta->getName(), 'fieldName' => 'children', 'mappedBy' => 'parent', 'cascade' => ['persist', 'remove'], 'fetch' => 'EXTRA_LAZY']);
}
}
示例5: loadMetadataForClass
/**
* Loads the metadata for the specified class into the provided container.
*
* @param string $className
* @param ClassMetadata $metadata
*
* @return void
*/
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
$originClassName = $className;
$originMetadata = $this->em->getClassMetadata('Opifer\\ContentBundle\\Entity\\ListBlock');
//
// $metadata->name = self::REVISION_ENTITY; //. '' . str_replace('\\', '', $class->name);
// $class->rootEntityName = $class->name;
// $class->namespace = 'Opifer\\Revisions\\Entity';
//
// $class->discriminatorMap = null;
// $class->discriminatorColumn = null;
$metadata->setPrimaryTable(['name' => $originMetadata->getTableName() . '_revisions']);
foreach ($originMetadata->fieldMappings as $key => $fieldMapping) {
$fieldMapping['inherited'] = self::REVISION_ENTITY;
$fieldMapping['declared'] = self::REVISION_ENTITY;
if ($this->annotationReader->isPropertyRevised($originClassName, $fieldMapping['fieldName'])) {
$metadata->mapField($fieldMapping);
}
}
foreach ($originMetadata->associationMappings as $key => $associationMapping) {
$associationMapping['inherited'] = self::REVISION_ENTITY;
$associationMapping['declared'] = self::REVISION_ENTITY;
if ($this->annotationReader->isPropertyRevised($originClassName, $associationMapping['fieldName'])) {
if ($associationMapping['type'] == ClassMetadataInfo::ONE_TO_ONE) {
$metadata->mapOneToOne($associationMapping);
} else {
if ($associationMapping['type'] == ClassMetadataInfo::MANY_TO_ONE) {
$metadata->mapManyToOne($associationMapping);
} else {
if ($associationMapping['type'] == ClassMetadataInfo::ONE_TO_MANY) {
$metadata->mapOneToMany($associationMapping);
} else {
if ($associationMapping['type'] == ClassMetadataInfo::MANY_TO_MANY) {
$metadata->mapManyToMany($associationMapping);
}
}
}
}
}
}
}
示例6: loadMetadataForClass
//.........这里部分代码省略.........
if ($idAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Id')) {
$mapping['id'] = true;
}
$mapping['targetEntity'] = $oneToOneAnnot->targetEntity;
$mapping['joinColumns'] = $joinColumns;
$mapping['mappedBy'] = $oneToOneAnnot->mappedBy;
$mapping['inversedBy'] = $oneToOneAnnot->inversedBy;
$mapping['cascade'] = $oneToOneAnnot->cascade;
$mapping['orphanRemoval'] = $oneToOneAnnot->orphanRemoval;
$mapping['fetch'] = $this->getFetchMode($className, $oneToOneAnnot->fetch);
$metadata->mapOneToOne($mapping);
} else {
if ($oneToManyAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OneToMany')) {
$mapping['mappedBy'] = $oneToManyAnnot->mappedBy;
$mapping['targetEntity'] = $oneToManyAnnot->targetEntity;
$mapping['cascade'] = $oneToManyAnnot->cascade;
$mapping['indexBy'] = $oneToManyAnnot->indexBy;
$mapping['orphanRemoval'] = $oneToManyAnnot->orphanRemoval;
$mapping['fetch'] = $this->getFetchMode($className, $oneToManyAnnot->fetch);
if ($orderByAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OrderBy')) {
$mapping['orderBy'] = $orderByAnnot->value;
}
$metadata->mapOneToMany($mapping);
} else {
if ($manyToOneAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\ManyToOne')) {
if ($idAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Id')) {
$mapping['id'] = true;
}
$mapping['joinColumns'] = $joinColumns;
$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);
}
}
}
示例7: loadMetadataForClass
//.........这里部分代码省略.........
}
}
}
// Evaluate manyToOne relationships
if (isset($element['manyToOne'])) {
foreach ($element['manyToOne'] as $name => $manyToOneElement) {
$mapping = array('fieldName' => $name, 'targetEntity' => $manyToOneElement['targetEntity']);
if (isset($associationIds[$mapping['fieldName']])) {
$mapping['id'] = true;
}
if (isset($manyToOneElement['fetch'])) {
$mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . $manyToOneElement['fetch']);
}
if (isset($manyToOneElement['inversedBy'])) {
$mapping['inversedBy'] = $manyToOneElement['inversedBy'];
}
$joinColumns = array();
if (isset($manyToOneElement['joinColumn'])) {
$joinColumns[] = $this->joinColumnToArray($manyToOneElement['joinColumn']);
} else {
if (isset($manyToOneElement['joinColumns'])) {
foreach ($manyToOneElement['joinColumns'] as $joinColumnName => $joinColumnElement) {
if (!isset($joinColumnElement['name'])) {
$joinColumnElement['name'] = $joinColumnName;
}
$joinColumns[] = $this->joinColumnToArray($joinColumnElement);
}
}
}
$mapping['joinColumns'] = $joinColumns;
if (isset($manyToOneElement['cascade'])) {
$mapping['cascade'] = $manyToOneElement['cascade'];
}
$metadata->mapManyToOne($mapping);
// Evaluate second level cache
if (isset($manyToOneElement['cache'])) {
$metadata->enableAssociationCache($mapping['fieldName'], $this->cacheToArray($manyToOneElement['cache']));
}
}
}
// Evaluate manyToMany relationships
if (isset($element['manyToMany'])) {
foreach ($element['manyToMany'] as $name => $manyToManyElement) {
$mapping = array('fieldName' => $name, 'targetEntity' => $manyToManyElement['targetEntity']);
if (isset($manyToManyElement['fetch'])) {
$mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . $manyToManyElement['fetch']);
}
if (isset($manyToManyElement['mappedBy'])) {
$mapping['mappedBy'] = $manyToManyElement['mappedBy'];
} else {
if (isset($manyToManyElement['joinTable'])) {
$joinTableElement = $manyToManyElement['joinTable'];
$joinTable = array('name' => $joinTableElement['name']);
if (isset($joinTableElement['schema'])) {
$joinTable['schema'] = $joinTableElement['schema'];
}
if (isset($joinTableElement['joinColumns'])) {
foreach ($joinTableElement['joinColumns'] as $joinColumnName => $joinColumnElement) {
if (!isset($joinColumnElement['name'])) {
$joinColumnElement['name'] = $joinColumnName;
}
}
$joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumnElement);
}
if (isset($joinTableElement['inverseJoinColumns'])) {
foreach ($joinTableElement['inverseJoinColumns'] as $joinColumnName => $joinColumnElement) {
示例8: mapManyToMany
/**
* @param ClassMetadata $metadata
* @param LoadClassMetadataEventArgs $eventArgs
*/
private function mapManyToMany(ClassMetadata $metadata, LoadClassMetadataEventArgs $eventArgs)
{
$cmf = $eventArgs->getEntityManager()->getMetadataFactory();
foreach ($this->variables as $variable => $class) {
if ($class['variant']['model'] !== $metadata->getName()) {
continue;
}
$targetEntity = $class['variable'];
$targetEntityMetadata = $cmf->getMetadataFor($targetEntity);
$metadata->mapManyToOne(array('fieldName' => 'object', 'targetEntity' => $class['variable'], 'inversedBy' => 'variants', 'joinColumns' => array(array('name' => $variable . '_id', 'referencedColumnName' => $targetEntityMetadata->fieldMappings['id']['columnName'], 'nullable' => false, 'onDelete' => 'CASCADE'))));
$targetEntity = $class['option_value']['model'];
$targetEntityMetadata = $cmf->getMetadataFor($targetEntity);
$metadata->mapManyToMany(array('fieldName' => 'options', 'type' => ClassMetadataInfo::MANY_TO_MANY, 'targetEntity' => $class['option_value']['model'], 'joinTable' => array('name' => sprintf('sylius_%s_variant_option_value', $variable), 'joinColumns' => array(array('name' => 'variant_id', 'referencedColumnName' => 'id', 'unique' => false, 'nullable' => false, 'onDelete' => 'CASCADE')), 'inverseJoinColumns' => array(array('name' => 'option_value_id', 'referencedColumnName' => $targetEntityMetadata->fieldMappings['id']['columnName'], 'unique' => false, 'nullable' => false, 'onDelete' => 'CASCADE')))));
}
}
示例9: 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);
//.........这里部分代码省略.........
示例10: addMappingFromReference
private function addMappingFromReference(ClassMetadata $class, $fieldName, $reference, $type)
{
/** @var $class \Doctrine\ODM\PHPCR\Mapping\ClassMetadata */
$mapping = array_merge(array('fieldName' => $fieldName), $reference);
$mapping['cascade'] = isset($reference['cascade']) ? $this->getCascadeMode($reference['cascade']) : 0;
$mapping['name'] = isset($reference['name']) ? $reference['name'] : null;
if (!isset($mapping['targetDocument'])) {
$mapping['targetDocument'] = null;
}
if ($type === 'many') {
$class->mapManyToMany($mapping);
} elseif ($type === 'one') {
$class->mapManyToOne($mapping);
}
}
示例11: loadMetadataForClass
//.........这里部分代码省略.........
foreach ($ids as $id) {
$metadata->mapField($id);
}
}
foreach ($fieldMappings as $fieldMapping) {
$metadata->mapField($fieldMapping);
}
foreach ($this->manyToManyTables as $manyTable) {
foreach ($manyTable->getForeignKeys() as $foreignKey) {
// foreign key maps to the table of the current entity, many to many association probably exists
if (strtolower($tableName) == strtolower($foreignKey->getForeignTableName())) {
$myFk = $foreignKey;
$otherFk = null;
foreach ($manyTable->getForeignKeys() as $foreignKey) {
if ($foreignKey != $myFk) {
$otherFk = $foreignKey;
break;
}
}
if (!$otherFk) {
// the definition of this many to many table does not contain
// enough foreign key information to continue reverse engineering.
continue;
}
$localColumn = current($myFk->getColumns());
$associationMapping = array();
$associationMapping['fieldName'] = $this->getFieldNameForColumn($manyTable->getName(), current($otherFk->getColumns()), true);
$associationMapping['targetEntity'] = $this->getClassNameForTable($otherFk->getForeignTableName());
if (current($manyTable->getColumns())->getName() == $localColumn) {
$associationMapping['inversedBy'] = $this->getFieldNameForColumn($manyTable->getName(), current($myFk->getColumns()), true);
$associationMapping['joinTable'] = array(
'name' => strtolower($manyTable->getName()),
'joinColumns' => array(),
'inverseJoinColumns' => array(),
);
$fkCols = $myFk->getForeignColumns();
$cols = $myFk->getColumns();
for ($i = 0; $i < count($cols); $i++) {
$associationMapping['joinTable']['joinColumns'][] = array(
'name' => $cols[$i],
'referencedColumnName' => $fkCols[$i],
);
}
$fkCols = $otherFk->getForeignColumns();
$cols = $otherFk->getColumns();
for ($i = 0; $i < count($cols); $i++) {
$associationMapping['joinTable']['inverseJoinColumns'][] = array(
'name' => $cols[$i],
'referencedColumnName' => $fkCols[$i],
);
}
} else {
$associationMapping['mappedBy'] = $this->getFieldNameForColumn($manyTable->getName(), current($myFk->getColumns()), true);
}
$metadata->mapManyToMany($associationMapping);
break;
}
}
}
foreach ($foreignKeys as $foreignKey) {
$foreignTable = $foreignKey->getForeignTableName();
$cols = $foreignKey->getColumns();
$fkCols = $foreignKey->getForeignColumns();
$localColumn = current($cols);
$associationMapping = array();
$associationMapping['fieldName'] = $this->getFieldNameForColumn($tableName, $localColumn, true);
$associationMapping['targetEntity'] = $this->getClassNameForTable($foreignTable);
if (isset($metadata->fieldMappings[$associationMapping['fieldName']])) {
$associationMapping['fieldName'] = $associationMapping['fieldName'] . "2";
}
if ($primaryKeyColumns && in_array($localColumn, $primaryKeyColumns)) {
$associationMapping['id'] = true;
}
for ($i = 0; $i < count($cols); $i++) {
$associationMapping['joinColumns'][] = array(
'name' => $cols[$i],
'referencedColumnName' => $fkCols[$i],
);
}
//Here we need to check if $cols are the same as $primaryKeyColumns
if (!array_diff($cols,$primaryKeyColumns)) {
$metadata->mapOneToOne($associationMapping);
} else {
$metadata->mapManyToOne($associationMapping);
}
}
}
示例12: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
$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 (isset($documentAnnot->versionable) && $documentAnnot->versionable) {
$metadata->setVersioned($documentAnnot->versionable);
}
$metadata->setNodeType($documentAnnot->nodeType);
if (isset($documentAnnot->referenceable) && $documentAnnot->referenceable) {
$metadata->setReferenceable(true);
}
if ($documentAnnot->repositoryClass) {
$metadata->setCustomRepositoryClassName($documentAnnot->repositoryClass);
}
if ($documentAnnot->translator) {
$metadata->setTranslator($documentAnnot->translator);
}
foreach ($reflClass->getProperties() as $property) {
if ($metadata->isMappedSuperclass && !$property->isPrivate() || $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);
$metadata->mapParentDocument($mapping);
} elseif ($fieldAnnot instanceof ODM\Child) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapChild($mapping);
} elseif ($fieldAnnot instanceof ODM\Children) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapChildren($mapping);
} elseif ($fieldAnnot instanceof ODM\ReferenceOne) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapManyToOne($mapping);
} elseif ($fieldAnnot instanceof ODM\ReferenceMany) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapManyToMany($mapping);
} elseif ($fieldAnnot instanceof ODM\Referrers) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapReferrers($mapping);
} elseif ($fieldAnnot instanceof ODM\Locale) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapLocale($mapping);
} elseif ($fieldAnnot instanceof ODM\VersionName) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapVersionName($mapping);
} elseif ($fieldAnnot instanceof ODM\VersionCreated) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
$metadata->mapVersionCreated($mapping);
}
if (!isset($mapping['name'])) {
$mapping['name'] = $property->getName();
}
}
}
foreach ($reflClass->getMethods() as $method) {
if ($method->isPublic() && $method->getDeclaringClass()->getName() == $metadata->name) {
foreach ($this->reader->getMethodAnnotations($method) as $annot) {
if ($annot instanceof ODM\PrePersist) {
$metadata->addLifecycleCallback($method->getName(), Event::prePersist);
} elseif ($annot instanceof ODM\PostPersist) {
$metadata->addLifecycleCallback($method->getName(), Event::postPersist);
} elseif ($annot instanceof ODM\PreUpdate) {
$metadata->addLifecycleCallback($method->getName(), Event::preUpdate);
} elseif ($annot instanceof ODM\PostUpdate) {
$metadata->addLifecycleCallback($method->getName(), Event::postUpdate);
} elseif ($annot instanceof ODM\PreRemove) {
$metadata->addLifecycleCallback($method->getName(), Event::preRemove);
} elseif ($annot instanceof ODM\PostRemove) {
$metadata->addLifecycleCallback($method->getName(), Event::postRemove);
//.........这里部分代码省略.........
示例13: loadMetadataForClass
/**
* Loads the metadata for the specified class into the provided container.
*
* @param string $className
* @param \Doctrine\ORM\Mapping\ClassMetadata $metadata
*/
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
global $container;
$builder = new ClassMetadataBuilder($metadata);
$tableName = static::classToTableName($className);
$this->loadDataContainer($tableName);
try {
/** @var ClassLoader $entitiesClassLoader */
$entitiesClassLoader = $container['doctrine.orm.entitiesClassLoader'];
if (!class_exists($className, false)) {
$entitiesClassLoader->loadClass($className);
}
if (class_exists($className, false)) {
$class = new \ReflectionClass($className);
} else {
$class = false;
}
} catch (\Exception $e) {
$class = false;
}
if (!array_key_exists('TL_DCA', $GLOBALS)) {
$GLOBALS['TL_DCA'] = array();
}
if (!array_key_exists($tableName, $GLOBALS['TL_DCA']) || !is_array($GLOBALS['TL_DCA'][$tableName])) {
$GLOBALS['TL_DCA'][$tableName] = array('fields' => array());
}
$entityConfig = array();
if (array_key_exists('entity', $GLOBALS['TL_DCA'][$tableName])) {
$entityConfig = $GLOBALS['TL_DCA'][$tableName]['entity'];
}
if ($class && !$class->isInstantiable()) {
$metadata->isMappedSuperclass = true;
} elseif (array_key_exists('isMappedSuperclass', $entityConfig)) {
$metadata->isMappedSuperclass = $entityConfig['isMappedSuperclass'];
}
// custom repository class
if (array_key_exists('repositoryClass', $entityConfig)) {
$metadata->setCustomRepositoryClass($entityConfig['repositoryClass']);
} else {
$metadata->setCustomRepositoryClass('Contao\\Doctrine\\ORM\\Repository');
}
// id generator
if (array_key_exists('idGenerator', $entityConfig)) {
$metadata->setIdGeneratorType($entityConfig['idGenerator']);
} else {
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
}
// indexes
if (isset($entityConfig['indexes'])) {
if (is_array($entityConfig['indexes'])) {
foreach ($entityConfig['indexes'] as $name => $columns) {
if (is_array($columns)) {
$builder->addIndex($columns, $name);
} else {
throw new \RuntimeException(sprintf('$GLOBALS[TL_DCA][%s][entity][indexes][%s] must be an array', $tableName, $name));
}
}
} else {
throw new \RuntimeException(sprintf('$GLOBALS[TL_DCA][%s][entity][indexes] must be an array', $tableName));
}
}
// uniques
if (isset($entityConfig['uniques'])) {
if (is_array($entityConfig['uniques'])) {
foreach ($entityConfig['uniques'] as $name => $columns) {
if (is_array($columns)) {
$builder->addUniqueConstraint($columns, $name);
} else {
throw new \RuntimeException(sprintf('$GLOBALS[TL_DCA][%s][entity][uniques][%s] must be an array', $tableName, $name));
}
}
} else {
throw new \RuntimeException(sprintf('$GLOBALS[TL_DCA][%s][entity][uniques] must be an array', $tableName));
}
}
$metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE);
$metadata->setPrimaryTable(array('name' => $tableName));
$fields = (array) $GLOBALS['TL_DCA'][$tableName]['fields'];
foreach ($fields as $fieldName => $fieldConfig) {
$configured = array_key_exists('field', $fieldConfig) || array_key_exists('oneToOne', $fieldConfig) || array_key_exists('oneToMany', $fieldConfig) || array_key_exists('manyToOne', $fieldConfig) || array_key_exists('manyToMany', $fieldConfig);
if (!$configured && empty($fieldConfig['inputType']) || $configured && $fieldConfig['field'] === false) {
continue;
}
if (isset($fieldConfig['oneToOne'])) {
$fieldConfig['oneToOne']['fieldName'] = $fieldName;
$metadata->mapOneToOne($fieldConfig['oneToOne']);
} elseif (isset($fieldConfig['oneToMany'])) {
$fieldConfig['oneToMany']['fieldName'] = $fieldName;
$metadata->mapOneToMany($fieldConfig['oneToMany']);
} elseif (isset($fieldConfig['manyToOne'])) {
$fieldConfig['manyToOne']['fieldName'] = $fieldName;
$metadata->mapManyToOne($fieldConfig['manyToOne']);
} elseif (isset($fieldConfig['manyToMany'])) {
$fieldConfig['manyToMany']['fieldName'] = $fieldName;
//.........这里部分代码省略.........
示例14: 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);
}
}
}
}
}
}
}
}
示例15: addReferenceMapping
private function addReferenceMapping(ClassMetadata $class, $reference, $type)
{
/** @var $class \Doctrine\ODM\PHPCR\Mapping\ClassMetadata */
$attributes = (array) $reference->attributes();
$mapping = $attributes["@attributes"];
$mapping['strategy'] = isset($mapping['strategy']) ? strtolower($mapping['strategy']) : null;
$mapping['targetDocument'] = isset($mapping['target-document']) ? $mapping['target-document'] : null;
unset($mapping['target-document']);
if ($type === 'many') {
$class->mapManyToMany($mapping);
} elseif ($type === 'one') {
$class->mapManyToOne($mapping);
}
}