Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
4d146d32
Commit
4d146d32
authored
Jul 20, 2009
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] Small hydration cleanups and improvements.
parent
e1973487
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
44 deletions
+32
-44
AbstractHydrator.php
lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php
+8
-29
ArrayHydrator.php
lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php
+11
-5
ObjectHydrator.php
lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php
+13
-10
No files found.
lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php
View file @
4d146d32
...
...
@@ -178,15 +178,15 @@ abstract class AbstractHydrator
foreach
(
$data
as
$key
=>
$value
)
{
// Parse each column name only once. Cache the results.
if
(
!
isset
(
$cache
[
$key
]))
{
if
(
isset
(
$this
->
_rsm
->
ignoredColumns
[
$key
]))
{
$cache
[
$key
]
=
false
;
}
else
if
(
isset
(
$this
->
_rsm
->
scalarMappings
[
$key
]))
{
if
(
isset
(
$this
->
_rsm
->
scalarMappings
[
$key
]))
{
$cache
[
$key
][
'fieldName'
]
=
$this
->
_rsm
->
scalarMappings
[
$key
];
$cache
[
$key
][
'isScalar'
]
=
true
;
}
else
if
(
isset
(
$this
->
_rsm
->
fieldMappings
[
$key
]))
{
$classMetadata
=
$this
->
_em
->
getClassMetadata
(
$this
->
_rsm
->
getOwningClass
(
$key
));
$fieldName
=
$this
->
_rsm
->
fieldMappings
[
$key
];
if
(
!
isset
(
$classMetadata
->
reflFields
[
$fieldName
]))
{
$classMetadata
=
$this
->
_lookupDeclaringClass
(
$classMetadata
,
$fieldName
);
}
$cache
[
$key
][
'fieldName'
]
=
$fieldName
;
$cache
[
$key
][
'isScalar'
]
=
false
;
$cache
[
$key
][
'type'
]
=
Type
::
getType
(
$classMetadata
->
fieldMappings
[
$fieldName
][
'type'
]);
...
...
@@ -222,11 +222,6 @@ abstract class AbstractHydrator
if
(
!
isset
(
$nonemptyComponents
[
$dqlAlias
])
&&
$value
!==
null
)
{
$nonemptyComponents
[
$dqlAlias
]
=
true
;
}
/* TODO: Consider this instead of the above 4 lines. */
/*if ($value !== null) {
$rowData[$dqlAlias][$fieldName] = $cache[$key]['type']->convertToPHPValue($value, $this->_platform);
}*/
}
return
$rowData
;
...
...
@@ -249,16 +244,15 @@ abstract class AbstractHydrator
foreach
(
$data
as
$key
=>
$value
)
{
// Parse each column name only once. Cache the results.
if
(
!
isset
(
$cache
[
$key
]))
{
if
(
isset
(
$this
->
_rsm
->
ignoredColumns
[
$key
]))
{
$cache
[
$key
]
=
false
;
continue
;
}
else
if
(
isset
(
$this
->
_rsm
->
scalarMappings
[
$key
]))
{
if
(
isset
(
$this
->
_rsm
->
scalarMappings
[
$key
]))
{
$cache
[
$key
][
'fieldName'
]
=
$this
->
_rsm
->
scalarMappings
[
$key
];
$cache
[
$key
][
'isScalar'
]
=
true
;
}
else
{
$classMetadata
=
$this
->
_em
->
getClassMetadata
(
$this
->
_rsm
->
getOwningClass
(
$key
));
$fieldName
=
$this
->
_rsm
->
fieldMappings
[
$key
];
if
(
!
isset
(
$classMetadata
->
reflFields
[
$fieldName
]))
{
$classMetadata
=
$this
->
_lookupDeclaringClass
(
$classMetadata
,
$fieldName
);
}
$cache
[
$key
][
'fieldName'
]
=
$fieldName
;
$cache
[
$key
][
'isScalar'
]
=
false
;
$cache
[
$key
][
'type'
]
=
Type
::
getType
(
$classMetadata
->
getTypeOfField
(
$fieldName
));
...
...
@@ -279,17 +273,6 @@ abstract class AbstractHydrator
return
$rowData
;
}
/**
* Gets the custom field used for indexing for the specified DQL alias.
*
* @return string The field name of the field used for indexing or NULL
* if the component does not use any custom field indices.
*/
protected
function
_getCustomIndexField
(
$alias
)
{
return
isset
(
$this
->
_rsm
->
indexByMap
[
$alias
])
?
$this
->
_rsm
->
indexByMap
[
$alias
]
:
null
;
}
/**
* Looks up the field name for a (lowercased) column name.
*
...
...
@@ -310,10 +293,6 @@ abstract class AbstractHydrator
*/
private
function
_lookupDeclaringClass
(
$class
,
$fieldName
)
{
if
(
isset
(
$class
->
reflFields
[
$fieldName
]))
{
return
$class
;
}
foreach
(
$class
->
subClasses
as
$subClass
)
{
$subClassMetadata
=
$this
->
_em
->
getClassMetadata
(
$subClass
);
if
(
$subClassMetadata
->
hasField
(
$fieldName
))
{
...
...
lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php
View file @
4d146d32
...
...
@@ -24,9 +24,11 @@ namespace Doctrine\ORM\Internal\Hydration;
use
Doctrine\DBAL\Connection
;
/**
* Description of ArrayHydrator
* The ArrayHydrator produces a nested array "graph" that is often (not always)
* interchangeable with the corresponding object graph for read-only access.
*
* @author robo
* @author Roman Borschel <roman@code-factory.org>
* @since 1.0
*/
class
ArrayHydrator
extends
AbstractHydrator
{
...
...
@@ -116,7 +118,8 @@ class ArrayHydrator extends AbstractHydrator
$indexIsValid
=
$index
!==
false
?
isset
(
$baseElement
[
$relationAlias
][
$index
])
:
false
;
if
(
!
$indexExists
||
!
$indexIsValid
)
{
$element
=
$data
;
if
(
$field
=
$this
->
_getCustomIndexField
(
$dqlAlias
))
{
if
(
isset
(
$this
->
_rsm
->
indexByMap
[
$dqlAlias
]))
{
$field
=
$this
->
_rsm
->
indexByMap
[
$dqlAlias
];
$baseElement
[
$relationAlias
][
$element
[
$field
]]
=
$element
;
}
else
{
$baseElement
[
$relationAlias
][]
=
$element
;
...
...
@@ -144,12 +147,15 @@ class ArrayHydrator extends AbstractHydrator
}
}
else
{
// It's a root result element
$this
->
_rootAliases
[
$dqlAlias
]
=
true
;
// Mark as root
// 2) Hydrate the data of the root entity from the current row
// Check for an existing element
if
(
$this
->
_isSimpleQuery
||
!
isset
(
$this
->
_identifierMap
[
$dqlAlias
][
$id
[
$dqlAlias
]]))
{
$element
=
$rowData
[
$dqlAlias
];
if
(
$field
=
$this
->
_getCustomIndexField
(
$dqlAlias
))
{
if
(
isset
(
$this
->
_rsm
->
indexByMap
[
$dqlAlias
]))
{
$field
=
$this
->
_rsm
->
indexByMap
[
$dqlAlias
];
if
(
$this
->
_rsm
->
isMixed
)
{
$result
[]
=
array
(
$element
[
$field
]
=>
$element
);
++
$this
->
_resultCounter
;
...
...
lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php
View file @
4d146d32
...
...
@@ -168,10 +168,10 @@ class ObjectHydrator extends AbstractHydrator
}
/**
* Initializes a related collection.
*
* @param object $entity
* @param string $name
* @todo Consider inlining this method.
* @param object $entity The entity to which the collection belongs.
* @param string $name The name of the field on the entity that holds the collection.
*/
private
function
initRelatedCollection
(
$entity
,
$name
)
{
...
...
@@ -179,16 +179,16 @@ class ObjectHydrator extends AbstractHydrator
$classMetadata
=
$this
->
_ce
[
get_class
(
$entity
)];
$relation
=
$classMetadata
->
associationMappings
[
$name
];
$relatedClass
=
$this
->
_em
->
getClassMetadata
(
$relation
->
targetEntityName
);
$coll
=
new
PersistentCollection
(
$this
->
_em
,
$relatedClass
);
if
(
!
isset
(
$this
->
_ce
[
$relation
->
targetEntityName
]))
{
$this
->
_ce
[
$relation
->
targetEntityName
]
=
$this
->
_em
->
getClassMetadata
(
$relation
->
targetEntityName
);
}
$coll
=
new
PersistentCollection
(
$this
->
_em
,
$this
->
_ce
[
$relation
->
targetEntityName
]);
$this
->
_collections
[]
=
$coll
;
$coll
->
setOwner
(
$entity
,
$relation
);
$classMetadata
->
reflFields
[
$name
]
->
setValue
(
$entity
,
$coll
);
$this
->
_uow
->
setOriginalEntityProperty
(
$oid
,
$name
,
$coll
);
$this
->
_initializedRelations
[
$oid
][
$name
]
=
true
;
return
$coll
;
}
/**
...
...
@@ -197,7 +197,7 @@ class ObjectHydrator extends AbstractHydrator
* @param <type> $assocField
* @param <type> $indexField
* @return <type>
* @todo
Consider inlining
this method.
* @todo
Inline
this method.
*/
private
function
isIndexKeyInUse
(
$entity
,
$assocField
,
$indexField
)
{
...
...
@@ -371,7 +371,8 @@ class ObjectHydrator extends AbstractHydrator
}
}
if
(
$field
=
$this
->
_getCustomIndexField
(
$dqlAlias
))
{
if
(
isset
(
$this
->
_rsm
->
indexByMap
[
$dqlAlias
]))
{
$field
=
$this
->
_rsm
->
indexByMap
[
$dqlAlias
];
$indexValue
=
$this
->
_ce
[
$entityName
]
->
reflFields
[
$field
]
->
getValue
(
$element
);
...
...
@@ -385,6 +386,7 @@ class ObjectHydrator extends AbstractHydrator
->
getValue
(
$baseElement
)
->
hydrateAdd
(
$element
);
}
$this
->
_identifierMap
[
$path
][
$id
[
$parent
]][
$id
[
$dqlAlias
]]
=
$this
->
getLastKey
(
$this
->
_ce
[
$parentClass
]
->
reflFields
[
$relationAlias
]
...
...
@@ -416,7 +418,8 @@ class ObjectHydrator extends AbstractHydrator
if
(
$this
->
_isSimpleQuery
||
!
isset
(
$this
->
_identifierMap
[
$dqlAlias
][
$id
[
$dqlAlias
]]))
{
$element
=
$this
->
getEntity
(
$rowData
[
$dqlAlias
],
$dqlAlias
);
if
(
$field
=
$this
->
_getCustomIndexField
(
$dqlAlias
))
{
if
(
isset
(
$this
->
_rsm
->
indexByMap
[
$dqlAlias
]))
{
$field
=
$this
->
_rsm
->
indexByMap
[
$dqlAlias
];
if
(
$this
->
_rsm
->
isMixed
)
{
$result
[]
=
array
(
$this
->
_ce
[
$entityName
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment