本文整理汇总了PHP中Doctrine\Common\Persistence\Mapping\ClassMetadata::setTableName方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::setTableName方法的具体用法?PHP ClassMetadata::setTableName怎么用?PHP ClassMetadata::setTableName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Persistence\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::setTableName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadMetadataForClass
/**
* Load the metadata for the specified class into the provided container.
*
* @param string $className
* @param ClassMetadata $metadata
*/
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
$metadataFactory = $this->getObjectManager()->getMetadataFactory();
$builder = new ClassMetadataBuilder($metadata);
$identifiers = array();
// Get the entity this entity audits
$metadataClassName = $metadata->getName();
$metadataClass = new $metadataClassName();
$auditedClassMetadata = $metadataFactory->getMetadataFor($metadataClass->getAuditedEntityClass());
$builder->addManyToOne('revisionEntity', 'ZF\\Doctrine\\Audit\\Entity\\RevisionEntity');
$identifiers[] = 'revisionEntity';
// Add fields from target to audit entity
foreach ($auditedClassMetadata->getFieldNames() as $fieldName) {
$builder->addField($fieldName, $auditedClassMetadata->getTypeOfField($fieldName), array('columnName' => $auditedClassMetadata->getColumnName($fieldName), 'nullable' => true, 'quoted' => true));
if ($auditedClassMetadata->isIdentifier($fieldName)) {
$identifiers[] = $fieldName;
}
}
foreach ($auditedClassMetadata->getAssociationMappings() as $mapping) {
if (!$mapping['isOwningSide'] || isset($mapping['joinTable'])) {
continue;
}
if (isset($mapping['joinTableColumns'])) {
foreach ($mapping['joinTableColumns'] as $field) {
// FIXME: set data type correct for mapping info
$builder->addField($mapping['fieldName'], 'bigint', array('nullable' => true, 'columnName' => $field));
}
} elseif (isset($mapping['joinColumnFieldNames'])) {
foreach ($mapping['joinColumnFieldNames'] as $field) {
// FIXME: set data type correct for mapping info
$builder->addField($mapping['fieldName'], 'bigint', array('nullable' => true, 'columnName' => $field));
}
} else {
throw new Exception('Unhandled association mapping');
}
}
$metadata->setTableName($this->getAuditOptions()['audit_table_name_prefix'] . $auditedClassMetadata->getTableName() . $this->getAuditOptions()['audit_table_name_suffix']);
$metadata->setIdentifier($identifiers);
return;
}
示例2: 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);
//.........这里部分代码省略.........
示例3: loadMetadataForClass
/**
* Loads the metadata for the specified class into the provided container.
*
* @param string $className
* @param ClassMetadata $metadata
*/
function loadMetadataForClass($className, ClassMetadata $metadata)
{
$moduleOptions = \ZF\Doctrine\Audit\Module::getModuleOptions();
$entityManager = $moduleOptions->getEntityManager();
$metadataFactory = $entityManager->getMetadataFactory();
$builder = new ClassMetadataBuilder($metadata);
if ($className == 'ZF\\Doctrine\\Audit\\Entity\\RevisionEntity') {
$builder->createField('id', 'integer')->isPrimaryKey()->generatedValue()->build();
$builder->addManyToOne('revision', 'ZF\\Doctrine\\Audit\\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 == 'ZF\\Doctrine\\Audit\\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', 'ZF\\Doctrine\\Audit\\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', 'ZF\\Doctrine\\Audit\\Entity\\RevisionEntity');
$builder->addManyToOne('sourceRevisionEntity', 'ZF\\Doctrine\\Audit\\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());
$builder->addManyToOne($moduleOptions->getRevisionEntityFieldName(), 'ZF\\Doctrine\\Audit\\Entity\\RevisionEntity');
# Compound keys removed in favor of auditId (audit_id)
$identifiers[] = $moduleOptions->getRevisionEntityFieldName();
// Add fields from target to audit entity
foreach ($auditedClassMetadata->getFieldNames() as $fieldName) {
$builder->addField($fieldName, $auditedClassMetadata->getTypeOfField($fieldName), array('nullable' => true, 'quoted' => true));
if ($auditedClassMetadata->isIdentifier($fieldName)) {
$identifiers[] = $fieldName;
}
}
foreach ($auditedClassMetadata->getAssociationMappings() as $mapping) {
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');
}
}
$metadata->setTableName($moduleOptions->getTableNamePrefix() . $auditedClassMetadata->getTableName() . $moduleOptions->getTableNameSuffix());
$metadata->setIdentifier($identifiers);
return;
}