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
929273a0
Commit
929273a0
authored
Nov 21, 2007
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More refactorings and small speed improvements on the default hydrator.
parent
205c50ea
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
168 additions
and
390 deletions
+168
-390
Array.php
lib/Doctrine/Hydrate/Array.php
+0
-73
Record.php
lib/Doctrine/Hydrate/Record.php
+0
-132
Abstract.php
lib/Doctrine/Hydrator/Abstract.php
+7
-11
Default.php
lib/Doctrine/Hydrator/Default.php
+89
-104
ArrayDriver.php
lib/Doctrine/Hydrator/Default/ArrayDriver.php
+1
-1
RecordDriver.php
lib/Doctrine/Hydrator/Default/RecordDriver.php
+4
-2
Exception.php
lib/Doctrine/Hydrator/Exception.php
+33
-33
Query.php
lib/Doctrine/Query.php
+4
-29
Abstract.php
lib/Doctrine/Query/Abstract.php
+29
-4
HydrateTestCase.php
tests/HydrateTestCase.php
+1
-1
No files found.
lib/Doctrine/Hydrate/Array.php
deleted
100644 → 0
View file @
205c50ea
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Hydrate_Array
* defines an array fetching strategy for Doctrine_Hydrate
*
* @package Doctrine
* @subpackage Hydrate
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class
Doctrine_Hydrate_Array
{
public
function
getElementCollection
(
$component
)
{
return
array
();
}
public
function
getElement
(
array
$data
,
$component
)
{
return
$data
;
}
public
function
isIdentifiable
(
array
$data
,
Doctrine_Table
$table
)
{
return
(
!
empty
(
$data
));
}
public
function
registerCollection
(
$coll
)
{
}
public
function
initRelated
(
array
&
$data
,
$name
)
{
if
(
!
isset
(
$data
[
$name
]))
{
$data
[
$name
]
=
array
();
}
return
true
;
}
public
function
getNullPointer
()
{
return
null
;
}
public
function
getLastKey
(
&
$data
)
{
end
(
$data
);
return
key
(
$data
);
}
public
function
flush
()
{
}
}
lib/Doctrine/Hydrate/Record.php
deleted
100644 → 0
View file @
205c50ea
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Hydrate_Record
* defines a record fetching strategy for Doctrine_Hydrate
*
* @package Doctrine
* @subpackage Hydrate
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class
Doctrine_Hydrate_Record
extends
Doctrine_Locator_Injectable
{
protected
$_collections
=
array
();
protected
$_records
=
array
();
protected
$_tables
=
array
();
public
function
getElementCollection
(
$component
)
{
$coll
=
new
Doctrine_Collection
(
$component
);
$this
->
_collections
[]
=
$coll
;
return
$coll
;
}
public
function
getLastKey
(
$coll
)
{
$coll
->
end
();
return
$coll
->
key
();
}
public
function
initRelated
(
$record
,
$name
)
{
if
(
!
is_array
(
$record
))
{
$record
[
$name
];
return
true
;
}
return
false
;
}
public
function
registerCollection
(
Doctrine_Collection
$coll
)
{
$this
->
_collections
[]
=
$coll
;
}
/**
* isIdentifiable
* returns whether or not a given data row is identifiable (it contains
* all primary key fields specified in the second argument)
*
* @param array $row
* @param Doctrine_Table $table
* @return boolean
*/
public
function
isIdentifiable
(
array
$row
,
Doctrine_Table
$table
)
{
$primaryKeys
=
$table
->
getIdentifierColumnNames
();
if
(
is_array
(
$primaryKeys
))
{
foreach
(
$primaryKeys
as
$id
)
{
if
(
!
isset
(
$row
[
$id
]))
{
return
false
;
}
}
}
else
{
if
(
!
isset
(
$row
[
$primaryKeys
]))
{
return
false
;
}
}
return
true
;
}
public
function
getNullPointer
()
{
return
self
::
$_null
;
}
public
function
getElement
(
array
$data
,
$component
)
{
if
(
!
isset
(
$this
->
_tables
[
$component
]))
{
$this
->
_tables
[
$component
]
=
Doctrine_Manager
::
getInstance
()
->
getTable
(
$component
);
$this
->
_tables
[
$component
]
->
setAttribute
(
Doctrine
::
ATTR_LOAD_REFERENCES
,
false
);
}
$this
->
_tables
[
$component
]
->
setData
(
$data
);
$record
=
$this
->
_tables
[
$component
]
->
getRecord
();
if
(
!
isset
(
$this
->
_records
[
$record
->
getOid
()])
)
{
$record
->
clearRelated
();
$this
->
_records
[
$record
->
getOid
()]
=
$record
;
}
return
$record
;
}
public
function
flush
()
{
// take snapshots from all initialized collections
foreach
(
$this
->
_collections
as
$key
=>
$coll
)
{
$coll
->
takeSnapshot
();
}
foreach
(
$this
->
_tables
as
$table
)
{
$table
->
setAttribute
(
Doctrine
::
ATTR_LOAD_REFERENCES
,
true
);
}
}
}
lib/Doctrine/Hydrator/Abstract.php
View file @
929273a0
...
...
@@ -47,7 +47,7 @@ abstract class Doctrine_Hydrator_Abstract extends Doctrine_Locator_Injectable
* map the name of the column / aggregate value this
* component is mapped to a collection
*/
protected
$_
aliasMap
=
array
();
protected
$_
queryComponents
=
array
();
/**
* The current hydration mode.
...
...
@@ -59,10 +59,7 @@ abstract class Doctrine_Hydrator_Abstract extends Doctrine_Locator_Injectable
*
* @param Doctrine_Connection|null $connection
*/
public
function
__construct
()
{
}
public
function
__construct
()
{}
/**
* Sets the fetchmode.
...
...
@@ -81,10 +78,9 @@ abstract class Doctrine_Hydrator_Abstract extends Doctrine_Locator_Injectable
* @param array $map alias map
* @return Doctrine_Hydrate this object
*/
public
function
set
AliasMap
(
array
$map
)
public
function
set
QueryComponents
(
array
$queryComponents
)
{
$this
->
_aliasMap
=
$map
;
return
$this
;
$this
->
_queryComponents
=
$queryComponents
;
}
/**
...
...
@@ -93,9 +89,9 @@ abstract class Doctrine_Hydrator_Abstract extends Doctrine_Locator_Injectable
*
* @return array component alias map
*/
public
function
get
AliasMap
()
public
function
get
QueryComponents
()
{
return
$this
->
_
aliasMap
;
return
$this
->
_
queryComponents
;
}
/**
...
...
@@ -114,6 +110,6 @@ abstract class Doctrine_Hydrator_Abstract extends Doctrine_Locator_Injectable
* @param mixed $stmt
* @return array
*/
abstract
public
function
hydrateResultSet
(
$stmt
,
$
aliasMap
,
$
tableAliases
,
$hydrationMode
=
null
);
abstract
public
function
hydrateResultSet
(
$stmt
,
$tableAliases
,
$hydrationMode
=
null
);
}
lib/Doctrine/Hydrator/Default.php
View file @
929273a0
...
...
@@ -38,7 +38,7 @@ class Doctrine_Hydrator_Default extends Doctrine_Hydrator_Abstract
* hydrateResultSet
* parses the data returned by statement object
*
* This is method defines the core of Doctrine object population algorithm
* This is method defines the core of Doctrine
's
object population algorithm
* hence this method strives to be as fast as possible
*
* The key idea is the loop over the rowset only once doing all the needed operations
...
...
@@ -49,31 +49,20 @@ class Doctrine_Hydrator_Default extends Doctrine_Hydrator_Abstract
* @param mixed $stmt
* @param array $tableAliases Array that maps table aliases (SQL alias => DQL alias)
* @param array $aliasMap Array that maps DQL aliases to their components
* (DQL alias => array('table' => Table object,
* 'parent' => Parent DQL alias (if any),
* 'relation' => Relation object (if any),
* 'map' => ??? (if any)
* )
* (DQL alias => array(
* 'table' => Table object,
* 'parent' => Parent DQL alias (if any),
* 'relation' => Relation object (if any),
* 'map' => ??? (if any)
* )
* )
* @return array
*/
public
function
hydrateResultSet
(
$stmt
,
$
aliasMap
,
$
tableAliases
,
$hydrationMode
=
null
)
public
function
hydrateResultSet
(
$stmt
,
$tableAliases
,
$hydrationMode
=
null
)
{
//$s = microtime(true);
$this
->
_aliasMap
=
$aliasMap
;
$this
->
_tableAliases
=
$tableAliases
;
/*echo "aliasmap:<br />";
foreach ($this->_aliasMap as $map) {
if ( ! empty($map['map'])) {
Doctrine::dump($map['map']);
}
}*/
//Doctrine::dump($this->_aliasMap);
//echo "<br />";
//echo "tableAliases:<br />";
//Doctrine::dump($tableAliases);
//echo "<br /><br />";
if
(
$hydrationMode
==
Doctrine
::
HYDRATE_NONE
)
{
return
$stmt
->
fetchAll
(
PDO
::
FETCH_NUM
);
...
...
@@ -84,56 +73,57 @@ class Doctrine_Hydrator_Default extends Doctrine_Hydrator_Abstract
}
if
(
$hydrationMode
===
Doctrine
::
HYDRATE_ARRAY
)
{
$driver
=
new
Doctrine_Hydrator_Default_
FetchModeDriver_Array
();
$driver
=
new
Doctrine_Hydrator_Default_
ArrayDriver
();
}
else
{
$driver
=
new
Doctrine_Hydrator_Default_
FetchModeDriver_Record
();
$driver
=
new
Doctrine_Hydrator_Default_
RecordDriver
();
}
$event
=
new
Doctrine_Event
(
null
,
Doctrine_Event
::
HYDRATE
,
null
);
// Used variables during hydration
$rootMap
=
reset
(
$this
->
_aliasMap
);
$rootAlias
=
key
(
$this
->
_aliasMap
);
$componentName
=
$rootMap
[
'table'
]
->
getComponentName
();
$isSimpleQuery
=
count
(
$this
->
_aliasMap
)
<=
1
;
$result
=
array
();
// Holds the resulting hydrated data structure
$listeners
=
array
();
// Holds hydration listeners that get called during hydration
$identifierMap
=
array
();
// Lookup map to quickly discover/lookup existing records in the result
$prev
=
array
();
// Holds for each component the last previously seen element in the result set
$id
=
array
();
// holds the values of the identifier/primary key columns of components,
// separated by a pipe '|' and grouped by component alias (r, u, i, ... whatever)
reset
(
$this
->
_queryComponents
);
$rootAlias
=
key
(
$this
->
_queryComponents
);
$rootComponentName
=
$this
->
_queryComponents
[
$rootAlias
][
'table'
]
->
getComponentName
();
// if only one component is involved we can make our lives easier
$isSimpleQuery
=
count
(
$this
->
_queryComponents
)
<=
1
;
// Holds the resulting hydrated data structure
$result
=
array
();
// Holds hydration listeners that get called during hydration
$listeners
=
array
();
// Lookup map to quickly discover/lookup existing records in the result
$identifierMap
=
array
();
// Holds for each component the last previously seen element in the result set
$prev
=
array
();
// holds the values of the identifier/primary key fields of components,
// separated by a pipe '|' and grouped by component alias (r, u, i, ... whatever)
$id
=
array
();
$result
=
$driver
->
getElementCollection
(
$
c
omponentName
);
$result
=
$driver
->
getElementCollection
(
$
rootC
omponentName
);
if
(
$stmt
===
false
||
$stmt
===
0
)
{
return
$result
;
}
// Initialize
the variables
foreach
(
$this
->
_
aliasMap
as
$a
lias
=>
$data
)
{
// Initialize
foreach
(
$this
->
_
queryComponents
as
$dqlA
lias
=>
$data
)
{
$componentName
=
$data
[
'table'
]
->
getComponentName
();
$listeners
[
$componentName
]
=
$data
[
'table'
]
->
getRecordListener
();
$identifierMap
[
$
a
lias
]
=
array
();
$prev
[
$
a
lias
]
=
array
();
$id
[
$
a
lias
]
=
''
;
$identifierMap
[
$
dqlA
lias
]
=
array
();
$prev
[
$
dqlA
lias
]
=
array
();
$id
[
$
dqlA
lias
]
=
''
;
}
// Process result set
$cache
=
array
();
while
(
$data
=
$stmt
->
fetch
(
Doctrine
::
FETCH_ASSOC
))
{
$identifiable
=
array
();
$rowData
=
$this
->
_gatherRowData
(
$data
,
$cache
,
$id
,
$identifiable
);
//echo "rowData of row:<br />";
//Doctrine::dump($rowData);
//echo "<br /><br />";
$nonemptyComponents
=
array
();
$rowData
=
$this
->
_gatherRowData
(
$data
,
$cache
,
$id
,
$nonemptyComponents
);
//
// hydrate the data of the root component from the current row
//
$table
=
$this
->
_
aliasMap
[
$rootAlias
][
'table'
];
$table
=
$this
->
_
queryComponents
[
$rootAlias
][
'table'
];
$componentName
=
$table
->
getComponentName
();
$event
->
set
(
'data'
,
$rowData
[
$rootAlias
]);
$listeners
[
$componentName
]
->
preHydrate
(
$event
);
...
...
@@ -148,9 +138,9 @@ class Doctrine_Hydrator_Default extends Doctrine_Hydrator_Abstract
// do we need to index by a custom field?
if
(
$field
=
$this
->
_getCustomIndexField
(
$rootAlias
))
{
if
(
isset
(
$result
[
$field
]))
{
throw
new
Doctrine_Hydrat
e
_Exception
(
"Couldn't hydrate. Found non-unique key mapping."
);
throw
new
Doctrine_Hydrat
or
_Exception
(
"Couldn't hydrate. Found non-unique key mapping."
);
}
else
if
(
!
isset
(
$element
[
$field
]))
{
throw
new
Doctrine_Hydrat
e
_Exception
(
"Couldn't hydrate. Found a non-existent key."
);
throw
new
Doctrine_Hydrat
or
_Exception
(
"Couldn't hydrate. Found a non-existent key."
);
}
$result
[
$element
[
$field
]]
=
$element
;
}
else
{
...
...
@@ -166,17 +156,16 @@ class Doctrine_Hydrator_Default extends Doctrine_Hydrator_Abstract
unset
(
$rowData
[
$rootAlias
]);
// end hydrate data of the root component for the current row
//echo "\$result after root element hydration:<br />";
//Doctrine::dump($result);
//echo "<br /><br />";
// $prev[$rootAlias] now points to the last element in $result.
// now hydrate the rest of the data found in the current row, that belongs to other
// (related) components
// (related) components
.
$oneToOne
=
false
;
foreach
(
$rowData
as
$
a
lias
=>
$data
)
{
foreach
(
$rowData
as
$
dqlA
lias
=>
$data
)
{
$index
=
false
;
$map
=
$this
->
_
aliasMap
[
$a
lias
];
$table
=
$
this
->
_aliasMap
[
$alias
]
[
'table'
];
$map
=
$this
->
_
queryComponents
[
$dqlA
lias
];
$table
=
$
map
[
'table'
];
$componentName
=
$table
->
getComponentName
();
$event
->
set
(
'data'
,
$data
);
$listeners
[
$componentName
]
->
preHydrate
(
$event
);
...
...
@@ -185,67 +174,63 @@ class Doctrine_Hydrator_Default extends Doctrine_Hydrator_Abstract
$parent
=
$map
[
'parent'
];
$relation
=
$map
[
'relation'
];
$
component
Alias
=
$map
[
'relation'
]
->
getAlias
();
$
relation
Alias
=
$map
[
'relation'
]
->
getAlias
();
$path
=
$parent
.
'.'
.
$
a
lias
;
$path
=
$parent
.
'.'
.
$
dqlA
lias
;
if
(
!
isset
(
$prev
[
$parent
]))
{
break
;
}
// check the type of the relation
if
(
!
$relation
->
isOneToOne
()
&&
$driver
->
initRelated
(
$prev
[
$parent
],
$
component
Alias
))
{
if
(
!
$relation
->
isOneToOne
()
&&
$driver
->
initRelated
(
$prev
[
$parent
],
$
relation
Alias
))
{
// append element
if
(
isset
(
$identifiable
[
$alias
]))
{
if
(
$isSimpleQuery
||
!
isset
(
$identifierMap
[
$path
][
$id
[
$parent
]][
$id
[
$alias
]]))
{
//$index = false;
if
(
isset
(
$nonemptyComponents
[
$dqlAlias
]))
{
if
(
$isSimpleQuery
||
!
isset
(
$identifierMap
[
$path
][
$id
[
$parent
]][
$id
[
$dqlAlias
]]))
{
$event
->
set
(
'data'
,
$element
);
$listeners
[
$componentName
]
->
postHydrate
(
$event
);
if
(
$field
=
$this
->
_getCustomIndexField
(
$
a
lias
))
{
if
(
isset
(
$prev
[
$parent
][
$
component
Alias
][
$field
]))
{
throw
new
Doctrine_Hydrat
e
_Exception
(
"Couldn't hydrate. Found non-unique key mapping."
);
if
(
$field
=
$this
->
_getCustomIndexField
(
$
dqlA
lias
))
{
if
(
isset
(
$prev
[
$parent
][
$
relation
Alias
][
$field
]))
{
throw
new
Doctrine_Hydrat
or
_Exception
(
"Couldn't hydrate. Found non-unique key mapping."
);
}
else
if
(
!
isset
(
$element
[
$field
]))
{
throw
new
Doctrine_Hydrat
e
_Exception
(
"Couldn't hydrate. Found a non-existent key."
);
throw
new
Doctrine_Hydrat
or
_Exception
(
"Couldn't hydrate. Found a non-existent key."
);
}
$prev
[
$parent
][
$
component
Alias
][
$element
[
$field
]]
=
$element
;
$prev
[
$parent
][
$
relation
Alias
][
$element
[
$field
]]
=
$element
;
}
else
{
$prev
[
$parent
][
$
component
Alias
][]
=
$element
;
$prev
[
$parent
][
$
relation
Alias
][]
=
$element
;
}
$identifierMap
[
$path
][
$id
[
$parent
]][
$id
[
$
alias
]]
=
$driver
->
getLastKey
(
$prev
[
$parent
][
$component
Alias
]);
$identifierMap
[
$path
][
$id
[
$parent
]][
$id
[
$
dqlAlias
]]
=
$driver
->
getLastKey
(
$prev
[
$parent
][
$relation
Alias
]);
}
else
{
$index
=
$identifierMap
[
$path
][
$id
[
$parent
]][
$id
[
$
a
lias
]];
$index
=
$identifierMap
[
$path
][
$id
[
$parent
]][
$id
[
$
dqlA
lias
]];
}
}
// register collection for later snapshots
$driver
->
registerCollection
(
$prev
[
$parent
][
$
component
Alias
]);
$driver
->
registerCollection
(
$prev
[
$parent
][
$
relation
Alias
]);
}
else
{
if
(
!
isset
(
$identifiable
[
$alias
]))
{
$prev
[
$parent
][
$componentAlias
]
=
$driver
->
getNullPointer
();
// 1-1 relation
$oneToOne
=
true
;
if
(
!
isset
(
$nonemptyComponents
[
$dqlAlias
]))
{
$prev
[
$parent
][
$relationAlias
]
=
$driver
->
getNullPointer
();
}
else
{
$prev
[
$parent
][
$
component
Alias
]
=
$element
;
$prev
[
$parent
][
$
relation
Alias
]
=
$element
;
}
$oneToOne
=
true
;
}
$coll
=&
$prev
[
$parent
][
$
component
Alias
];
$this
->
_setLastElement
(
$prev
,
$coll
,
$index
,
$
a
lias
,
$oneToOne
);
$id
[
$
a
lias
]
=
''
;
$coll
=&
$prev
[
$parent
][
$
relation
Alias
];
$this
->
_setLastElement
(
$prev
,
$coll
,
$index
,
$
dqlA
lias
,
$oneToOne
);
$id
[
$
dqlA
lias
]
=
''
;
}
//echo "\$result after related element hydration:<br />";
//Doctrine::dump($result);
//echo "<br /><br />";
$id
[
$rootAlias
]
=
''
;
}
$driver
->
flush
();
$stmt
->
closeCursor
();
$driver
->
flush
();
//$e = microtime(true);
//echo 'Hydration took: ' . ($e - $s) . ' for '.count($result).' records<br />';
return
$result
;
}
...
...
@@ -259,30 +244,30 @@ class Doctrine_Hydrator_Default extends Doctrine_Hydrator_Abstract
* @return void
* @todo Detailed documentation
*/
protected
function
_setLastElement
(
&
$prev
,
&
$coll
,
$index
,
$
a
lias
,
$oneToOne
)
protected
function
_setLastElement
(
&
$prev
,
&
$coll
,
$index
,
$
dqlA
lias
,
$oneToOne
)
{
if
(
$coll
===
self
::
$_null
)
{
return
false
;
}
if
(
$index
!==
false
)
{
//
Set lement at $index as
previous element for the component
//
Link element at $index to
previous element for the component
// identified by the DQL alias $alias
$prev
[
$
a
lias
]
=&
$coll
[
$index
];
$prev
[
$
dqlA
lias
]
=&
$coll
[
$index
];
return
;
}
if
(
is_array
(
$coll
)
&&
$coll
)
{
if
(
$oneToOne
)
{
$prev
[
$
a
lias
]
=&
$coll
;
$prev
[
$
dqlA
lias
]
=&
$coll
;
}
else
{
end
(
$coll
);
$prev
[
$
a
lias
]
=&
$coll
[
key
(
$coll
)];
$prev
[
$
dqlA
lias
]
=&
$coll
[
key
(
$coll
)];
}
}
else
if
(
count
(
$coll
)
>
0
)
{
$prev
[
$
a
lias
]
=
$coll
->
getLast
();
}
else
if
(
isset
(
$prev
[
$
a
lias
]))
{
unset
(
$prev
[
$
a
lias
]);
$prev
[
$
dqlA
lias
]
=
$coll
->
getLast
();
}
else
if
(
isset
(
$prev
[
$
dqlA
lias
]))
{
unset
(
$prev
[
$
dqlA
lias
]);
}
}
...
...
@@ -294,7 +279,7 @@ class Doctrine_Hydrator_Default extends Doctrine_Hydrator_Abstract
* @return array An array with all the fields (name => value) of the data row,
* grouped by their component (alias).
*/
protected
function
_gatherRowData
(
&
$data
,
&
$cache
,
&
$id
,
&
$
identifiable
)
protected
function
_gatherRowData
(
&
$data
,
&
$cache
,
&
$id
,
&
$
nonemptyComponents
)
{
$rowData
=
array
();
...
...
@@ -302,29 +287,29 @@ class Doctrine_Hydrator_Default extends Doctrine_Hydrator_Abstract
// Parse each column name only once. Cache the results.
if
(
!
isset
(
$cache
[
$key
]))
{
$e
=
explode
(
'__'
,
$key
);
$last
=
strtolower
(
array_pop
(
$e
));
$cache
[
$key
][
'
a
lias'
]
=
$this
->
_tableAliases
[
strtolower
(
implode
(
'__'
,
$e
))];
$fieldName
=
$this
->
_
aliasMap
[
$cache
[
$key
][
'a
lias'
]][
'table'
]
->
getFieldName
(
$last
);
$last
=
strtolower
(
array_pop
(
$e
));
$cache
[
$key
][
'
dqlA
lias'
]
=
$this
->
_tableAliases
[
strtolower
(
implode
(
'__'
,
$e
))];
$fieldName
=
$this
->
_
queryComponents
[
$cache
[
$key
][
'dqlA
lias'
]][
'table'
]
->
getFieldName
(
$last
);
$cache
[
$key
][
'fieldName'
]
=
$fieldName
;
}
$map
=
$this
->
_
aliasMap
[
$cache
[
$key
][
'a
lias'
]];
$map
=
$this
->
_
queryComponents
[
$cache
[
$key
][
'dqlA
lias'
]];
$table
=
$map
[
'table'
];
$
alias
=
$cache
[
$key
][
'a
lias'
];
$
dqlAlias
=
$cache
[
$key
][
'dqlA
lias'
];
$fieldName
=
$cache
[
$key
][
'fieldName'
];
if
(
isset
(
$this
->
_
aliasMap
[
$a
lias
][
'agg'
][
$fieldName
]))
{
$fieldName
=
$this
->
_
aliasMap
[
$a
lias
][
'agg'
][
$fieldName
];
if
(
isset
(
$this
->
_
queryComponents
[
$dqlA
lias
][
'agg'
][
$fieldName
]))
{
$fieldName
=
$this
->
_
queryComponents
[
$dqlA
lias
][
'agg'
][
$fieldName
];
}
if
(
$table
->
isIdentifier
(
$fieldName
))
{
$id
[
$
a
lias
]
.=
'|'
.
$value
;
$id
[
$
dqlA
lias
]
.=
'|'
.
$value
;
}
$rowData
[
$
a
lias
][
$fieldName
]
=
$table
->
prepareValue
(
$fieldName
,
$value
);
$rowData
[
$
dqlA
lias
][
$fieldName
]
=
$table
->
prepareValue
(
$fieldName
,
$value
);
if
(
$value
!==
null
)
{
$
identifiable
[
$a
lias
]
=
true
;
if
(
!
isset
(
$nonemptyComponents
[
$dqlAlias
])
&&
$value
!==
null
)
{
$
nonemptyComponents
[
$dqlA
lias
]
=
true
;
}
}
...
...
@@ -339,7 +324,7 @@ class Doctrine_Hydrator_Default extends Doctrine_Hydrator_Abstract
*/
protected
function
_getCustomIndexField
(
$alias
)
{
return
isset
(
$this
->
_
aliasMap
[
$alias
][
'map'
])
?
$this
->
_aliasMap
[
$alias
][
'map'
]
:
null
;
return
isset
(
$this
->
_
queryComponents
[
$alias
][
'map'
])
?
$this
->
_queryComponents
[
$alias
][
'map'
]
:
null
;
}
}
lib/Doctrine/Hydrator/Default/
FetchModeDriver/Array
.php
→
lib/Doctrine/Hydrator/Default/
ArrayDriver
.php
View file @
929273a0
...
...
@@ -31,7 +31,7 @@
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class
Doctrine_Hydrator_Default_
FetchModeDriver_Array
class
Doctrine_Hydrator_Default_
ArrayDriver
{
public
function
getElementCollection
(
$component
)
{
...
...
lib/Doctrine/Hydrator/Default/
FetchModeDriver/Record
.php
→
lib/Doctrine/Hydrator/Default/
RecordDriver
.php
View file @
929273a0
...
...
@@ -31,7 +31,7 @@
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class
Doctrine_Hydrator_Default_
FetchModeDriver_Record
extends
Doctrine_Locator_Injectable
class
Doctrine_Hydrator_Default_
RecordDriver
extends
Doctrine_Locator_Injectable
{
protected
$_collections
=
array
();
...
...
@@ -56,12 +56,14 @@ class Doctrine_Hydrator_Default_FetchModeDriver_Record extends Doctrine_Locator_
public
function
initRelated
(
$record
,
$name
)
{
return
true
;
/*
if ( ! is_array($record)) {
$record[$name];
return true;
}
return false;
*/
}
public
function
registerCollection
(
Doctrine_Collection
$coll
)
...
...
lib/Doctrine/Hydrat
e
/Exception.php
→
lib/Doctrine/Hydrat
or
/Exception.php
View file @
929273a0
<?php
/*
* $Id: Exception.php 1080 2007-02-10 18:17:08Z romanb $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
Doctrine
::
autoload
(
'Doctrine_Exception'
);
/**
* Doctrine_Hydrat
e_Exception
*
* @package Doctrine
* @subpackage Hydrate
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision: 1080 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class
Doctrine_Hydrat
e_Exception
extends
Doctrine_Exception
<?php
/*
* $Id: Exception.php 1080 2007-02-10 18:17:08Z romanb $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
Doctrine
::
autoload
(
'Doctrine_Exception'
);
/**
* Doctrine_Hydrat
or_Exception
*
* @package Doctrine
* @subpackage Hydrate
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision: 1080 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class
Doctrine_Hydrat
or_Exception
extends
Doctrine_Exception
{
}
\ No newline at end of file
lib/Doctrine/Query.php
View file @
929273a0
...
...
@@ -208,31 +208,6 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
$this
->
_params
=
$params
;
}
/**
* getCachedForm
* returns the cached form of this query for given resultSet
*
* @param array $resultSet
* @return string serialized string representation of this query
*/
public
function
getCachedForm
(
array
$resultSet
)
{
$map
=
''
;
foreach
(
$this
->
getAliasMap
()
as
$k
=>
$v
)
{
if
(
!
isset
(
$v
[
'parent'
]))
{
$map
[
$k
][]
=
$v
[
'table'
]
->
getComponentName
();
}
else
{
$map
[
$k
][]
=
$v
[
'parent'
]
.
'.'
.
$v
[
'relation'
]
->
getAlias
();
}
if
(
isset
(
$v
[
'agg'
]))
{
$map
[
$k
][]
=
$v
[
'agg'
];
}
}
return
serialize
(
array
(
$resultSet
,
$map
,
$this
->
getTableAliases
()));
}
/**
* fetchArray
* Convenience method to execute using array fetching as hydration mode.
...
...
@@ -950,8 +925,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
}
if
(
count
(
$tableAliases
)
!==
1
)
{
$componentAlias
=
reset
(
$this
->
tableAliases
);
$tableAlias
=
key
(
$this
->
tableAliases
);
$componentAlias
=
reset
(
$this
->
_
tableAliases
);
$tableAlias
=
key
(
$this
->
_
tableAliases
);
}
$index
=
count
(
$this
->
aggregateMap
);
...
...
@@ -1405,7 +1380,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
{
$e
=
Doctrine_Tokenizer
::
sqlExplode
(
$query
,
' '
);
foreach
(
$e
as
$k
=>
$part
)
{
foreach
(
$e
as
$k
=>
$part
)
{
$part
=
trim
(
$part
);
switch
(
strtolower
(
$part
))
{
case
'delete'
:
...
...
@@ -1752,7 +1727,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
$queryPart
.=
' '
.
$this
->
_conn
->
quoteIdentifier
(
$tableAlias
);
}
$this
->
tableAliases
[
$tableAlias
]
=
$componentAlias
;
$this
->
_
tableAliases
[
$tableAlias
]
=
$componentAlias
;
$queryPart
.=
$this
->
buildInheritanceJoinSql
(
$name
,
$componentAlias
);
...
...
lib/Doctrine/Query/Abstract.php
View file @
929273a0
...
...
@@ -752,8 +752,9 @@ abstract class Doctrine_Query_Abstract
if
(
$cached
===
false
)
{
// cache miss
$stmt
=
$this
->
_execute
(
$params
);
$array
=
$this
->
_hydrator
->
hydrateResultSet
(
$stmt
,
$this
->
_aliasMap
,
$this
->
_tableAliases
,
Doctrine
::
HYDRATE_ARRAY
);
$this
->
_hydrator
->
setQueryComponents
(
$this
->
_aliasMap
);
$array
=
$this
->
_hydrator
->
hydrateResultSet
(
$stmt
,
$this
->
_tableAliases
,
Doctrine
::
HYDRATE_ARRAY
);
$cached
=
$this
->
getCachedForm
(
$array
);
...
...
@@ -786,12 +787,36 @@ abstract class Doctrine_Query_Abstract
return
$stmt
;
}
$
array
=
$this
->
_hydrator
->
hydrateResultSet
(
$stmt
,
$this
->
_aliasMap
,
$this
->
_tableAliases
,
$hydrationMode
);
$
this
->
_hydrator
->
setQueryComponents
(
$this
->
_aliasMap
);
$array
=
$this
->
_hydrator
->
hydrateResultSet
(
$stmt
,
$this
->
_tableAliases
,
$hydrationMode
);
}
return
$array
;
}
/**
* getCachedForm
* returns the cached form of this query for given resultSet
*
* @param array $resultSet
* @return string serialized string representation of this query
*/
public
function
getCachedForm
(
array
$resultSet
)
{
$map
=
array
();
foreach
(
$this
->
getAliasMap
()
as
$k
=>
$v
)
{
if
(
!
isset
(
$v
[
'parent'
]))
{
$map
[
$k
][]
=
$v
[
'table'
]
->
getComponentName
();
}
else
{
$map
[
$k
][]
=
$v
[
'parent'
]
.
'.'
.
$v
[
'relation'
]
->
getAlias
();
}
if
(
isset
(
$v
[
'agg'
]))
{
$map
[
$k
][]
=
$v
[
'agg'
];
}
}
return
serialize
(
array
(
$resultSet
,
$map
,
$this
->
getTableAliases
()));
}
/**
* addSelect
...
...
tests/HydrateTestCase.php
View file @
929273a0
...
...
@@ -98,7 +98,7 @@ class Doctrine_Hydrate_Mock extends Doctrine_Hydrator_Abstract
$this
->
data
=
$data
;
}
public
function
hydrateResultSet
(
$stmt
,
$
aliasMap
,
$
tableAliases
,
$hydrationMode
=
null
)
public
function
hydrateResultSet
(
$stmt
,
$tableAliases
,
$hydrationMode
=
null
)
{
return
true
;
}
...
...
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