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
e77b65bb
Commit
e77b65bb
authored
May 28, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
first (ugly) draft for array population algorithm
parent
7130cb5a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
134 additions
and
11 deletions
+134
-11
Hydrate.php
lib/Doctrine/Hydrate.php
+134
-11
No files found.
lib/Doctrine/Hydrate.php
View file @
e77b65bb
...
...
@@ -626,7 +626,7 @@ class Doctrine_Hydrate implements Serializable
}
$stmt
=
$this
->
_conn
->
execute
(
$query
,
$params
);
return
(
array
)
$this
->
parseData
(
$stmt
)
;
return
$stmt
;
}
/**
* execute
...
...
@@ -646,7 +646,8 @@ class Doctrine_Hydrate implements Serializable
if
(
$cached
===
null
)
{
// cache miss
$array
=
$this
->
_execute
(
$params
,
$return
);
$stmt
=
$this
->
_execute
(
$params
,
$return
);
$array
=
$this
->
parseData
(
$stmt
);
$cached
=
$this
->
getCachedForm
(
$array
);
...
...
@@ -673,11 +674,12 @@ class Doctrine_Hydrate implements Serializable
$this
->
_aliasMap
=
$map
;
}
}
else
{
$array
=
$this
->
_execute
(
$params
,
$return
);
}
if
(
$return
===
Doctrine
::
FETCH_ARRAY
)
{
return
$array
;
$stmt
=
$this
->
_execute
(
$params
,
$return
);
if
(
$return
===
Doctrine
::
FETCH_ARRAY
)
{
return
$this
->
parseData2
(
$stmt
);
}
else
{
$array
=
$this
->
parseData
(
$stmt
);
}
}
if
(
empty
(
$this
->
_aliasMap
))
{
...
...
@@ -892,6 +894,127 @@ class Doctrine_Hydrate implements Serializable
return
$str
;
}
/**
* parseData
* parses the data returned by statement object
*
* @param mixed $stmt
* @return array
*/
public
function
parseData2
(
$stmt
)
{
$array
=
array
();
$cache
=
array
();
$rootMap
=
reset
(
$this
->
_aliasMap
);
$rootAlias
=
key
(
$this
->
_aliasMap
);
$index
=
0
;
$incr
=
true
;
$lastAlias
=
''
;
$currData
=
array
();
while
(
$data
=
$stmt
->
fetch
(
PDO
::
FETCH_ASSOC
))
{
foreach
(
$data
as
$key
=>
$value
)
{
if
(
!
isset
(
$cache
[
$key
]))
{
$e
=
explode
(
'__'
,
$key
);
$cache
[
$key
][
'field'
]
=
$field
=
strtolower
(
array_pop
(
$e
));
$componentAlias
=
$this
->
_tableAliases
[
strtolower
(
implode
(
'__'
,
$e
))];
$cache
[
$key
][
'alias'
]
=
$componentAlias
;
if
(
isset
(
$this
->
_aliasMap
[
$componentAlias
][
'relation'
]))
{
$cache
[
$key
][
'component'
]
=
$this
->
_aliasMap
[
$componentAlias
][
'relation'
]
->
getAlias
();
$cache
[
$key
][
'parent'
]
=
$this
->
_aliasMap
[
$componentAlias
][
'parent'
];
}
else
{
$cache
[
$key
][
'component'
]
=
$this
->
_aliasMap
[
$componentAlias
][
'table'
]
->
getComponentName
();
}
}
$tmp
=
array
();
$alias
=
$cache
[
$key
][
'alias'
];
$component
=
$cache
[
$key
][
'component'
];
if
(
!
isset
(
$currData
[
$alias
]))
{
$currData
[
$alias
]
=
array
();
}
if
(
!
isset
(
$prev
[
$alias
]))
{
$prev
[
$alias
]
=
array
();
}
if
(
$lastAlias
!==
$alias
)
{
// component changed
if
(
$alias
===
$rootAlias
)
{
// dealing with root component
if
(
!
isset
(
$prevData
[
$alias
])
||
$currData
[
$alias
]
!==
$prevData
[
$alias
])
{
if
(
!
empty
(
$currData
[
$alias
]))
{
$array
[
$index
]
=
$currData
[
$alias
];
$prev
[
$alias
]
=&
$array
[
$index
];
$index
++
;
}
}
}
else
{
$parent
=
$cache
[
$key
][
'parent'
];
$relation
=
$this
->
_aliasMap
[
$cache
[
$key
][
'alias'
]][
'relation'
];
if
(
!
isset
(
$prevData
[
$alias
])
||
$currData
[
$alias
]
!==
$prevData
[
$alias
])
{
if
(
$relation
->
getType
()
>=
Doctrine_Relation
::
MANY
)
{
$prev
[
$parent
][
$component
][]
=
$currData
[
$alias
];
}
else
{
$prev
[
$parent
][
$component
]
=
$currData
[
$alias
];
}
}
}
if
(
isset
(
$currData
[
$alias
]))
{
$prevData
[
$alias
]
=
$currData
[
$alias
];
}
else
{
$prevData
[
$alias
]
=
array
();
}
}
else
{
$field
=
$cache
[
$key
][
'field'
];
$currData
[
$alias
][
$field
]
=
$value
;
}
$lastAlias
=
$alias
;
}
}
foreach
(
$currData
as
$alias
=>
$data
)
{
if
(
$alias
===
$rootAlias
)
{
// dealing with root component
if
(
!
isset
(
$prevData
[
$alias
])
||
$currData
[
$alias
]
!==
$prevData
[
$alias
])
{
if
(
!
empty
(
$currData
[
$alias
]))
{
$array
[
$index
]
=
$currData
[
$alias
];
$prev
[
$alias
]
=&
$array
[
$index
];
$index
++
;
}
}
}
else
{
$parent
=
$cache
[
$key
][
'parent'
];
$relation
=
$this
->
_aliasMap
[
$cache
[
$key
][
'alias'
]][
'relation'
];
if
(
!
isset
(
$prevData
[
$alias
])
||
$currData
[
$alias
]
!==
$prevData
[
$alias
])
{
if
(
$relation
->
getType
()
>=
Doctrine_Relation
::
MANY
)
{
$prev
[
$parent
][
$component
][]
=
$currData
[
$alias
];
}
else
{
$prev
[
$parent
][
$component
]
=
$currData
[
$alias
];
}
}
}
}
$stmt
->
closeCursor
();
unset
(
$cache
);
return
$array
;
}
/**
* parseData
* parses the data returned by statement object
...
...
@@ -906,7 +1029,7 @@ class Doctrine_Hydrate implements Serializable
while
(
$data
=
$stmt
->
fetch
(
PDO
::
FETCH_ASSOC
))
{
foreach
(
$data
as
$key
=>
$value
)
{
if
(
!
isset
(
$cache
[
$key
]))
{
if
(
!
isset
(
$cache
[
$key
]))
{
$e
=
explode
(
'__'
,
$key
);
$cache
[
$key
][
'field'
]
=
strtolower
(
array_pop
(
$e
));
$cache
[
$key
][
'component'
]
=
strtolower
(
implode
(
'__'
,
$e
));
...
...
@@ -915,11 +1038,11 @@ class Doctrine_Hydrate implements Serializable
$data
[
$cache
[
$key
][
'component'
]][
$cache
[
$key
][
'field'
]]
=
$value
;
unset
(
$data
[
$key
]);
}
;
}
$array
[]
=
$data
;
}
;
}
$stmt
->
closeCursor
();
unset
(
$cache
);
return
$array
;
}
/**
...
...
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