1
0
mirror of synced 2025-02-21 14:43:14 +03:00

Highlighted intention of converting scalar types during single scalar or scalar hydration, but leaving it commented and added a note about the BC reason why we cannot do that for 2.X series.

This commit is contained in:
Guilherme Blanco 2014-04-23 18:04:53 +00:00
parent 9ec54b8fed
commit a4dac7a292

View File

@ -263,7 +263,7 @@ abstract class AbstractHydrator
$cache[$key]['isIdentifier'] = $classMetadata->isIdentifier($fieldName); $cache[$key]['isIdentifier'] = $classMetadata->isIdentifier($fieldName);
$cache[$key]['dqlAlias'] = $this->_rsm->columnOwnerMap[$key]; $cache[$key]['dqlAlias'] = $this->_rsm->columnOwnerMap[$key];
break; break;
case (isset($this->_rsm->newObjectMappings[$key])): case (isset($this->_rsm->newObjectMappings[$key])):
// WARNING: A NEW object is also a scalar, so it must be declared before! // WARNING: A NEW object is also a scalar, so it must be declared before!
$mapping = $this->_rsm->newObjectMappings[$key]; $mapping = $this->_rsm->newObjectMappings[$key];
@ -300,7 +300,7 @@ abstract class AbstractHydrator
continue 2; continue 2;
} }
} }
switch (true) { switch (true) {
case (isset($cache[$key]['isNewObjectParameter'])): case (isset($cache[$key]['isNewObjectParameter'])):
$fieldName = $cache[$key]['fieldName']; $fieldName = $cache[$key]['fieldName'];
@ -311,38 +311,38 @@ abstract class AbstractHydrator
$rowData['newObjects'][$objIndex]['class'] = $cache[$key]['class']; $rowData['newObjects'][$objIndex]['class'] = $cache[$key]['class'];
$rowData['newObjects'][$objIndex]['args'][$argIndex] = $value; $rowData['newObjects'][$objIndex]['args'][$argIndex] = $value;
$rowData['scalars'][$fieldName] = $value; $rowData['scalars'][$fieldName] = $value;
break; break;
case (isset($cache[$key]['isScalar'])): case (isset($cache[$key]['isScalar'])):
$value = $cache[$key]['type']->convertToPHPValue($value, $this->_platform); $value = $cache[$key]['type']->convertToPHPValue($value, $this->_platform);
$rowData['scalars'][$cache[$key]['fieldName']] = $value; $rowData['scalars'][$cache[$key]['fieldName']] = $value;
break; break;
case (isset($cache[$key]['isMetaColumn'])): case (isset($cache[$key]['isMetaColumn'])):
$dqlAlias = $cache[$key]['dqlAlias']; $dqlAlias = $cache[$key]['dqlAlias'];
$fieldName = $cache[$key]['fieldName']; $fieldName = $cache[$key]['fieldName'];
// Avoid double setting or null assignment // Avoid double setting or null assignment
if (isset($rowData[$dqlAlias][$fieldName]) || $value === null) { if (isset($rowData[$dqlAlias][$fieldName]) || $value === null) {
break; break;
} }
if ($cache[$key]['isIdentifier']) { if ($cache[$key]['isIdentifier']) {
$id[$dqlAlias] .= '|' . $value; $id[$dqlAlias] .= '|' . $value;
$nonemptyComponents[$dqlAlias] = true; $nonemptyComponents[$dqlAlias] = true;
} }
$rowData[$dqlAlias][$fieldName] = $value; $rowData[$dqlAlias][$fieldName] = $value;
break; break;
default: default:
$dqlAlias = $cache[$key]['dqlAlias']; $dqlAlias = $cache[$key]['dqlAlias'];
$fieldName = $cache[$key]['fieldName']; $fieldName = $cache[$key]['fieldName'];
$type = $cache[$key]['type']; $type = $cache[$key]['type'];
// in an inheritance hierarchy the same field could be defined several times. // in an inheritance hierarchy the same field could be defined several times.
// We overwrite this value so long we don't have a non-null value, that value we keep. // We overwrite this value so long we don't have a non-null value, that value we keep.
// Per definition it cannot be that a field is defined several times and has several values. // Per definition it cannot be that a field is defined several times and has several values.
@ -353,13 +353,13 @@ abstract class AbstractHydrator
if ($cache[$key]['isIdentifier']) { if ($cache[$key]['isIdentifier']) {
$id[$dqlAlias] .= '|' . $value; $id[$dqlAlias] .= '|' . $value;
} }
$value = $type->convertToPHPValue($value, $this->_platform); $value = $type->convertToPHPValue($value, $this->_platform);
if ( ! isset($nonemptyComponents[$dqlAlias]) && $value !== null) { if ( ! isset($nonemptyComponents[$dqlAlias]) && $value !== null) {
$nonemptyComponents[$dqlAlias] = true; $nonemptyComponents[$dqlAlias] = true;
} }
$rowData[$dqlAlias][$fieldName] = $value; $rowData[$dqlAlias][$fieldName] = $value;
break; break;
} }
@ -392,6 +392,7 @@ abstract class AbstractHydrator
// NOTE: During scalar hydration, most of the times it's a scalar mapping, keep it first!!! // NOTE: During scalar hydration, most of the times it's a scalar mapping, keep it first!!!
case (isset($this->_rsm->scalarMappings[$key])): case (isset($this->_rsm->scalarMappings[$key])):
$cache[$key]['fieldName'] = $this->_rsm->scalarMappings[$key]; $cache[$key]['fieldName'] = $this->_rsm->scalarMappings[$key];
$cache[$key]['type'] = Type::getType($this->_rsm->typeMappings[$key]);
$cache[$key]['isScalar'] = true; $cache[$key]['isScalar'] = true;
break; break;
@ -422,17 +423,27 @@ abstract class AbstractHydrator
switch (true) { switch (true) {
case (isset($cache[$key]['isScalar'])): case (isset($cache[$key]['isScalar'])):
// WARNING: BC break! We know this is the desired behavior to type convert values, but this
// erroneous behavior exists since 2.0 and we're forced to keep compatibility. For 3.0 release,
// uncomment these 2 lines of code.
//$type = $cache[$key]['type'];
//$value = $type->convertToPHPValue($value, $this->_platform);
$rowData[$fieldName] = $value; $rowData[$fieldName] = $value;
break; break;
case (isset($cache[$key]['isMetaColumn'])): case (isset($cache[$key]['isMetaColumn'])):
$rowData[$cache[$key]['dqlAlias'] . '_' . $fieldName] = $value; $dqlAlias = $cache[$key]['dqlAlias'];
$rowData[$dqlAlias . '_' . $fieldName] = $value;
break; break;
default: default:
$value = $cache[$key]['type']->convertToPHPValue($value, $this->_platform); $dqlAlias = $cache[$key]['dqlAlias'];
$type = $cache[$key]['type'];
$value = $type->convertToPHPValue($value, $this->_platform);
$rowData[$cache[$key]['dqlAlias'] . '_' . $fieldName] = $value; $rowData[$dqlAlias . '_' . $fieldName] = $value;
} }
} }
@ -454,7 +465,7 @@ abstract class AbstractHydrator
{ {
if ($class->isIdentifierComposite) { if ($class->isIdentifierComposite) {
$id = array(); $id = array();
foreach ($class->identifier as $fieldName) { foreach ($class->identifier as $fieldName) {
$id[$fieldName] = isset($class->associationMappings[$fieldName]) $id[$fieldName] = isset($class->associationMappings[$fieldName])
? $data[$class->associationMappings[$fieldName]['joinColumns'][0]['name']] ? $data[$class->associationMappings[$fieldName]['joinColumns'][0]['name']]