本文整理汇总了PHP中Doctrine\Common\Persistence\Mapping\ClassMetadata::setDiscriminatorColumn方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::setDiscriminatorColumn方法的具体用法?PHP ClassMetadata::setDiscriminatorColumn怎么用?PHP ClassMetadata::setDiscriminatorColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Persistence\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::setDiscriminatorColumn方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadMetadataForClass
/**
* {@inheritDoc}
*/
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
/* @var $metadata \Doctrine\ORM\Mapping\ClassMetadataInfo */
/* @var $xmlRoot SimpleXMLElement */
$xmlRoot = $this->getElement($className);
if ($xmlRoot->getName() == 'entity') {
if (isset($xmlRoot['repository-class'])) {
$metadata->setCustomRepositoryClass((string) $xmlRoot['repository-class']);
}
if (isset($xmlRoot['read-only']) && $this->evaluateBoolean($xmlRoot['read-only'])) {
$metadata->markReadOnly();
}
} else {
if ($xmlRoot->getName() == 'mapped-superclass') {
$metadata->setCustomRepositoryClass(isset($xmlRoot['repository-class']) ? (string) $xmlRoot['repository-class'] : null);
$metadata->isMappedSuperclass = true;
} else {
throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
}
}
// Evaluate <entity...> attributes
$table = array();
if (isset($xmlRoot['table'])) {
$table['name'] = (string) $xmlRoot['table'];
}
$metadata->setPrimaryTable($table);
// Evaluate named queries
if (isset($xmlRoot->{'named-queries'})) {
foreach ($xmlRoot->{'named-queries'}->{'named-query'} as $namedQueryElement) {
$metadata->addNamedQuery(array('name' => (string) $namedQueryElement['name'], 'query' => (string) $namedQueryElement['query']));
}
}
// Evaluate native named queries
if (isset($xmlRoot->{'named-native-queries'})) {
foreach ($xmlRoot->{'named-native-queries'}->{'named-native-query'} as $nativeQueryElement) {
$metadata->addNamedNativeQuery(array('name' => isset($nativeQueryElement['name']) ? (string) $nativeQueryElement['name'] : null, 'query' => isset($nativeQueryElement->query) ? (string) $nativeQueryElement->query : null, 'resultClass' => isset($nativeQueryElement['result-class']) ? (string) $nativeQueryElement['result-class'] : null, 'resultSetMapping' => isset($nativeQueryElement['result-set-mapping']) ? (string) $nativeQueryElement['result-set-mapping'] : null));
}
}
// Evaluate sql result set mapping
if (isset($xmlRoot->{'sql-result-set-mappings'})) {
foreach ($xmlRoot->{'sql-result-set-mappings'}->{'sql-result-set-mapping'} as $rsmElement) {
$entities = array();
$columns = array();
foreach ($rsmElement as $entityElement) {
//<entity-result/>
if (isset($entityElement['entity-class'])) {
$entityResult = array('fields' => array(), 'entityClass' => (string) $entityElement['entity-class'], 'discriminatorColumn' => isset($entityElement['discriminator-column']) ? (string) $entityElement['discriminator-column'] : null);
foreach ($entityElement as $fieldElement) {
$entityResult['fields'][] = array('name' => isset($fieldElement['name']) ? (string) $fieldElement['name'] : null, 'column' => isset($fieldElement['column']) ? (string) $fieldElement['column'] : null);
}
$entities[] = $entityResult;
}
//<column-result/>
if (isset($entityElement['name'])) {
$columns[] = array('name' => (string) $entityElement['name']);
}
}
$metadata->addSqlResultSetMapping(array('name' => (string) $rsmElement['name'], 'entities' => $entities, 'columns' => $columns));
}
}
/* not implemented specially anyway. use table = schema.table
if (isset($xmlRoot['schema'])) {
$metadata->table['schema'] = (string)$xmlRoot['schema'];
}*/
if (isset($xmlRoot['inheritance-type'])) {
$inheritanceType = (string) $xmlRoot['inheritance-type'];
$metadata->setInheritanceType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceType));
if ($metadata->inheritanceType != \Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_NONE) {
// Evaluate <discriminator-column...>
if (isset($xmlRoot->{'discriminator-column'})) {
$discrColumn = $xmlRoot->{'discriminator-column'};
$metadata->setDiscriminatorColumn(array('name' => isset($discrColumn['name']) ? (string) $discrColumn['name'] : null, 'type' => isset($discrColumn['type']) ? (string) $discrColumn['type'] : null, 'length' => isset($discrColumn['length']) ? (string) $discrColumn['length'] : null, 'columnDefinition' => isset($discrColumn['column-definition']) ? (string) $discrColumn['column-definition'] : null));
} else {
$metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));
}
// Evaluate <discriminator-map...>
if (isset($xmlRoot->{'discriminator-map'})) {
$map = array();
foreach ($xmlRoot->{'discriminator-map'}->{'discriminator-mapping'} as $discrMapElement) {
$map[(string) $discrMapElement['value']] = (string) $discrMapElement['class'];
}
$metadata->setDiscriminatorMap($map);
}
}
}
// Evaluate <change-tracking-policy...>
if (isset($xmlRoot['change-tracking-policy'])) {
$metadata->setChangeTrackingPolicy(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CHANGETRACKING_' . strtoupper((string) $xmlRoot['change-tracking-policy'])));
}
// Evaluate <indexes...>
if (isset($xmlRoot->indexes)) {
$metadata->table['indexes'] = array();
foreach ($xmlRoot->indexes->index as $index) {
$columns = explode(',', (string) $index['columns']);
if (isset($index['name'])) {
$metadata->table['indexes'][(string) $index['name']] = array('columns' => $columns);
} else {
//.........这里部分代码省略.........
示例2: loadMetadataForClass
//.........这里部分代码省略.........
// Evaluate SqlResultSetMappings annotation
if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\SqlResultSetMappings'])) {
$sqlResultSetMappingsAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\SqlResultSetMappings'];
foreach ($sqlResultSetMappingsAnnotation->value as $resultSetMapping) {
$entities = array();
$columns = array();
foreach ($resultSetMapping->entities as $entityResultAnnotation) {
$entityResult = array('fields' => array(), 'entityClass' => $entityResultAnnotation->entityClass, 'discriminatorColumn' => $entityResultAnnotation->discriminatorColumn);
foreach ($entityResultAnnotation->fields as $fieldResultAnnotation) {
$entityResult['fields'][] = array('name' => $fieldResultAnnotation->name, 'column' => $fieldResultAnnotation->column);
}
$entities[] = $entityResult;
}
foreach ($resultSetMapping->columns as $columnResultAnnotation) {
$columns[] = array('name' => $columnResultAnnotation->name);
}
$metadata->addSqlResultSetMapping(array('name' => $resultSetMapping->name, 'entities' => $entities, 'columns' => $columns));
}
}
// Evaluate NamedQueries annotation
if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\NamedQueries'])) {
$namedQueriesAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\NamedQueries'];
if (!is_array($namedQueriesAnnotation->value)) {
throw new \UnexpectedValueException('@NamedQueries should contain an array of @NamedQuery annotations.');
}
foreach ($namedQueriesAnnotation->value as $namedQuery) {
if (!$namedQuery instanceof NamedQuery) {
throw new \UnexpectedValueException('@NamedQueries should contain an array of @NamedQuery annotations.');
}
$metadata->addNamedQuery(array('name' => $namedQuery->name, 'query' => $namedQuery->query));
}
}
// Evaluate InheritanceType annotation
if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\InheritanceType'])) {
$inheritanceTypeAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\InheritanceType'];
$inheritanceType = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . strtoupper($inheritanceTypeAnnotation->value));
if ($inheritanceType !== OrmClassMetadata::INHERITANCE_TYPE_NONE) {
// Evaluate DiscriminatorColumn annotation
if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorColumn'])) {
$discriminatorColumnAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorColumn'];
$discriminatorColumn = array('name' => $discriminatorColumnAnnotation->name, 'type' => $discriminatorColumnAnnotation->type, 'length' => $discriminatorColumnAnnotation->length, 'columnDefinition' => $discriminatorColumnAnnotation->columnDefinition);
} else {
$discriminatorColumn = array('name' => 'dtype', 'type' => 'string', 'length' => 255);
}
// Evaluate DiscriminatorMap annotation
if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorMap'])) {
$discriminatorMapAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorMap'];
$discriminatorMap = $discriminatorMapAnnotation->value;
} else {
$discriminatorMap = array();
$subclassNames = $this->reflectionService->getAllSubClassNamesForClass($className);
if (!$this->reflectionService->isClassAbstract($className)) {
$mappedClassName = strtolower(str_replace('Domain_Model_', '', str_replace('\\', '_', $className)));
$discriminatorMap[$mappedClassName] = $className;
}
foreach ($subclassNames as $subclassName) {
$mappedSubclassName = strtolower(str_replace('Domain_Model_', '', str_replace('\\', '_', $subclassName)));
$discriminatorMap[$mappedSubclassName] = $subclassName;
}
}
if ($discriminatorMap !== array()) {
$metadata->setDiscriminatorColumn($discriminatorColumn);
$metadata->setDiscriminatorMap($discriminatorMap);
} else {
$inheritanceType = OrmClassMetadata::INHERITANCE_TYPE_NONE;
}
}
$metadata->setInheritanceType($inheritanceType);
}
// Evaluate DoctrineChangeTrackingPolicy annotation
if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\ChangeTrackingPolicy'])) {
$changeTrackingAnnotation = $classAnnotations['Doctrine\\ORM\\Mapping\\ChangeTrackingPolicy'];
$metadata->setChangeTrackingPolicy(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CHANGETRACKING_' . strtoupper($changeTrackingAnnotation->value)));
} else {
$metadata->setChangeTrackingPolicy(OrmClassMetadata::CHANGETRACKING_DEFERRED_EXPLICIT);
}
// Evaluate annotations on properties/fields
try {
$this->evaluatePropertyAnnotations($metadata);
} catch (MappingException $exception) {
throw new MappingException(sprintf('Failure while evaluating property annotations for class "%s": %s', $metadata->getName(), $exception->getMessage()), 1382003497, $exception);
}
// build unique index for table
if (!isset($primaryTable['uniqueConstraints'])) {
$idProperties = array_keys($classSchema->getIdentityProperties());
if (array_diff($idProperties, $metadata->getIdentifierFieldNames()) !== array()) {
$uniqueIndexName = $this->truncateIdentifier('flow_identity_' . $primaryTable['name']);
foreach ($idProperties as $idProperty) {
$primaryTable['uniqueConstraints'][$uniqueIndexName]['columns'][] = isset($metadata->columnNames[$idProperty]) ? $metadata->columnNames[$idProperty] : strtolower($idProperty);
}
}
}
$metadata->setPrimaryTable($primaryTable);
// Evaluate AssociationOverrides annotation
$this->evaluateOverridesAnnotations($classAnnotations, $metadata);
// Evaluate EntityListeners annotation
$this->evaluateEntityListenersAnnotation($class, $metadata, $classAnnotations);
// Evaluate @HasLifecycleCallbacks annotation
$this->evaluateLifeCycleAnnotations($class, $metadata);
}
示例3: loadMetadataForClass
/**
* {@inheritDoc}
*/
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
/* @var $metadata \Doctrine\ORM\Mapping\ClassMetadataInfo */
$element = $this->getElement($className);
if ($element['type'] == 'entity') {
if (isset($element['repositoryClass'])) {
$metadata->setCustomRepositoryClass($element['repositoryClass']);
}
if (isset($element['readOnly']) && $element['readOnly'] == true) {
$metadata->markReadOnly();
}
} else {
if ($element['type'] == 'mappedSuperclass') {
$metadata->setCustomRepositoryClass(isset($element['repositoryClass']) ? $element['repositoryClass'] : null);
$metadata->isMappedSuperclass = true;
} else {
if ($element['type'] == 'embeddable') {
$metadata->isEmbeddedClass = true;
} else {
throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
}
}
}
// Evaluate root level properties
$table = array();
if (isset($element['table'])) {
$table['name'] = $element['table'];
}
// Evaluate second level cache
if (isset($element['cache'])) {
$metadata->enableCache($this->cacheToArray($element['cache']));
}
$metadata->setPrimaryTable($table);
// Evaluate named queries
if (isset($element['namedQueries'])) {
foreach ($element['namedQueries'] as $name => $queryMapping) {
if (is_string($queryMapping)) {
$queryMapping = array('query' => $queryMapping);
}
if (!isset($queryMapping['name'])) {
$queryMapping['name'] = $name;
}
$metadata->addNamedQuery($queryMapping);
}
}
// Evaluate named native queries
if (isset($element['namedNativeQueries'])) {
foreach ($element['namedNativeQueries'] as $name => $mappingElement) {
if (!isset($mappingElement['name'])) {
$mappingElement['name'] = $name;
}
$metadata->addNamedNativeQuery(array('name' => $mappingElement['name'], 'query' => isset($mappingElement['query']) ? $mappingElement['query'] : null, 'resultClass' => isset($mappingElement['resultClass']) ? $mappingElement['resultClass'] : null, 'resultSetMapping' => isset($mappingElement['resultSetMapping']) ? $mappingElement['resultSetMapping'] : null));
}
}
// Evaluate sql result set mappings
if (isset($element['sqlResultSetMappings'])) {
foreach ($element['sqlResultSetMappings'] as $name => $resultSetMapping) {
if (!isset($resultSetMapping['name'])) {
$resultSetMapping['name'] = $name;
}
$entities = array();
$columns = array();
if (isset($resultSetMapping['entityResult'])) {
foreach ($resultSetMapping['entityResult'] as $entityResultElement) {
$entityResult = array('fields' => array(), 'entityClass' => isset($entityResultElement['entityClass']) ? $entityResultElement['entityClass'] : null, 'discriminatorColumn' => isset($entityResultElement['discriminatorColumn']) ? $entityResultElement['discriminatorColumn'] : null);
if (isset($entityResultElement['fieldResult'])) {
foreach ($entityResultElement['fieldResult'] as $fieldResultElement) {
$entityResult['fields'][] = array('name' => isset($fieldResultElement['name']) ? $fieldResultElement['name'] : null, 'column' => isset($fieldResultElement['column']) ? $fieldResultElement['column'] : null);
}
}
$entities[] = $entityResult;
}
}
if (isset($resultSetMapping['columnResult'])) {
foreach ($resultSetMapping['columnResult'] as $columnResultAnnot) {
$columns[] = array('name' => isset($columnResultAnnot['name']) ? $columnResultAnnot['name'] : null);
}
}
$metadata->addSqlResultSetMapping(array('name' => $resultSetMapping['name'], 'entities' => $entities, 'columns' => $columns));
}
}
/* not implemented specially anyway. use table = schema.table
if (isset($element['schema'])) {
$metadata->table['schema'] = $element['schema'];
}*/
if (isset($element['inheritanceType'])) {
$metadata->setInheritanceType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . strtoupper($element['inheritanceType'])));
if ($metadata->inheritanceType != \Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_NONE) {
// Evaluate discriminatorColumn
if (isset($element['discriminatorColumn'])) {
$discrColumn = $element['discriminatorColumn'];
$metadata->setDiscriminatorColumn(array('name' => isset($discrColumn['name']) ? (string) $discrColumn['name'] : null, 'type' => isset($discrColumn['type']) ? (string) $discrColumn['type'] : null, 'length' => isset($discrColumn['length']) ? (string) $discrColumn['length'] : null, 'columnDefinition' => isset($discrColumn['columnDefinition']) ? (string) $discrColumn['columnDefinition'] : null));
} else {
$metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));
}
// Evaluate discriminatorMap
if (isset($element['discriminatorMap'])) {
//.........这里部分代码省略.........
示例4: loadMetadataForClass
//.........这里部分代码省略.........
$entityResult = array('fields' => array(), 'entityClass' => $entityResultAnnot->entityClass, 'discriminatorColumn' => $entityResultAnnot->discriminatorColumn);
foreach ($entityResultAnnot->fields as $fieldResultAnnot) {
$entityResult['fields'][] = array('name' => $fieldResultAnnot->name, 'column' => $fieldResultAnnot->column);
}
$entities[] = $entityResult;
}
foreach ($resultSetMapping->columns as $columnResultAnnot) {
$columns[] = array('name' => $columnResultAnnot->name);
}
$metadata->addSqlResultSetMapping(array('name' => $resultSetMapping->name, 'entities' => $entities, 'columns' => $columns));
}
}
// Evaluate NamedQueries annotation
if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\NamedQueries'])) {
$namedQueriesAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\NamedQueries'];
if (!is_array($namedQueriesAnnot->value)) {
throw new \UnexpectedValueException("@NamedQueries should contain an array of @NamedQuery annotations.");
}
foreach ($namedQueriesAnnot->value as $namedQuery) {
if (!$namedQuery instanceof \Doctrine\ORM\Mapping\NamedQuery) {
throw new \UnexpectedValueException("@NamedQueries should contain an array of @NamedQuery annotations.");
}
$metadata->addNamedQuery(array('name' => $namedQuery->name, 'query' => $namedQuery->query));
}
}
// Evaluate InheritanceType annotation
if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\InheritanceType'])) {
$inheritanceTypeAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\InheritanceType'];
$metadata->setInheritanceType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceTypeAnnot->value));
if ($metadata->inheritanceType != \Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_NONE) {
// Evaluate DiscriminatorColumn annotation
if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorColumn'])) {
$discrColumnAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorColumn'];
$metadata->setDiscriminatorColumn(array('name' => $discrColumnAnnot->name, 'type' => $discrColumnAnnot->type ?: 'string', 'length' => $discrColumnAnnot->length ?: 255, 'columnDefinition' => $discrColumnAnnot->columnDefinition));
} else {
$metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));
}
// Evaluate DiscriminatorMap annotation
if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorMap'])) {
$discrMapAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\DiscriminatorMap'];
$metadata->setDiscriminatorMap($discrMapAnnot->value);
}
}
}
// Evaluate DoctrineChangeTrackingPolicy annotation
if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\ChangeTrackingPolicy'])) {
$changeTrackingAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\ChangeTrackingPolicy'];
$metadata->setChangeTrackingPolicy(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CHANGETRACKING_' . $changeTrackingAnnot->value));
}
// Evaluate annotations on properties/fields
/* @var $property \ReflectionProperty */
foreach ($class->getProperties() as $property) {
if ($metadata->isMappedSuperclass && !$property->isPrivate() || $metadata->isInheritedField($property->name) || $metadata->isInheritedAssociation($property->name) || $metadata->isInheritedEmbeddedClass($property->name)) {
continue;
}
$mapping = array();
$mapping['fieldName'] = $property->getName();
// Evaluate @Cache annotation
if (($cacheAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Cache')) !== null) {
$mapping['cache'] = $metadata->getAssociationCacheDefaults($mapping['fieldName'], array('usage' => constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CACHE_USAGE_' . $cacheAnnot->usage), 'region' => $cacheAnnot->region));
}
// Check for JoinColumn/JoinColumns annotations
$joinColumns = array();
if ($joinColumnAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\JoinColumn')) {
$joinColumns[] = $this->joinColumnToArray($joinColumnAnnot);
} else {
示例5: loadMetadataForClass
/**
* Loads the metadata for the specified class into the provided container.
*
* @param string $className
* @param ClassMetadata $metadata
*/
function loadMetadataForClass($className, ClassMetadata $metadata)
{
$moduleOptions = \SoliantEntityAudit\Module::getModuleOptions();
$entityManager = $moduleOptions->getEntityManager();
$metadataFactory = $entityManager->getMetadataFactory();
$builder = new ClassMetadataBuilder($metadata);
if ($className == 'SoliantEntityAudit\\Entity\\RevisionEntity') {
$builder->createField('id', 'integer')->isPrimaryKey()->generatedValue()->build();
$builder->addManyToOne('revision', 'SoliantEntityAudit\\Entity\\Revision', 'revisionEntities');
$builder->addField('entityKeys', 'string');
$builder->addField('auditEntityClass', 'string');
$builder->addField('targetEntityClass', 'string');
$builder->addField('revisionType', 'string');
$builder->addField('title', 'string', array('nullable' => true));
$metadata->setTableName($moduleOptions->getRevisionEntityTableName());
return;
}
// Revision is managed here rather than a separate namespace and driver
if ($className == 'SoliantEntityAudit\\Entity\\Revision') {
$builder->createField('id', 'integer')->isPrimaryKey()->generatedValue()->build();
$builder->addField('comment', 'text', array('nullable' => true));
$builder->addField('timestamp', 'datetime');
// Add association between RevisionEntity and Revision
$builder->addOneToMany('revisionEntities', 'SoliantEntityAudit\\Entity\\RevisionEntity', 'revision');
// Add assoication between User and Revision
$userMetadata = $metadataFactory->getMetadataFor($moduleOptions->getUserEntityClassName());
$builder->createManyToOne('user', $userMetadata->getName())->addJoinColumn('user_id', $userMetadata->getSingleIdentifierColumnName())->build();
$metadata->setTableName($moduleOptions->getRevisionTableName());
return;
}
# $builder->createField('audit_id', 'integer')->isPrimaryKey()->generatedValue()->build();
$identifiers = array();
# $metadata->setIdentifier(array('audit_id'));
// Build a discovered many to many join class
$joinClasses = $moduleOptions->getJoinClasses();
if (in_array($className, array_keys($joinClasses))) {
$builder->createField('id', 'integer')->isPrimaryKey()->generatedValue()->build();
$builder->addManyToOne('targetRevisionEntity', 'SoliantEntityAudit\\Entity\\RevisionEntity');
$builder->addManyToOne('sourceRevisionEntity', 'SoliantEntityAudit\\Entity\\RevisionEntity');
$metadata->setTableName($moduleOptions->getTableNamePrefix() . $joinClasses[$className]['joinTable']['name'] . $moduleOptions->getTableNameSuffix());
// $metadata->setIdentifier($identifiers);
return;
}
// Get the entity this entity audits
$metadataClassName = $metadata->getName();
$metadataClass = new $metadataClassName();
$auditedClassMetadata = $metadataFactory->getMetadataFor($metadataClass->getAuditedEntityClass());
try {
$builder->addManyToOne($moduleOptions->getRevisionEntityFieldName(), 'SoliantEntityAudit\\Entity\\RevisionEntity');
} catch (MappingException $e) {
// do nothing
}
// Compound keys removed in favor of auditId (audit_id)
$identifiers[] = $moduleOptions->getRevisionEntityFieldName();
// Add fields from target to audit entity
foreach ($auditedClassMetadata->getFieldNames() as $fieldName) {
$fieldMapping = $auditedClassMetadata->getFieldMapping($fieldName);
if (!isset($fieldMapping['inherited']) && !isset($fieldMapping['declared'])) {
$fieldMapping['nullable'] = true;
$fieldMapping['quoted'] = true;
$builder->addField($fieldName, $auditedClassMetadata->getTypeOfField($fieldName), $fieldMapping);
}
if ($auditedClassMetadata->isIdentifier($fieldName)) {
$identifiers[] = $fieldName;
}
}
foreach ($auditedClassMetadata->getAssociationMappings() as $mapping) {
if (!isset($mapping['inherited']) && !isset($mapping['declared'])) {
if (!$mapping['isOwningSide']) {
continue;
}
if (isset($mapping['joinTable'])) {
continue;
}
if (isset($mapping['joinTableColumns'])) {
foreach ($mapping['joinTableColumns'] as $field) {
$builder->addField($mapping['fieldName'], 'integer', array('nullable' => true, 'columnName' => $field));
}
} elseif (isset($mapping['joinColumnFieldNames'])) {
foreach ($mapping['joinColumnFieldNames'] as $field) {
$builder->addField($mapping['fieldName'], 'integer', array('nullable' => true, 'columnName' => $field));
}
} else {
throw new \Exception('Unhandled association mapping');
}
}
}
if ($auditedClassMetadata->isInheritanceTypeJoined() || $auditedClassMetadata->isInheritanceTypeSingleTable()) {
$metadata->setInheritanceType($auditedClassMetadata->inheritanceType);
$metadata->setDiscriminatorColumn($auditedClassMetadata->discriminatorColumn);
$parentAuditClasses = array();
$subAuditClasses = array();
foreach ($auditedClassMetadata->parentClasses as $idx => $parentClass) {
$parentAuditClass = 'SoliantEntityAudit\\Entity\\' . str_replace('\\', '_', $parentClass);
//.........这里部分代码省略.........