本文整理汇总了PHP中Doctrine\ORM\Mapping\ClassMetadataInfo::mapOneToOne方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadataInfo::mapOneToOne方法的具体用法?PHP ClassMetadataInfo::mapOneToOne怎么用?PHP ClassMetadataInfo::mapOneToOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Mapping\ClassMetadataInfo
的用法示例。
在下文中一共展示了ClassMetadataInfo::mapOneToOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUpBeforeClass
static public function setUpBeforeClass()
{
$metadata = new ClassMetadataInfo('Propel\\Tests\\Builder\\ORM\\Book');
$metadata->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
$metadata->mapField(array('fieldName' => 'name', 'type' => 'string', 'columnName' => 'foo_name', 'length' => 25, 'nullable' => true, 'columnDefinition' => 'Hello world'));
$metadata->mapField(array('fieldName' => 'status', 'type' => 'integer', 'default' => 23, 'precision' => 2, 'scale' => 2, 'unique' => 'unique_status'));
$metadata->mapOneToOne(array(
'fieldName' => 'author',
'targetEntity' => 'Doctrine\Tests\ORM\Tools\EntityGeneratorAuthor',
'mappedBy' => 'book',
'joinColumns' => array(
array('name' => 'author_id', 'referencedColumnName' => 'id')
),
));
$metadata->mapManyToMany(array(
'fieldName' => 'comments',
'targetEntity' => 'Doctrine\Tests\ORM\Tools\EntityGeneratorComment',
'joinTable' => array(
'name' => 'book_comment',
'joinColumns' => array(array('name' => 'book_id', 'referencedColumnName' => 'id')),
'inverseJoinColumns' => array(array('name' => 'comment_id', 'referencedColumnName' => 'id')),
),
));
$builder = new BaseActiveRecord($metadata);
eval('?>' . $builder->getCode());
}
示例2: ClassMetadataInfo
function it_configures_the_mappings_of_an_original_model_that_is_override($configuration)
{
$metadataInfo = new ClassMetadataInfo('Foo\\Bar\\OriginalQux');
$metadataInfo->mapManyToMany(['fieldName' => 'relation1', 'targetEntity' => 'Foo']);
$metadataInfo->mapManyToOne(['fieldName' => 'relation2', 'targetEntity' => 'Foo']);
$metadataInfo->mapOneToMany(['fieldName' => 'relation3', 'targetEntity' => 'Foo', 'mappedBy' => 'baz']);
$metadataInfo->mapOneToOne(['fieldName' => 'relation4', 'targetEntity' => 'Foo']);
$overrides = [['original' => 'Foo\\Bar\\OriginalQux', 'override' => 'Acme\\Bar\\OverrideQux'], ['original' => 'Foo\\Baz\\OriginalQux', 'override' => 'Acme\\Baz\\OverrideQux']];
$this->configure($metadataInfo, $overrides, $configuration)->shouldBeAnOverrideModel();
}
示例3: testWriteEntityClass
public function testWriteEntityClass()
{
$metadata = new ClassMetadataInfo('EntityGeneratorBook');
$metadata->primaryTable['name'] = 'book';
$metadata->mapField(array('fieldName' => 'name', 'type' => 'string'));
$metadata->mapField(array('fieldName' => 'status', 'type' => 'string', 'default' => 'published'));
$metadata->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
$metadata->mapOneToOne(array('fieldName' => 'author', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Tools\\EntityGeneratorAuthor', 'mappedBy' => 'book'));
$joinColumns = array(array('name' => 'author_id', 'referencedColumnName' => 'id'));
$metadata->mapManyToMany(array('fieldName' => 'comments', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Tools\\EntityGeneratorComment', 'joinTable' => array('name' => 'book_comment', 'joinColumns' => array(array('name' => 'book_id', 'referencedColumnName' => 'id')), 'inverseJoinColumns' => array(array('name' => 'comment_id', 'referencedColumnName' => 'id')))));
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
$this->_generator->writeEntityClass($metadata, __DIR__);
$path = __DIR__ . '/EntityGeneratorBook.php';
$this->assertTrue(file_exists($path));
require_once $path;
return $metadata;
}
示例4: generateBookEntityFixture
public function generateBookEntityFixture()
{
$metadata = new ClassMetadataInfo($this->_namespace . '\\EntityGeneratorBook');
$metadata->namespace = $this->_namespace;
$metadata->customRepositoryClassName = $this->_namespace . '\\EntityGeneratorBookRepository';
$metadata->table['name'] = 'book';
$metadata->mapField(array('fieldName' => 'name', 'type' => 'string'));
$metadata->mapField(array('fieldName' => 'status', 'type' => 'string', 'default' => 'published'));
$metadata->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
$metadata->mapOneToOne(array('fieldName' => 'author', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Tools\\EntityGeneratorAuthor', 'mappedBy' => 'book'));
$joinColumns = array(array('name' => 'author_id', 'referencedColumnName' => 'id'));
$metadata->mapManyToMany(array('fieldName' => 'comments', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Tools\\EntityGeneratorComment', 'joinTable' => array('name' => 'book_comment', 'joinColumns' => array(array('name' => 'book_id', 'referencedColumnName' => 'id')), 'inverseJoinColumns' => array(array('name' => 'comment_id', 'referencedColumnName' => 'id')))));
$metadata->addLifecycleCallback('loading', 'postLoad');
$metadata->addLifecycleCallback('willBeRemoved', 'preRemove');
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
$this->_generator->writeEntityClass($metadata, $this->_tmpDir);
return $metadata;
}
示例5: generateBookEntityFixture
/**
* @param ClassMetadataInfo[] $embeddedClasses
*
* @return ClassMetadataInfo
*/
public function generateBookEntityFixture(array $embeddedClasses = array())
{
$metadata = new ClassMetadataInfo($this->_namespace . '\\EntityGeneratorBook');
$metadata->namespace = $this->_namespace;
$metadata->customRepositoryClassName = $this->_namespace . '\\EntityGeneratorBookRepository';
$metadata->table['name'] = 'book';
$metadata->table['uniqueConstraints']['name_uniq'] = array('columns' => array('name'));
$metadata->table['indexes']['status_idx'] = array('columns' => array('status'));
$metadata->mapField(array('fieldName' => 'name', 'type' => 'string'));
$metadata->mapField(array('fieldName' => 'status', 'type' => 'string', 'options' => array('default' => 'published')));
$metadata->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
$metadata->mapOneToOne(array('fieldName' => 'author', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Tools\\EntityGeneratorAuthor', 'mappedBy' => 'book'));
$joinColumns = array(array('name' => 'author_id', 'referencedColumnName' => 'id'));
$metadata->mapManyToMany(array('fieldName' => 'comments', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Tools\\EntityGeneratorComment', 'fetch' => ClassMetadataInfo::FETCH_EXTRA_LAZY, 'joinTable' => array('name' => 'book_comment', 'joinColumns' => array(array('name' => 'book_id', 'referencedColumnName' => 'id')), 'inverseJoinColumns' => array(array('name' => 'comment_id', 'referencedColumnName' => 'id')))));
$metadata->addLifecycleCallback('loading', 'postLoad');
$metadata->addLifecycleCallback('willBeRemoved', 'preRemove');
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
foreach ($embeddedClasses as $fieldName => $embeddedClass) {
$this->mapNestedEmbedded($fieldName, $metadata, $embeddedClass);
$this->mapEmbedded($fieldName, $metadata, $embeddedClass);
}
$this->_generator->writeEntityClass($metadata, $this->_tmpDir);
return $metadata;
}
示例6: loadMetadataForClass
//.........这里部分代码省略.........
if (isset($columnAnnot->columnDefinition)) {
$mapping['columnDefinition'] = $columnAnnot->columnDefinition;
}
if ($idAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Id')) {
$mapping['id'] = true;
}
if ($generatedValueAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\GeneratedValue')) {
$metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . $generatedValueAnnot->strategy));
}
if ($versionAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Version')) {
$metadata->setVersionMapping($mapping);
}
$metadata->mapField($mapping);
// Check for SequenceGenerator/TableGenerator definition
if ($seqGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\SequenceGenerator')) {
$metadata->setSequenceGeneratorDefinition(array('sequenceName' => $seqGeneratorAnnot->sequenceName, 'allocationSize' => $seqGeneratorAnnot->allocationSize, 'initialValue' => $seqGeneratorAnnot->initialValue));
} else {
if ($tblGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\TableGenerator')) {
throw MappingException::tableIdGeneratorNotImplemented($className);
}
}
} else {
if ($oneToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OneToOne')) {
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'][] = array('name' => $joinColumn->name, 'referencedColumnName' => $joinColumn->referencedColumnName, 'unique' => $joinColumn->unique, 'nullable' => $joinColumn->nullable, 'onDelete' => $joinColumn->onDelete, 'columnDefinition' => $joinColumn->columnDefinition);
}
foreach ($joinTableAnnot->inverseJoinColumns as $joinColumn) {
示例7: loadMetadataForClass
//.........这里部分代码省略.........
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->_getJoinColumnMapping($oneToOneElement['joinColumn']);
} else {
if (isset($oneToOneElement['joinColumns'])) {
foreach ($oneToOneElement['joinColumns'] as $name => $joinColumnElement) {
if (!isset($joinColumnElement['name'])) {
$joinColumnElement['name'] = $name;
}
$joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement);
}
}
}
$mapping['joinColumns'] = $joinColumns;
}
if (isset($oneToOneElement['cascade'])) {
$mapping['cascade'] = $oneToOneElement['cascade'];
}
if (isset($oneToOneElement['orphanRemoval'])) {
$mapping['orphanRemoval'] = (bool) $oneToOneElement['orphanRemoval'];
}
$metadata->mapOneToOne($mapping);
}
}
// Evaluate oneToMany relationships
if (isset($element['oneToMany'])) {
foreach ($element['oneToMany'] as $name => $oneToManyElement) {
$mapping = array('fieldName' => $name, 'targetEntity' => $oneToManyElement['targetEntity'], 'mappedBy' => $oneToManyElement['mappedBy']);
if (isset($oneToManyElement['fetch'])) {
$mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . $oneToManyElement['fetch']);
}
if (isset($oneToManyElement['cascade'])) {
$mapping['cascade'] = $oneToManyElement['cascade'];
}
if (isset($oneToManyElement['orphanRemoval'])) {
$mapping['orphanRemoval'] = (bool) $oneToManyElement['orphanRemoval'];
}
if (isset($oneToManyElement['orderBy'])) {
$mapping['orderBy'] = $oneToManyElement['orderBy'];
}
if (isset($oneToManyElement['indexBy'])) {
$mapping['indexBy'] = $oneToManyElement['indexBy'];
}
$metadata->mapOneToMany($mapping);
}
}
// 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'])) {
示例8: buildToOneAssociationMappings
/**
* Build to one (one to one, many to one) association mapping from class metadata.
*
* @param \Doctrine\ORM\Mapping\ClassMetadataInfo $metadata
*/
private function buildToOneAssociationMappings(ClassMetadataInfo $metadata)
{
$tableName = $metadata->table['name'];
$primaryKeys = $this->getTablePrimaryKeys($this->tables[$tableName]);
$foreignKeys = $this->getTableForeignKeys($this->tables[$tableName]);
foreach ($foreignKeys as $foreignKey) {
$foreignTableName = $foreignKey->getForeignTableName();
$fkColumns = $foreignKey->getColumns();
$fkForeignColumns = $foreignKey->getForeignColumns();
$localColumn = current($fkColumns);
$associationMapping = array('fieldName' => $this->getFieldNameForColumn($tableName, $localColumn, true), 'targetEntity' => $this->getClassNameForTable($foreignTableName));
if (isset($metadata->fieldMappings[$associationMapping['fieldName']])) {
$associationMapping['fieldName'] .= '2';
// "foo" => "foo2"
}
if ($primaryKeys && in_array($localColumn, $primaryKeys)) {
$associationMapping['id'] = true;
}
for ($i = 0; $i < count($fkColumns); $i++) {
$associationMapping['joinColumns'][] = array('name' => $fkColumns[$i], 'referencedColumnName' => $fkForeignColumns[$i]);
}
// Here we need to check if $fkColumns are the same as $primaryKeys
if (!array_diff($fkColumns, $primaryKeys)) {
$metadata->mapOneToOne($associationMapping);
} else {
$metadata->mapManyToOne($associationMapping);
}
}
}
示例9: loadMetadata
public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata)
{
$metadata->setPrimaryTable(array('name' => 'company_person'));
$metadata->mapField(array('id' => true, 'fieldName' => 'id', 'type' => 'integer'));
$metadata->mapField(array('fieldName' => 'zip', 'length' => 50));
$metadata->mapField(array('fieldName' => 'city', 'length' => 50));
$metadata->mapOneToOne(array('fieldName' => 'user', 'targetEntity' => 'CmsUser', 'joinColumns' => array(array('referencedColumnName' => 'id'))));
$metadata->addNamedNativeQuery(array('name' => 'find-all', 'query' => 'SELECT id, country, city FROM cms_addresses', 'resultSetMapping' => 'mapping-find-all'));
$metadata->addNamedNativeQuery(array('name' => 'find-by-id', 'query' => 'SELECT * FROM cms_addresses WHERE id = ?', 'resultClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsAddress'));
$metadata->addNamedNativeQuery(array('name' => 'count', 'query' => 'SELECT COUNT(*) AS count FROM cms_addresses', 'resultSetMapping' => 'mapping-count'));
$metadata->addSqlResultSetMapping(array('name' => 'mapping-find-all', 'columns' => array(), 'entities' => array(array('fields' => array(array('name' => 'id', 'column' => 'id'), array('name' => 'city', 'column' => 'city'), array('name' => 'country', 'column' => 'country')), 'entityClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsAddress'))));
$metadata->addSqlResultSetMapping(array('name' => 'mapping-without-fields', 'columns' => array(), 'entities' => array(array('entityClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsAddress', 'fields' => array()))));
$metadata->addSqlResultSetMapping(array('name' => 'mapping-count', 'columns' => array(array('name' => 'count'))));
$metadata->addEntityListener(\Doctrine\ORM\Events::postPersist, 'CmsAddressListener', 'postPersist');
$metadata->addEntityListener(\Doctrine\ORM\Events::prePersist, 'CmsAddressListener', 'prePersist');
$metadata->addEntityListener(\Doctrine\ORM\Events::postUpdate, 'CmsAddressListener', 'postUpdate');
$metadata->addEntityListener(\Doctrine\ORM\Events::preUpdate, 'CmsAddressListener', 'preUpdate');
$metadata->addEntityListener(\Doctrine\ORM\Events::postRemove, 'CmsAddressListener', 'postRemove');
$metadata->addEntityListener(\Doctrine\ORM\Events::preRemove, 'CmsAddressListener', 'preRemove');
$metadata->addEntityListener(\Doctrine\ORM\Events::preFlush, 'CmsAddressListener', 'preFlush');
$metadata->addEntityListener(\Doctrine\ORM\Events::postLoad, 'CmsAddressListener', 'postLoad');
}
示例10: evaluatePropertyAnnotations
/**
* Evaluate the property annotations and amend the metadata accordingly.
*
* @param ORM\ClassMetadataInfo $metadata
* @return void
* @throws ORM\MappingException
*/
protected function evaluatePropertyAnnotations(ORM\ClassMetadataInfo $metadata)
{
$className = $metadata->name;
$class = $metadata->getReflectionClass();
$classSchema = $this->getClassSchema($className);
foreach ($class->getProperties() as $property) {
if (!$classSchema->hasProperty($property->getName()) || $classSchema->isPropertyTransient($property->getName()) || $metadata->isMappedSuperclass && !$property->isPrivate() || $metadata->isInheritedField($property->getName()) || $metadata->isInheritedAssociation($property->getName()) || $metadata->isInheritedEmbeddedClass($property->getName())) {
continue;
}
$propertyMetaData = $classSchema->getProperty($property->getName());
$mapping = [];
$mapping['fieldName'] = $property->getName();
$mapping['columnName'] = strtolower($property->getName());
$mapping['targetEntity'] = $propertyMetaData['type'];
$joinColumns = $this->evaluateJoinColumnAnnotations($property);
// Field can only be annotated with one of:
// @OneToOne, @OneToMany, @ManyToOne, @ManyToMany, @Column (optional)
if ($oneToOneAnnotation = $this->reader->getPropertyAnnotation($property, ORM\OneToOne::class)) {
if ($this->reader->getPropertyAnnotation($property, ORM\Id::class) !== null) {
$mapping['id'] = true;
}
if ($oneToOneAnnotation->targetEntity) {
$mapping['targetEntity'] = $oneToOneAnnotation->targetEntity;
}
if ($oneToOneAnnotation->inversedBy !== null || $oneToOneAnnotation->mappedBy === null) {
$mapping['joinColumns'] = $this->buildJoinColumnsIfNeeded($joinColumns, $mapping, $property);
}
$mapping['mappedBy'] = $oneToOneAnnotation->mappedBy;
$mapping['inversedBy'] = $oneToOneAnnotation->inversedBy;
if ($oneToOneAnnotation->cascade) {
$mapping['cascade'] = $oneToOneAnnotation->cascade;
} elseif ($this->isValueObject($mapping['targetEntity'], $className)) {
$mapping['cascade'] = ['persist'];
} elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false) {
$mapping['cascade'] = ['all'];
}
if ($oneToOneAnnotation->orphanRemoval) {
$mapping['orphanRemoval'] = $oneToOneAnnotation->orphanRemoval;
} elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false && $this->isValueObject($mapping['targetEntity'], $className) === false) {
$mapping['orphanRemoval'] = true;
}
$mapping['fetch'] = $this->getFetchMode($className, $oneToOneAnnotation->fetch);
$metadata->mapOneToOne($mapping);
} elseif ($oneToManyAnnotation = $this->reader->getPropertyAnnotation($property, ORM\OneToMany::class)) {
$mapping['mappedBy'] = $oneToManyAnnotation->mappedBy;
if ($oneToManyAnnotation->targetEntity) {
$mapping['targetEntity'] = $oneToManyAnnotation->targetEntity;
} elseif (isset($propertyMetaData['elementType'])) {
$mapping['targetEntity'] = $propertyMetaData['elementType'];
}
if ($oneToManyAnnotation->cascade) {
$mapping['cascade'] = $oneToManyAnnotation->cascade;
} elseif ($this->isValueObject($mapping['targetEntity'], $className)) {
$mapping['cascade'] = ['persist'];
} elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false) {
$mapping['cascade'] = ['all'];
}
$mapping['indexBy'] = $oneToManyAnnotation->indexBy;
if ($oneToManyAnnotation->orphanRemoval) {
$mapping['orphanRemoval'] = $oneToManyAnnotation->orphanRemoval;
} elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false && $this->isValueObject($mapping['targetEntity'], $className) === false) {
$mapping['orphanRemoval'] = true;
}
$mapping['fetch'] = $this->getFetchMode($className, $oneToManyAnnotation->fetch);
if ($orderByAnnotation = $this->reader->getPropertyAnnotation($property, ORM\OrderBy::class)) {
$mapping['orderBy'] = $orderByAnnotation->value;
}
$metadata->mapOneToMany($mapping);
} elseif ($manyToOneAnnotation = $this->reader->getPropertyAnnotation($property, ORM\ManyToOne::class)) {
if ($this->reader->getPropertyAnnotation($property, ORM\Id::class) !== null) {
$mapping['id'] = true;
}
if ($manyToOneAnnotation->targetEntity) {
$mapping['targetEntity'] = $manyToOneAnnotation->targetEntity;
}
$mapping['joinColumns'] = $this->buildJoinColumnsIfNeeded($joinColumns, $mapping, $property);
if ($manyToOneAnnotation->cascade) {
$mapping['cascade'] = $manyToOneAnnotation->cascade;
} elseif ($this->isValueObject($mapping['targetEntity'], $className)) {
$mapping['cascade'] = ['persist'];
} elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false) {
$mapping['cascade'] = ['all'];
}
$mapping['inversedBy'] = $manyToOneAnnotation->inversedBy;
$mapping['fetch'] = $this->getFetchMode($className, $manyToOneAnnotation->fetch);
$metadata->mapManyToOne($mapping);
} elseif ($manyToManyAnnotation = $this->reader->getPropertyAnnotation($property, ORM\ManyToMany::class)) {
if ($manyToManyAnnotation->targetEntity) {
$mapping['targetEntity'] = $manyToManyAnnotation->targetEntity;
} elseif (isset($propertyMetaData['elementType'])) {
$mapping['targetEntity'] = $propertyMetaData['elementType'];
}
/** @var ORM\JoinTable $joinTableAnnotation */
//.........这里部分代码省略.........
示例11: loadMetadataForClass
//.........这里部分代码省略.........
if (isset($idElement->{'table-generator'})) {
throw MappingException::tableIdGeneratorNotImplemented($className);
}
}
}
// Evaluate <one-to-one ...> mappings
if (isset($xmlRoot->{'one-to-one'})) {
foreach ($xmlRoot->{'one-to-one'} as $oneToOneElement) {
$mapping = array('fieldName' => (string) $oneToOneElement['field'], 'targetEntity' => (string) $oneToOneElement['target-entity']);
if (isset($oneToOneElement['fetch'])) {
$mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\AssociationMapping::FETCH_' . (string) $oneToOneElement['fetch']);
}
if (isset($oneToOneElement['mapped-by'])) {
$mapping['mappedBy'] = (string) $oneToOneElement['mapped-by'];
} else {
$joinColumns = array();
if (isset($oneToOneElement->{'join-column'})) {
$joinColumns[] = $this->_getJoinColumnMapping($oneToOneElement->{'join-column'});
} else {
if (isset($oneToOneElement->{'join-columns'})) {
foreach ($oneToOneElement->{'join-columns'}->{'join-column'} as $joinColumnElement) {
$joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement);
}
}
}
$mapping['joinColumns'] = $joinColumns;
}
if (isset($oneToOneElement->cascade)) {
$mapping['cascade'] = $this->_getCascadeMappings($oneToOneElement->cascade);
}
if (isset($oneToOneElement->{'orphan-removal'})) {
$mapping['orphanRemoval'] = (bool) $oneToOneElement->{'orphan-removal'};
}
$metadata->mapOneToOne($mapping);
}
}
// Evaluate <one-to-many ...> mappings
if (isset($xmlRoot->{'one-to-many'})) {
foreach ($xmlRoot->{'one-to-many'} as $oneToManyElement) {
$mapping = array('fieldName' => (string) $oneToManyElement['field'], 'targetEntity' => (string) $oneToManyElement['target-entity'], 'mappedBy' => (string) $oneToManyElement['mapped-by']);
if (isset($oneToManyElement['fetch'])) {
$mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\AssociationMapping::FETCH_' . (string) $oneToManyElement['fetch']);
}
if (isset($oneToManyElement->cascade)) {
$mapping['cascade'] = $this->_getCascadeMappings($oneToManyElement->cascade);
}
if (isset($oneToManyElement->{'orphan-removal'})) {
$mapping['orphanRemoval'] = (bool) $oneToManyElement->{'orphan-removal'};
}
$metadata->mapOneToMany($mapping);
}
}
// Evaluate <many-to-one ...> mappings
if (isset($xmlRoot->{'many-to-one'})) {
foreach ($xmlRoot->{'many-to-one'} as $manyToOneElement) {
$mapping = array('fieldName' => (string) $manyToOneElement['field'], 'targetEntity' => (string) $manyToOneElement['target-entity']);
if (isset($manyToOneElement['fetch'])) {
$mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\AssociationMapping::FETCH_' . (string) $manyToOneElement['fetch']);
}
$joinColumns = array();
if (isset($manyToOneElement->{'join-column'})) {
$joinColumns[] = $this->_getJoinColumnMapping($manyToOneElement->{'join-column'});
} else {
if (isset($manyToOneElement->{'join-columns'})) {
foreach ($manyToOneElement->{'join-columns'}->{'join-column'} as $joinColumnElement) {
if (!isset($joinColumnElement['name'])) {
示例12: loadMetadataForClass
//.........这里部分代码省略.........
}
if (isset($columnAnnot->name)) {
$mapping['columnName'] = $columnAnnot->name;
}
if (isset($columnAnnot->columnDefinition)) {
$mapping['columnDefinition'] = $columnAnnot->columnDefinition;
}
if ($idAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Id')) {
$mapping['id'] = true;
}
if ($generatedValueAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\GeneratedValue')) {
$metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . $generatedValueAnnot->strategy));
}
if ($versionAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Version')) {
$metadata->setVersionMapping($mapping);
}
$metadata->mapField($mapping);
// Check for SequenceGenerator/TableGenerator definition
if ($seqGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\SequenceGenerator')) {
$metadata->setSequenceGeneratorDefinition(array('sequenceName' => $seqGeneratorAnnot->sequenceName, 'allocationSize' => $seqGeneratorAnnot->allocationSize, 'initialValue' => $seqGeneratorAnnot->initialValue));
} else {
if ($tblGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\TableGenerator')) {
throw MappingException::tableIdGeneratorNotImplemented($className);
}
}
} else {
if ($oneToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OneToOne')) {
$mapping['targetEntity'] = $oneToOneAnnot->targetEntity;
$mapping['joinColumns'] = $joinColumns;
$mapping['mappedBy'] = $oneToOneAnnot->mappedBy;
$mapping['cascade'] = $oneToOneAnnot->cascade;
$mapping['orphanRemoval'] = $oneToOneAnnot->orphanRemoval;
$mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\AssociationMapping::FETCH_' . $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['orphanRemoval'] = $oneToManyAnnot->orphanRemoval;
$mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\AssociationMapping::FETCH_' . $oneToManyAnnot->fetch);
$metadata->mapOneToMany($mapping);
} else {
if ($manyToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\ManyToOne')) {
$mapping['joinColumns'] = $joinColumns;
$mapping['cascade'] = $manyToOneAnnot->cascade;
$mapping['targetEntity'] = $manyToOneAnnot->targetEntity;
$mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\AssociationMapping::FETCH_' . $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'][] = array('name' => $joinColumn->name, 'referencedColumnName' => $joinColumn->referencedColumnName, 'unique' => $joinColumn->unique, 'nullable' => $joinColumn->nullable, 'onDelete' => $joinColumn->onDelete, 'onUpdate' => $joinColumn->onUpdate, 'columnDefinition' => $joinColumn->columnDefinition);
}
foreach ($joinTableAnnot->inverseJoinColumns as $joinColumn) {
$joinTable['inverseJoinColumns'][] = array('name' => $joinColumn->name, 'referencedColumnName' => $joinColumn->referencedColumnName, 'unique' => $joinColumn->unique, 'nullable' => $joinColumn->nullable, 'onDelete' => $joinColumn->onDelete, 'onUpdate' => $joinColumn->onUpdate, 'columnDefinition' => $joinColumn->columnDefinition);
}
}
$mapping['joinTable'] = $joinTable;
$mapping['targetEntity'] = $manyToManyAnnot->targetEntity;
$mapping['mappedBy'] = $manyToManyAnnot->mappedBy;
$mapping['cascade'] = $manyToManyAnnot->cascade;
$mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\AssociationMapping::FETCH_' . $manyToManyAnnot->fetch);
示例13: getTestMetadataProcessingData
/**
* Data provider for testMetadataProcessing().
*
* @return array
* @throws \Doctrine\ORM\Mapping\MappingException
*/
public function getTestMetadataProcessingData()
{
$out = [];
/** @var ObjectManager $entityManager Common data for most test cases. */
$entityManager = $this->getMock('Doctrine\\ORM\\EntityManagerInterface');
$baseMapping = ['fieldName' => 'fieldNameValue'];
$replacements = ['@placeholder' => '_1'];
// Case 0: no replacements, no mapping.
$classMetadataInfo = new ClassMetadataInfo('someEntity');
$input = new LoadClassMetadataEventArgs($classMetadataInfo, $entityManager);
$output = new LoadClassMetadataEventArgs($classMetadataInfo, $entityManager);
$out[] = [[], $input, $output];
// Case 1: no replacements, default mappings.
$inputClassMetadataInfo = new ClassMetadataInfo('someEntity');
$inputClassMetadataInfo->mapField($baseMapping);
$input = new LoadClassMetadataEventArgs($inputClassMetadataInfo, $entityManager);
$outputClassMetadataInfo = new ClassMetadataInfo('someEntity');
$outputClassMetadataInfo->mapField($baseMapping);
$output = new LoadClassMetadataEventArgs($outputClassMetadataInfo, $entityManager);
$out[] = [[], $input, $output];
// Case 2: no replacements.
$inputClassMetadataInfo = new ClassMetadataInfo('someEntity');
$inputClassMetadataInfo->mapField(array_merge($baseMapping, ['key' => 'value']));
$input = new LoadClassMetadataEventArgs($inputClassMetadataInfo, $entityManager);
$outputClassMetadataInfo = new ClassMetadataInfo('someEntity');
$outputClassMetadataInfo->mapField(array_merge($baseMapping, ['key' => 'value']));
$output = new LoadClassMetadataEventArgs($outputClassMetadataInfo, $entityManager);
$out[] = [[], $input, $output];
// Case 3: irrelevant replacements.
$inputClassMetadataInfo = new ClassMetadataInfo('someEntity');
$inputClassMetadataInfo->mapField(array_merge($baseMapping, ['key' => 'value']));
$input = new LoadClassMetadataEventArgs($inputClassMetadataInfo, $entityManager);
$outputClassMetadataInfo = new ClassMetadataInfo('someEntity');
$outputClassMetadataInfo->mapField(array_merge($baseMapping, ['key' => 'value']));
$output = new LoadClassMetadataEventArgs($outputClassMetadataInfo, $entityManager);
$out[] = [$replacements, $input, $output];
// Case 4: replacements provided.
$inputClassMetadataInfo = new ClassMetadataInfo('someEntity');
$inputClassMetadataInfo->mapField(array_merge($baseMapping, ['key' => 'value@placeholder']));
$input = new LoadClassMetadataEventArgs($inputClassMetadataInfo, $entityManager);
$outputClassMetadataInfo = new ClassMetadataInfo('someEntity');
$outputClassMetadataInfo->mapField(array_merge($baseMapping, ['key' => 'value_1']));
$output = new LoadClassMetadataEventArgs($outputClassMetadataInfo, $entityManager);
$out[] = [$replacements, $input, $output];
// Case 5: nested annotations.
$inputClassMetadataInfo = new ClassMetadataInfo('someEntity');
$inputClassMetadataInfo->mapField(array_merge($baseMapping, ['key' => ['internalKey' => ['value@placeholder']]]));
$input = new LoadClassMetadataEventArgs($inputClassMetadataInfo, $entityManager);
$outputClassMetadataInfo = new ClassMetadataInfo('someEntity');
$outputClassMetadataInfo->mapField(array_merge($baseMapping, ['key' => ['internalKey' => ['value@placeholder']]]));
$output = new LoadClassMetadataEventArgs($outputClassMetadataInfo, $entityManager);
$out[] = [$replacements, $input, $output];
// Case 6: replacing table name.
$inputClassMetadataInfo = new ClassMetadataInfo('someEntity');
$inputClassMetadataInfo->mapField($baseMapping);
$inputClassMetadataInfo->setPrimaryTable(['name' => 'my_table@placeholder']);
$input = new LoadClassMetadataEventArgs($inputClassMetadataInfo, $entityManager);
$outputClassMetadataInfo = new ClassMetadataInfo('someEntity');
$outputClassMetadataInfo->mapField($baseMapping);
$outputClassMetadataInfo->setPrimaryTable(['name' => 'my_table_1']);
$output = new LoadClassMetadataEventArgs($outputClassMetadataInfo, $entityManager);
$out[] = [$replacements, $input, $output];
// Case 7: one-to-one mapping.
$replacements = ['@placeholder' => '_1'];
$inputClassMetadataInfo = new ClassMetadataInfo('someEntity');
$inputClassMetadataInfo->setPrimaryTable(['name' => 'my_table']);
$inputClassMetadataInfo->mapOneToOne(array_merge($baseMapping, ['targetEntity' => 'whatever', 'joinColumns' => [['name' => 'someName', 'referencedColumnName' => 'FK@placeholder']]]));
$input = new LoadClassMetadataEventArgs($inputClassMetadataInfo, $entityManager);
$outputClassMetadataInfo = new ClassMetadataInfo('someEntity');
$outputClassMetadataInfo->setPrimaryTable(['name' => 'my_table']);
$outputClassMetadataInfo->mapOneToOne(array_merge($baseMapping, ['targetEntity' => 'whatever', 'joinColumns' => [['name' => 'someName', 'referencedColumnName' => 'FK_1']], 'joinTableColumns' => null, 'relationToSourceKeyColumns' => null, 'relationToTargetKeyColumns' => null]));
$output = new LoadClassMetadataEventArgs($outputClassMetadataInfo, $entityManager);
$out[] = [$replacements, $input, $output];
return $out;
}
示例14: mapOneToOneField
private function mapOneToOneField($name, array $mapping, ClassMetadataInfo $metadata)
{
$oneToOne = array('fieldName' => $name, 'targetEntity' => $mapping['typeParenthese']);
if (isset($mapping['fetch'])) {
$oneToOne['fetch'] = constant(sprintf('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_%s', $mapping['fetch']));
}
$joinColumns = array();
if (isset($mapping['joinColumn'])) {
$joinColumns[] = $this->getJoinColumnMapping($mapping['joinColumn']);
} elseif (isset($mapping['joinColumns'])) {
foreach ($mapping['joinColumns'] as $name => $joinColumnMapping) {
if (!isset($joinColumnMapping['name'])) {
$joinColumnMapping['name'] = $name;
}
$joinColumns[] = $this->getJoinColumnMapping($joinColumnMapping);
}
}
$oneToOne['joinColumns'] = $joinColumns;
if (isset($mapping['cascade'])) {
$oneToOne['cascade'] = $mapping['cascade'];
}
if (isset($mapping['orphanRemoval'])) {
$oneToOne['orphanRemoval'] = (bool) $mapping['orphanRemoval'];
}
$metadata->mapOneToOne($oneToOne);
}
示例15: remapAssociation
/**
* @param \Doctrine\ORM\Mapping\ClassMetadataInfo $classMetadata
* @param array $mapping
*
* @return void
*/
private function remapAssociation($classMetadata, $mapping)
{
$newMapping = $this->resolveTargetEntities[$mapping['targetEntity']];
$newMapping = array_replace_recursive($mapping, $newMapping);
$newMapping['fieldName'] = $mapping['fieldName'];
unset($classMetadata->associationMappings[$mapping['fieldName']]);
switch ($mapping['type']) {
case ClassMetadata::MANY_TO_MANY:
$classMetadata->mapManyToMany($newMapping);
break;
case ClassMetadata::MANY_TO_ONE:
$classMetadata->mapManyToOne($newMapping);
break;
case ClassMetadata::ONE_TO_MANY:
$classMetadata->mapOneToMany($newMapping);
break;
case ClassMetadata::ONE_TO_ONE:
$classMetadata->mapOneToOne($newMapping);
break;
}
}