本文整理汇总了PHP中Doctrine\ORM\Mapping\ClassMetadata::getColumnName方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::getColumnName方法的具体用法?PHP ClassMetadata::getColumnName怎么用?PHP ClassMetadata::getColumnName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::getColumnName方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepareSet
/**
* @param $entity
* @return array
*/
protected function prepareSet($entity)
{
$data = [];
foreach ($this->metaData->getFieldNames() as $fieldName) {
$columnName = $this->metaData->getColumnName($fieldName);
$type = $this->metaData->getTypeOfField($fieldName);
$fieldValue = $entity->{$fieldName};
$type = \Doctrine\DBAL\Types\Type::getType($type);
$value = $type->convertToDatabaseValue($fieldValue, $this->em->getConnection()->getDatabasePlatform());
$data[$columnName] = $value;
}
return $data;
}
示例2: _assignDefaultVersionValue
/**
* Retrieves the default version value which was created
* by the preceding INSERT statement and assigns it back in to the
* entities version field.
*
* @param Doctrine\ORM\Mapping\ClassMetadata $class
* @param object $entity
* @param mixed $id
*/
protected function _assignDefaultVersionValue($class, $entity, $id)
{
$versionField = $this->_class->versionField;
$identifier = $this->_class->getIdentifierColumnNames();
$versionFieldColumnName = $this->_class->getColumnName($versionField);
//FIXME: Order with composite keys might not be correct
$sql = "SELECT " . $versionFieldColumnName . " FROM " . $class->getQuotedTableName($this->_platform) . " WHERE " . implode(' = ? AND ', $identifier) . " = ?";
$value = $this->_conn->fetchColumn($sql, array_values((array) $id));
$this->_class->setFieldValue($entity, $versionField, $value);
}
示例3: _prepareData
/**
* Prepares the data changeset of an entity for database insertion.
*
* @param object $entity
* @param boolean $isInsert Whether the preparation is for an INSERT (or UPDATE, if FALSE).
*
* return The reference to the data array.
* @access private
*
* @author Etienne de Longeaux <etienne.delongeaux@gmail.com>
*/
private function _prepareData($entity, $isInsert = false)
{
$result = array();
$platform = $this->_conn->getDatabasePlatform();
$uow = $this->_em->getUnitOfWork();
foreach ($this->_reflFields as $field => $ReflectionProperty) {
$newVal = $this->_class->getFieldValue($entity, $field);
$columnName = $this->_class->getColumnName($field);
if (isset($this->_class->associationMappings[$field])) {
$assocMapping = $this->_class->associationMappings[$field];
// Only owning side of x-1 associations can have a FK column.
if (!$assocMapping['isOwningSide']) {
continue;
}
// Special case: One-one self-referencing of the same class with IDENTITY type key generation.
if ($this->_class->isIdGeneratorIdentity() && $newVal !== null && $assocMapping['sourceEntity'] == $assocMapping['targetEntity']) {
$oid = spl_object_hash($newVal);
$isScheduledForInsert = $uow->isScheduledForInsert($newVal);
if (isset($this->_queuedInserts[$oid]) || $isScheduledForInsert) {
// The associated entity $newVal is not yet persisted, so we must
// set $newVal = null, in order to insert a null value and schedule an
// extra update on the UnitOfWork.
$uow->scheduleExtraUpdate($entity, array($field => array(null, $newVal)));
$newVal = null;
} else {
if ($isInsert && !$isScheduledForInsert && $uow->getEntityState($newVal) == UnitOfWork::STATE_MANAGED) {
// $newVal is already fully persisted.
// Schedule an extra update for it, so that the foreign key(s) are properly set.
$uow->scheduleExtraUpdate($newVal, array($field => array(null, $entity)));
}
}
}
foreach ($assocMapping['sourceToTargetKeyColumns'] as $sourceColumn => $targetColumn) {
if ($newVal === null) {
$result[$sourceColumn] = null;
} else {
$otherClass = $this->_em->getClassMetadata($assocMapping['targetEntity']);
$result[$sourceColumn] = $otherClass->reflFields[$otherClass->fieldNames[$targetColumn]]->getValue($newVal);
}
}
} else {
if ($newVal === null) {
$result[$columnName] = null;
} else {
$result[$columnName] = Type::getType($this->_class->fieldMappings[$field]['type'])->convertToDatabaseValue($newVal, $platform);
}
}
}
return $result;
}
示例4: _prepareData
/**
* Prepares the data changeset of an entity for database insertion.
* The array that is passed as the second parameter is filled with
* <columnName> => <value> pairs, grouped by table name, during this preparation.
*
* Example:
* <code>
* array(
* 'foo_table' => array('column1' => 'value1', 'column2' => 'value2', ...),
* 'bar_table' => array('columnX' => 'valueX', 'columnY' => 'valueY', ...),
* ...
* )
* </code>
*
* Notes to inheritors: Be sure to call <code>parent::_prepareData($entity, $result, $isInsert);</code>
*
* @param object $entity
* @param array $result The reference to the data array.
* @param boolean $isInsert
*/
protected function _prepareData($entity, array &$result, $isInsert = false)
{
$platform = $this->_conn->getDatabasePlatform();
$uow = $this->_em->getUnitOfWork();
foreach ($uow->getEntityChangeSet($entity) as $field => $change) {
$oldVal = $change[0];
$newVal = $change[1];
$columnName = $this->_class->getColumnName($field);
if (isset($this->_class->associationMappings[$field])) {
$assocMapping = $this->_class->associationMappings[$field];
// Only owning side of x-1 associations can have a FK column.
if (!$assocMapping->isOneToOne() || $assocMapping->isInverseSide()) {
continue;
}
//TODO: If the one-one is self-referencing, check whether the referenced entity ($newVal)
// is still scheduled for insertion. If so:
// 1) set $newVal = null, so that we insert a null value
// 2) schedule $entity for an update, so that the FK gets set through an update
// later, after the referenced entity has been inserted.
//$needsPostponedUpdate = ...
/*if ($assocMapping->sourceEntityName == $assocMapping->targetEntityName &&
isset($this->_queuedInserts[spl_object_hash($entity)])) {
echo "SELF-REFERENCING!";
}*/
foreach ($assocMapping->sourceToTargetKeyColumns as $sourceColumn => $targetColumn) {
$otherClass = $this->_em->getClassMetadata($assocMapping->targetEntityName);
if ($newVal === null) {
$result[$this->getOwningTable($field)][$sourceColumn] = null;
} else {
$result[$this->getOwningTable($field)][$sourceColumn] = $otherClass->reflFields[$otherClass->fieldNames[$targetColumn]]->getValue($newVal);
}
}
} else {
if ($newVal === null) {
$result[$this->getOwningTable($field)][$columnName] = null;
} else {
$result[$this->getOwningTable($field)][$columnName] = Type::getType($this->_class->fieldMappings[$field]['type'])->convertToDatabaseValue($newVal, $platform);
}
}
}
}
示例5: fetchVersionValue
/**
* Fetch the current version value of a versioned entity.
*
* @param Doctrine\ORM\Mapping\ClassMetadata $versionedClass
* @param mixed $id
* @return mixed
*/
protected function fetchVersionValue($versionedClass, $id)
{
$versionField = $versionedClass->versionField;
$identifier = $versionedClass->getIdentifierColumnNames();
$versionFieldColumnName = $versionedClass->getColumnName($versionField);
//FIXME: Order with composite keys might not be correct
$sql = "SELECT " . $versionFieldColumnName . " FROM " . $versionedClass->getQuotedTableName($this->_platform) . " WHERE " . implode(' = ? AND ', $identifier) . " = ?";
$value = $this->_conn->fetchColumn($sql, array_values((array) $id));
return Type::getType($versionedClass->fieldMappings[$versionField]['type'])->convertToPHPValue($value, $this->_platform);
}
示例6: initializeExtendedFieldsOptions
/**
* Initialize extended field options by field.
*
* @param ClassMetadata $classMetadata
*/
protected function initializeExtendedFieldsOptions(ClassMetadata $classMetadata)
{
$configManager = $this->getConfigManager();
$className = $classMetadata->getName();
$tableName = $classMetadata->getTableName();
foreach ($classMetadata->getFieldNames() as $fieldName) {
if ($configManager->hasConfig($className, $fieldName)) {
$columnName = $classMetadata->getColumnName($fieldName);
$options = $this->getExtendedFieldOptions($className, $fieldName);
if (!empty($options['extend']['is_extend'])) {
$this->extendedFieldOptions[$tableName][$columnName] = $options;
}
}
}
}
示例7: determineFromColumns
private function determineFromColumns(ClassMetadata $classMetadata)
{
$out = [];
/** @var Column $column */
foreach ($classMetadata->getFieldNames() as $fieldName) {
$fieldMapping = [];
try {
$fieldMapping = $classMetadata->getFieldMapping($fieldName);
} catch (MappingException $e) {
$fieldMapping['type'] = 'undefined';
}
$columnName = $classMetadata->getColumnName($fieldName);
$type = $classMetadata->getTypeOfField($fieldName);
$isNullable = $classMetadata->isNullable($fieldName);
if (strtolower($type) === 'enum') {
$out[$columnName] = ['type' => IColumnStructure::ENUM];
$enum = $fieldMapping['columnDefinition'];
$options = str_getcsv(str_replace('enum(', '', substr($enum, 0, strlen($enum) - 1)), ',', "'");
$out[$columnName]['values'] = [];
foreach ($options as $option) {
$out[$columnName]['values'][] = $option;
}
} else {
switch ($type) {
case Type::STRING:
case Type::TEXT:
$out[$columnName] = ['type' => IColumnStructure::TEXT];
break;
case Type::INTEGER:
case Type::FLOAT:
case Type::SMALLINT:
case Type::BIGINT:
case Type::DECIMAL:
$out[$columnName] = ['type' => IColumnStructure::NUMBER];
break;
case Type::DATETIME:
case Type::DATETIMETZ:
case Type::DATE:
case Type::TIME:
$out[$columnName] = ['type' => IColumnStructure::DATE];
break;
case Type::BOOLEAN:
$out[$columnName] = ['type' => IColumnStructure::BOOL];
break;
}
}
if (isset($out[$columnName])) {
$out[$columnName]['nullable'] = $isNullable;
}
}
return $out;
}