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
f4462041
Commit
f4462041
authored
May 29, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
e448bcb8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
201 deletions
+4
-201
Hydrate.php
draft/new-core/Hydrate.php
+4
-201
No files found.
draft/new-core/Hydrate.php
View file @
f4462041
...
@@ -647,7 +647,7 @@ class Doctrine_Hydrate implements Serializable
...
@@ -647,7 +647,7 @@ class Doctrine_Hydrate implements Serializable
if
(
$cached
===
null
)
{
if
(
$cached
===
null
)
{
// cache miss
// cache miss
$stmt
=
$this
->
_execute
(
$params
,
$return
);
$stmt
=
$this
->
_execute
(
$params
,
$return
);
$array
=
$this
->
parseData
(
$stmt
);
$array
=
$this
->
parseData
2
(
$stmt
);
$cached
=
$this
->
getCachedForm
(
$array
);
$cached
=
$this
->
getCachedForm
(
$array
);
...
@@ -675,127 +675,10 @@ class Doctrine_Hydrate implements Serializable
...
@@ -675,127 +675,10 @@ class Doctrine_Hydrate implements Serializable
}
}
}
else
{
}
else
{
$stmt
=
$this
->
_execute
(
$params
,
$return
);
$stmt
=
$this
->
_execute
(
$params
,
$return
);
//if ($return === Doctrine::FETCH_ARRAY) {
return
$this
->
parseData2
(
$stmt
,
$return
);
/**
} else {
$array = $this->parseData($stmt);
}
*/
}
if
(
empty
(
$this
->
_aliasMap
))
{
throw
new
Doctrine_Hydrate_Exception
(
"Couldn't execute query. Component alias map was empty."
);
}
// initialize some variables used within the main loop
reset
(
$this
->
_aliasMap
);
$rootMap
=
current
(
$this
->
_aliasMap
);
$rootAlias
=
key
(
$this
->
_aliasMap
);
$coll
=
new
Doctrine_Collection
(
$rootMap
[
'table'
]);
$prev
[
$rootAlias
]
=
$coll
;
// we keep track of all the collections
$colls
=
array
();
$colls
[]
=
$coll
;
$prevRow
=
array
();
/**
* iterate over the fetched data
* here $data is a two dimensional array
*/
foreach
(
$array
as
$data
)
{
/**
* remove duplicated data rows and map data into objects
*/
foreach
(
$data
as
$tableAlias
=>
$row
)
{
// skip empty rows (not mappable)
if
(
empty
(
$row
))
{
continue
;
}
$alias
=
$this
->
getComponentAlias
(
$tableAlias
);
$map
=
$this
->
_aliasMap
[
$alias
];
// initialize previous row array if not set
if
(
!
isset
(
$prevRow
[
$tableAlias
]))
{
$prevRow
[
$tableAlias
]
=
array
();
}
// don't map duplicate rows
if
(
$prevRow
[
$tableAlias
]
!==
$row
)
{
$identifiable
=
$this
->
isIdentifiable
(
$row
,
$map
[
'table'
]
->
getIdentifier
());
if
(
$identifiable
)
{
// set internal data
$map
[
'table'
]
->
setData
(
$row
);
}
// initialize a new record
$record
=
$map
[
'table'
]
->
getRecord
();
// map aggregate values (if any)
if
(
$this
->
mapAggregateValues
(
$record
,
$row
,
$alias
))
{
$identifiable
=
true
;
}
if
(
$alias
==
$rootAlias
)
{
// add record into root collection
if
(
$identifiable
)
{
$coll
->
add
(
$record
);
unset
(
$prevRow
);
}
}
else
{
$relation
=
$map
[
'relation'
];
$parentAlias
=
$map
[
'parent'
];
$parentMap
=
$this
->
_aliasMap
[
$parentAlias
];
$parent
=
$prev
[
$parentAlias
]
->
getLast
();
// check the type of the relation
if
(
$relation
->
isOneToOne
())
{
if
(
!
$identifiable
)
{
continue
;
}
$prev
[
$alias
]
=
$record
;
}
else
{
// one-to-many relation or many-to-many relation
if
(
!
$prev
[
$parentAlias
]
->
getLast
()
->
hasReference
(
$relation
->
getAlias
()))
{
// initialize a new collection
$prev
[
$alias
]
=
new
Doctrine_Collection
(
$map
[
'table'
]);
$prev
[
$alias
]
->
setReference
(
$parent
,
$relation
);
}
else
{
// previous entry found from memory
$prev
[
$alias
]
=
$prev
[
$parentAlias
]
->
getLast
()
->
get
(
$relation
->
getAlias
());
}
$colls
[]
=
$prev
[
$alias
];
$array
=
$this
->
parseData2
(
$stmt
,
$return
);
// add record to the current collection
if
(
$identifiable
)
{
$prev
[
$alias
]
->
add
(
$record
);
}
}
// initialize the relation from parent to the current collection/record
$parent
->
set
(
$relation
->
getAlias
(),
$prev
[
$alias
]);
}
// following statement is needed to ensure that mappings
// are being done properly when the result set doesn't
// contain the rows in 'right order'
if
(
$prev
[
$alias
]
!==
$record
)
{
$prev
[
$alias
]
=
$record
;
}
}
$prevRow
[
$tableAlias
]
=
$row
;
}
}
// take snapshots from all initialized collections
foreach
(
array_unique
(
$colls
)
as
$c
)
{
$c
->
takeSnapshot
();
}
}
return
$array
;
return
$coll
;
}
}
/**
/**
* isIdentifiable
* isIdentifiable
...
@@ -1040,36 +923,6 @@ class Doctrine_Hydrate implements Serializable
...
@@ -1040,36 +923,6 @@ class Doctrine_Hydrate implements Serializable
$stmt
->
closeCursor
();
$stmt
->
closeCursor
();
return
$array
;
return
$array
;
}
}
/**
* parseData
* parses the data returned by statement object
*
* @param mixed $stmt
* @return array
*/
public
function
parseData
(
$stmt
)
{
$array
=
array
();
$cache
=
array
();
while
(
$data
=
$stmt
->
fetch
(
PDO
::
FETCH_ASSOC
))
{
foreach
(
$data
as
$key
=>
$value
)
{
if
(
!
isset
(
$cache
[
$key
]))
{
$e
=
explode
(
'__'
,
$key
);
$cache
[
$key
][
'field'
]
=
strtolower
(
array_pop
(
$e
));
$cache
[
$key
][
'component'
]
=
strtolower
(
implode
(
'__'
,
$e
));
}
$data
[
$cache
[
$key
][
'component'
]][
$cache
[
$key
][
'field'
]]
=
$value
;
unset
(
$data
[
$key
]);
}
$array
[]
=
$data
;
}
$stmt
->
closeCursor
();
return
$array
;
}
/**
/**
* @return string returns a string representation of this object
* @return string returns a string representation of this object
*/
*/
...
@@ -1077,54 +930,4 @@ class Doctrine_Hydrate implements Serializable
...
@@ -1077,54 +930,4 @@ class Doctrine_Hydrate implements Serializable
{
{
return
Doctrine_Lib
::
formatSql
(
$this
->
getQuery
());
return
Doctrine_Lib
::
formatSql
(
$this
->
getQuery
());
}
}
}
}
class
Doctrine_Hydrate_Array
{
public
function
getElementCollection
(
$component
)
{
return
array
();
}
public
function
getElement
(
array
$data
,
$component
)
{
return
$data
;
}
public
function
flush
()
{
}
}
class
Doctrine_Hydrate_Record
{
protected
$_collections
=
array
();
protected
$_records
=
array
();
public
function
getElementCollection
(
$component
)
{
$coll
=
new
Doctrine_Collection
(
$component
);
$this
->
_collections
[]
=
$coll
;
return
$coll
;
}
public
function
getElement
(
array
$data
,
$component
)
{
$record
=
new
$component
();
$record
->
hydrate
(
$data
);
$this
->
_records
[]
=
$record
;
return
$record
;
}
public
function
flush
()
{
// take snapshots from all initialized collections
foreach
(
array_unique
(
$this
->
_collections
)
as
$c
)
{
$c
->
takeSnapshot
();
}
foreach
(
$this
->
_records
as
$record
)
{
$record
->
state
(
Doctrine_Record
::
STATE_CLEAN
);
}
}
}
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