本文整理汇总了PHP中Doctrine\ORM\Mapping\ClassMetadata::getIdentifierFieldNames方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::getIdentifierFieldNames方法的具体用法?PHP ClassMetadata::getIdentifierFieldNames怎么用?PHP ClassMetadata::getIdentifierFieldNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::getIdentifierFieldNames方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createEntityMetadata
/**
* @param ClassMetadata $classMetadata
*
* @return EntityMetadata
*/
public function createEntityMetadata(ClassMetadata $classMetadata)
{
$entityMetadata = new EntityMetadata();
$entityMetadata->setClassName($classMetadata->name);
$entityMetadata->setIdentifierFieldNames($classMetadata->getIdentifierFieldNames());
return $entityMetadata;
}
示例2: writeClearedProperties
/**
* @param AbstractFile $file
* @param ClassMetadata $metadata
* @param object $entity
* @param array $properties
*/
protected function writeClearedProperties(AbstractFile $file, ClassMetadata $metadata, $entity, array $properties)
{
$cleared = $this->entityToArray($entity, $properties);
if ($cleared) {
$file->writeObject(['identifiers' => $this->entityToArray($entity, $metadata->getIdentifierFieldNames()), 'cleared' => $cleared]);
}
}
示例3: addDoctrineFields
/**
* @param EntityMetadata $entityMetadata
* @param ClassMetadata $classMetadata
*/
protected function addDoctrineFields(EntityMetadata $entityMetadata, ClassMetadata $classMetadata)
{
$fields = array_diff($classMetadata->getFieldNames(), $classMetadata->getIdentifierFieldNames(), $this->getDeletedFields($classMetadata->name));
foreach ($fields as $fieldName) {
$fieldMetadata = $this->metadataFactory->createFieldMetadata(array('field_name' => $fieldName), $classMetadata->getFieldMapping($fieldName));
$entityMetadata->addFieldMetadata($fieldMetadata);
}
}
示例4: getNamePrimaryKeyField
/**
* @param ClassMetadata $metadata
* @return mixed
*/
public function getNamePrimaryKeyField(ClassMetadata $metadata)
{
$idNames = $metadata->getIdentifierFieldNames();
if (count($idNames) !== 1) {
throw new Exception('Primary key for this entity is absent or contains few fields');
}
return $idNames[0];
}
示例5: createEntityMetadata
/**
* @param ClassMetadata $classMetadata
*
* @return EntityMetadata
*/
public function createEntityMetadata(ClassMetadata $classMetadata)
{
$entityMetadata = new EntityMetadata();
$entityMetadata->setClassName($classMetadata->name);
$entityMetadata->setIdentifierFieldNames($classMetadata->getIdentifierFieldNames());
$entityMetadata->setInheritedType($classMetadata->inheritanceType !== ClassMetadata::INHERITANCE_TYPE_NONE);
return $entityMetadata;
}
示例6: getNamePrimaryKeyField
/**
* @param ClassMetadata $metadata
* @return mixed
*/
public function getNamePrimaryKeyField(ClassMetadata $metadata)
{
$idNames = $metadata->getIdentifierFieldNames();
if (count($idNames) !== 1) {
throw new RuntimeException(sprintf('Primary key for entity %s is absent or contains more than one field', $metadata->getName()));
}
return $idNames[0];
}
示例7: addDoctrineFields
/**
* @param EntityMetadata $entityMetadata
* @param ClassMetadata $classMetadata
*/
protected function addDoctrineFields(EntityMetadata $entityMetadata, ClassMetadata $classMetadata)
{
$identifierFields = $classMetadata->getIdentifierFieldNames();
foreach ($classMetadata->getFieldNames() as $fieldName) {
if (in_array($fieldName, $identifierFields)) {
continue;
}
$fieldMetadata = $this->metadataFactory->createFieldMetadata(array('field_name' => $fieldName), $classMetadata->getFieldMapping($fieldName));
$entityMetadata->addFieldMetadata($fieldMetadata);
}
}
示例8: dispatchPostCreateEntityEvent
/**
* @param ClassMetadata $classMetaData
* @param array $data
* @return $this
*/
protected function dispatchPostCreateEntityEvent(ClassMetadata $classMetaData, array $data)
{
$identifiers = [];
foreach ($classMetaData->getIdentifierFieldNames() as $identifier) {
if (array_key_exists($identifier, $data)) {
$identifiers[$identifier] = $data[$identifier];
}
}
$eventArgs = new PostCreateEntityEventArgs(get_class($this), $classMetaData->name, $identifiers);
$this->getEntityManager()->getEventManager()->dispatchEvent(PostCreateEntityEventArgs::EVENT_NAME, $eventArgs);
return $this;
}
示例9: getDefiningClass
/**
* Get the class metadata that is responsible for the definition of the referenced column name.
*
* Previously this was a simple task, but with DDC-117 this problem is actually recursive. If its
* not a simple field, go through all identifier field names that are associations recursivly and
* find that referenced column name.
*
* TODO: Is there any way to make this code more pleasing?
*
* @param ClassMetadata $class
* @param string $referencedColumnName
* @return array(ClassMetadata, referencedFieldName)
*/
private function getDefiningClass($class, $referencedColumnName)
{
$referencedFieldName = $class->getFieldName($referencedColumnName);
if ($class->hasField($referencedFieldName)) {
return array($class, $referencedFieldName);
} else {
if (in_array($referencedColumnName, $class->getIdentifierColumnNames())) {
// it seems to be an entity as foreign key
foreach ($class->getIdentifierFieldNames() as $fieldName) {
if ($class->hasAssociation($fieldName) && $class->getSingleAssociationJoinColumnName($fieldName) == $referencedColumnName) {
return $this->getDefiningClass($this->em->getClassMetadata($class->associationMappings[$fieldName]['targetEntity']), $class->getSingleAssociationReferencedJoinColumnName($fieldName));
}
}
}
}
return null;
}
示例10: delete
/**
* Deletes an entity.
*
* @param object $entity The entity to delete.
*/
public function delete($entity)
{
$id = array_combine($this->_class->getIdentifierFieldNames(), $this->_em->getUnitOfWork()->getEntityIdentifier($entity));
$this->_conn->delete($this->_class->primaryTable['name'], $id);
}
示例11: isAutogeneratedIdField
/**
* @param $field
* @param $meta
* @return bool
*/
protected function isAutogeneratedIdField($field, ClassMetadata $meta)
{
$isIdentifierField = in_array($field, $meta->getIdentifierFieldNames());
$isAutoGenerated = $meta->generatorType !== ClassMetadata::GENERATOR_TYPE_NONE;
return $isIdentifierField && $isAutoGenerated;
}
示例12: getIdentifier
/**
* Get identifier.
*
* @param ClassMetadata $metadata
*
* @return mixed
*/
private function getIdentifier(ClassMetadata $metadata)
{
$identifiers = $metadata->getIdentifierFieldNames();
return array_shift($identifiers);
}
示例13: getIdentifierFieldNames
/**
* Returns names of entity identifier fields
*
* @return string[]
*/
public function getIdentifierFieldNames()
{
return $this->metadata->getIdentifierFieldNames();
}
示例14: _gatherColumn
/**
* Creates a column definition as required by the DBAL from an ORM field mapping definition.
*
* @param ClassMetadata $class The class that owns the field mapping.
* @param array $mapping The field mapping.
* @param Table $table
* @return array The portable column definition as required by the DBAL.
*/
private function _gatherColumn($class, array $mapping, $table)
{
$columnName = $class->getQuotedColumnName($mapping['fieldName'], $this->_platform);
$columnType = $mapping['type'];
$options = array();
$options['length'] = isset($mapping['length']) ? $mapping['length'] : null;
$options['notnull'] = isset($mapping['nullable']) ? !$mapping['nullable'] : true;
if ($class->isInheritanceTypeSingleTable() && count($class->parentClasses) > 0) {
$options['notnull'] = false;
}
$options['platformOptions'] = array();
$options['platformOptions']['version'] = $class->isVersioned && $class->versionField == $mapping['fieldName'] ? true : false;
if (strtolower($columnType) == 'string' && $options['length'] === null) {
$options['length'] = 255;
}
if (isset($mapping['precision'])) {
$options['precision'] = $mapping['precision'];
}
if (isset($mapping['scale'])) {
$options['scale'] = $mapping['scale'];
}
if (isset($mapping['default'])) {
$options['default'] = $mapping['default'];
}
if (isset($mapping['columnDefinition'])) {
$options['columnDefinition'] = $mapping['columnDefinition'];
}
if ($class->isIdGeneratorIdentity() && $class->getIdentifierFieldNames() == array($mapping['fieldName'])) {
$options['autoincrement'] = true;
}
if ($class->isInheritanceTypeJoined() && $class->name != $class->rootEntityName) {
$options['autoincrement'] = false;
}
if ($table->hasColumn($columnName)) {
// required in some inheritance scenarios
$table->changeColumn($columnName, $options);
} else {
$table->addColumn($columnName, $columnType, $options);
}
$isUnique = isset($mapping['unique']) ? $mapping['unique'] : false;
if ($isUnique) {
$table->addUniqueIndex(array($columnName));
}
}
示例15: getIndexedFields
/**
* Gets a list of all indexed fields
*
* @param ClassMetadata $metadata
*
* @return array [field name => field data-type, ...]
*/
public function getIndexedFields(ClassMetadata $metadata)
{
$indexedColumns = [];
$idFieldNames = $metadata->getIdentifierFieldNames();
if (count($idFieldNames) > 0) {
$indexedColumns[reset($idFieldNames)] = true;
}
if (isset($metadata->table['indexes'])) {
foreach ($metadata->table['indexes'] as $index) {
$firstFieldName = reset($index['columns']);
if (!isset($indexedColumns[$firstFieldName])) {
$indexedColumns[$firstFieldName] = true;
}
}
}
$fields = [];
$fieldNames = $metadata->getFieldNames();
foreach ($fieldNames as $fieldName) {
$mapping = $metadata->getFieldMapping($fieldName);
$hasIndex = false;
if (isset($mapping['unique']) && true === $mapping['unique']) {
$hasIndex = true;
} elseif (array_key_exists($mapping['columnName'], $indexedColumns)) {
$hasIndex = true;
}
if ($hasIndex) {
$fields[$fieldName] = $mapping['type'];
}
}
return $fields;
}