本文整理汇总了PHP中Doctrine\ORM\Mapping\ClassMetadata::getFieldForColumn方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::getFieldForColumn方法的具体用法?PHP ClassMetadata::getFieldForColumn怎么用?PHP ClassMetadata::getFieldForColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::getFieldForColumn方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: hydrate
/**
* @param object $entity
* @param array $queryResult
* @return object
* @throws \Doctrine\DBAL\DBALException
* @throws \Doctrine\ORM\Mapping\MappingException
*/
public function hydrate($entity, $queryResult)
{
$platform = $this->em->getConnection()->getDatabasePlatform();
foreach ($queryResult as $columnName => $value) {
$fieldName = $this->metaData->getFieldForColumn($columnName);
$typeForField = $this->metaData->getTypeOfField($fieldName);
if ($typeForField) {
$type = Type::getType($typeForField);
$entity->{$fieldName} = $type->convertToPHPValue($value, $platform);
} else {
throw new RuntimeException('Unknown type for field ' . $fieldName);
}
}
return $entity;
}
示例2: update
/**
* @param object $entity
* @return int
* @throws \Doctrine\ORM\Mapping\MappingException
*/
public function update($entity)
{
$identifiers = [];
$types = ['id' => \PDO::PARAM_INT];
foreach ($this->metaData->getIdentifierColumnNames() as $columnName) {
$fieldName = $this->metaData->getFieldForColumn($columnName);
$value = $this->metaData->getFieldValue($entity, $fieldName);
$identifiers[$columnName] = $value;
}
$updateSet = [];
foreach ($this->metaData->getColumnNames() as $columnName) {
if (isset($identifiers[$columnName])) {
continue;
}
$fieldName = $this->metaData->getFieldForColumn($columnName);
$typeName = $this->metaData->getTypeOfColumn($fieldName);
$type = \Doctrine\DBAL\Types\Type::getType($typeName);
$value = $type->convertToDatabaseValue($entity->{$fieldName}, $this->em->getConnection()->getDatabasePlatform());
$types[$columnName] = $type->getBindingType();
$updateSet[$columnName] = $value;
}
return $this->em->getConnection()->update($this->metaData->getTableName(), $updateSet, $identifiers, $types);
}