本文整理汇总了PHP中Doctrine\ORM\Mapping\ClassMetadataInfo::getIdentifierColumnNames方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadataInfo::getIdentifierColumnNames方法的具体用法?PHP ClassMetadataInfo::getIdentifierColumnNames怎么用?PHP ClassMetadataInfo::getIdentifierColumnNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Mapping\ClassMetadataInfo
的用法示例。
在下文中一共展示了ClassMetadataInfo::getIdentifierColumnNames方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateClass
/**
* Validate a single class of the current
*
* @param ClassMetadataInfo $class
* @return array
*/
public function validateClass(ClassMetadataInfo $class)
{
$ce = array();
$cmf = $this->em->getMetadataFactory();
foreach ($class->fieldMappings as $fieldName => $mapping) {
if (!Type::hasType($mapping['type'])) {
$ce[] = "The field '" . $class->name . "#" . $fieldName . "' uses a non-existant type '" . $mapping['type'] . "'.";
}
}
foreach ($class->associationMappings as $fieldName => $assoc) {
if (!class_exists($assoc['targetEntity']) || $cmf->isTransient($assoc['targetEntity'])) {
$ce[] = "The target entity '" . $assoc['targetEntity'] . "' specified on " . $class->name . '#' . $fieldName . ' is unknown or not an entity.';
return $ce;
}
if ($assoc['mappedBy'] && $assoc['inversedBy']) {
$ce[] = "The association " . $class . "#" . $fieldName . " cannot be defined as both inverse and owning.";
}
$targetMetadata = $cmf->getMetadataFor($assoc['targetEntity']);
if (isset($assoc['id']) && $targetMetadata->containsForeignIdentifier) {
$ce[] = "Cannot map association '" . $class->name . "#" . $fieldName . " as identifier, because " . "the target entity '" . $targetMetadata->name . "' also maps an association as identifier.";
}
/* @var $assoc AssociationMapping */
if ($assoc['mappedBy']) {
if ($targetMetadata->hasField($assoc['mappedBy'])) {
$ce[] = "The association " . $class->name . "#" . $fieldName . " refers to the owning side " . "field " . $assoc['targetEntity'] . "#" . $assoc['mappedBy'] . " which is not defined as association.";
}
if (!$targetMetadata->hasAssociation($assoc['mappedBy'])) {
$ce[] = "The association " . $class->name . "#" . $fieldName . " refers to the owning side " . "field " . $assoc['targetEntity'] . "#" . $assoc['mappedBy'] . " which does not exist.";
} else {
if ($targetMetadata->associationMappings[$assoc['mappedBy']]['inversedBy'] == null) {
$ce[] = "The field " . $class->name . "#" . $fieldName . " is on the inverse side of a " . "bi-directional relationship, but the specified mappedBy association on the target-entity " . $assoc['targetEntity'] . "#" . $assoc['mappedBy'] . " does not contain the required " . "'inversedBy=" . $fieldName . "' attribute.";
} else {
if ($targetMetadata->associationMappings[$assoc['mappedBy']]['inversedBy'] != $fieldName) {
$ce[] = "The mappings " . $class->name . "#" . $fieldName . " and " . $assoc['targetEntity'] . "#" . $assoc['mappedBy'] . " are " . "incosistent with each other.";
}
}
}
}
if ($assoc['inversedBy']) {
if ($targetMetadata->hasField($assoc['inversedBy'])) {
$ce[] = "The association " . $class->name . "#" . $fieldName . " refers to the inverse side " . "field " . $assoc['targetEntity'] . "#" . $assoc['inversedBy'] . " which is not defined as association.";
}
if (!$targetMetadata->hasAssociation($assoc['inversedBy'])) {
$ce[] = "The association " . $class->name . "#" . $fieldName . " refers to the inverse side " . "field " . $assoc['targetEntity'] . "#" . $assoc['inversedBy'] . " which does not exist.";
} else {
if ($targetMetadata->associationMappings[$assoc['inversedBy']]['mappedBy'] == null) {
$ce[] = "The field " . $class->name . "#" . $fieldName . " is on the owning side of a " . "bi-directional relationship, but the specified mappedBy association on the target-entity " . $assoc['targetEntity'] . "#" . $assoc['mappedBy'] . " does not contain the required " . "'inversedBy' attribute.";
} else {
if ($targetMetadata->associationMappings[$assoc['inversedBy']]['mappedBy'] != $fieldName) {
$ce[] = "The mappings " . $class->name . "#" . $fieldName . " and " . $assoc['targetEntity'] . "#" . $assoc['inversedBy'] . " are " . "incosistent with each other.";
}
}
}
// Verify inverse side/owning side match each other
if (array_key_exists($assoc['inversedBy'], $targetMetadata->associationMappings)) {
$targetAssoc = $targetMetadata->associationMappings[$assoc['inversedBy']];
if ($assoc['type'] == ClassMetadataInfo::ONE_TO_ONE && $targetAssoc['type'] !== ClassMetadataInfo::ONE_TO_ONE) {
$ce[] = "If association " . $class->name . "#" . $fieldName . " is one-to-one, then the inversed " . "side " . $targetMetadata->name . "#" . $assoc['inversedBy'] . " has to be one-to-one as well.";
} else {
if ($assoc['type'] == ClassMetadataInfo::MANY_TO_ONE && $targetAssoc['type'] !== ClassMetadataInfo::ONE_TO_MANY) {
$ce[] = "If association " . $class->name . "#" . $fieldName . " is many-to-one, then the inversed " . "side " . $targetMetadata->name . "#" . $assoc['inversedBy'] . " has to be one-to-many.";
} else {
if ($assoc['type'] == ClassMetadataInfo::MANY_TO_MANY && $targetAssoc['type'] !== ClassMetadataInfo::MANY_TO_MANY) {
$ce[] = "If association " . $class->name . "#" . $fieldName . " is many-to-many, then the inversed " . "side " . $targetMetadata->name . "#" . $assoc['inversedBy'] . " has to be many-to-many as well.";
}
}
}
}
}
if ($assoc['isOwningSide']) {
if ($assoc['type'] == ClassMetadataInfo::MANY_TO_MANY) {
$identifierColumns = $class->getIdentifierColumnNames();
foreach ($assoc['joinTable']['joinColumns'] as $joinColumn) {
if (!in_array($joinColumn['referencedColumnName'], $identifierColumns)) {
$ce[] = "The referenced column name '" . $joinColumn['referencedColumnName'] . "' " . "has to be a primary key column on the target entity class '" . $class->name . "'.";
break;
}
}
$identifierColumns = $targetMetadata->getIdentifierColumnNames();
foreach ($assoc['joinTable']['inverseJoinColumns'] as $inverseJoinColumn) {
if (!in_array($inverseJoinColumn['referencedColumnName'], $identifierColumns)) {
$ce[] = "The referenced column name '" . $joinColumn['referencedColumnName'] . "' " . "has to be a primary key column on the target entity class '" . $targetMetadata->name . "'.";
break;
}
}
if (count($targetMetadata->getIdentifierColumnNames()) != count($assoc['joinTable']['inverseJoinColumns'])) {
$ce[] = "The inverse join columns of the many-to-many table '" . $assoc['joinTable']['name'] . "' " . "have to contain to ALL identifier columns of the target entity '" . $targetMetadata->name . "', " . "however '" . implode(", ", array_diff($targetMetadata->getIdentifierColumnNames(), array_values($assoc['relationToTargetKeyColumns']))) . "' are missing.";
}
if (count($class->getIdentifierColumnNames()) != count($assoc['joinTable']['joinColumns'])) {
$ce[] = "The join columns of the many-to-many table '" . $assoc['joinTable']['name'] . "' " . "have to contain to ALL identifier columns of the source entity '" . $class->name . "', " . "however '" . implode(", ", array_diff($class->getIdentifierColumnNames(), array_values($assoc['relationToSourceKeyColumns']))) . "' are missing.";
}
} else {
if ($assoc['type'] & ClassMetadataInfo::TO_ONE) {
$identifierColumns = $targetMetadata->getIdentifierColumnNames();
//.........这里部分代码省略.........
示例2: initialize
protected function initialize()
{
if (!$this->initialized) {
$params = array();
$sql = 'SELECT MAX(' . $this->configuration->getRevisionFieldName() . ') as rev, ';
$sql .= $this->configuration->getRevisionTypeFieldName() . ' AS revtype, ';
$sql .= implode(', ', $this->metadata->getIdentifierColumnNames()) . ' ';
if (isset($this->associationDefinition['indexBy'])) {
$sql .= ', ' . $this->associationDefinition['indexBy'] . ' ';
}
$sql .= 'FROM ' . $this->configuration->getTablePrefix() . $this->metadata->table['name'] . $this->configuration->getTableSuffix() . ' t ';
$sql .= 'WHERE ' . $this->configuration->getRevisionFieldName() . ' <= ' . $this->revision . ' ';
foreach ($this->foreignKeys as $column => $value) {
$sql .= 'AND ' . $column . ' = ? ';
$params[] = $value;
}
//we check for revisions greater than current belonging to other entities
$sql .= 'AND NOT EXISTS (SELECT * FROM ' . $this->configuration->getTablePrefix() . $this->metadata->table['name'] . $this->configuration->getTableSuffix() . ' st WHERE';
//ids
foreach ($this->metadata->getIdentifierColumnNames() as $name) {
$sql .= ' st.' . $name . ' = t.' . $name . ' AND';
}
//foreigns
$sql .= ' ((';
//master entity query, not equals
$notEqualParts = $nullParts = array();
foreach ($this->foreignKeys as $column => $value) {
$notEqualParts[] = $column . ' <> ?';
$nullParts[] = $column . ' IS NULL';
$params[] = $value;
}
$sql .= implode(' AND ', $notEqualParts) . ') OR (' . implode(' AND ', $nullParts) . '))';
//revision
$sql .= ' AND st.' . $this->configuration->getRevisionFieldName() . ' <= ' . $this->revision;
$sql .= ' AND st.' . $this->configuration->getRevisionFieldName() . ' > t.' . $this->configuration->getRevisionFieldName();
$sql .= ') ';
//end of check for for belonging to other entities
//check for deleted revisions older than requested
$sql .= 'AND NOT EXISTS (SELECT * FROM ' . $this->configuration->getTablePrefix() . $this->metadata->table['name'] . $this->configuration->getTableSuffix() . ' sd WHERE';
//ids
foreach ($this->metadata->getIdentifierColumnNames() as $name) {
$sql .= ' sd.' . $name . ' = t.' . $name . ' AND';
}
//revision
$sql .= ' sd.' . $this->configuration->getRevisionFieldName() . ' <= ' . $this->revision;
$sql .= ' AND sd.' . $this->configuration->getRevisionFieldName() . ' > t.' . $this->configuration->getRevisionFieldName();
$sql .= ' AND sd.' . $this->configuration->getRevisionTypeFieldName() . ' = ?';
$params[] = 'DEL';
$sql .= ') ';
//end check for deleted revisions older than requested
$sql .= 'GROUP BY ' . implode(', ', $this->metadata->getIdentifierColumnNames()) . ' ';
$sql .= 'HAVING ' . $this->configuration->getRevisionTypeFieldName() . ' <> ?';
//add rev type parameter
$params[] = 'DEL';
$rows = $this->auditReader->getConnection()->fetchAll($sql, $params);
foreach ($rows as $row) {
$entity = array('rev' => $row['rev'], 'revtype' => $row['revtype']);
unset($row['rev'], $row['revtype']);
$entity['keys'] = $row;
if (isset($this->associationDefinition['indexBy'])) {
$key = $row[$this->associationDefinition['indexBy']];
unset($entity['keys'][$this->associationDefinition['indexBy']]);
$this->entities[$key] = $entity;
} else {
$this->entities[] = $entity;
}
}
$this->initialized = true;
}
}