| 1 |
lars |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
* $Id$
|
|
|
4 |
*
|
|
|
5 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
6 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
7 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
8 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
9 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
10 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
11 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
12 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
13 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
14 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
15 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
16 |
*
|
|
|
17 |
* This software consists of voluntary contributions made by many individuals
|
|
|
18 |
* and is licensed under the LGPL. For more information, see
|
|
|
19 |
* <http://www.doctrine-project.org>.
|
|
|
20 |
*/
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* Builds result sets in to the object graph using Doctrine_Record instances
|
|
|
24 |
*
|
|
|
25 |
* @package Doctrine
|
|
|
26 |
* @subpackage Hydrate
|
|
|
27 |
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
|
28 |
* @link www.doctrine-project.org
|
|
|
29 |
* @since 1.0
|
|
|
30 |
* @version $Revision$
|
|
|
31 |
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
|
|
32 |
* @author Roman Borschel <roman@code-factory.org>
|
|
|
33 |
* @author Jonathan H. Wage <jonwage@gmail.com>
|
|
|
34 |
*/
|
|
|
35 |
class Doctrine_Hydrator_RecordDriver extends Doctrine_Hydrator_Graph
|
|
|
36 |
{
|
|
|
37 |
protected $_collections = array();
|
|
|
38 |
private $_initializedRelations = array();
|
|
|
39 |
|
|
|
40 |
public function getElementCollection($component)
|
|
|
41 |
{
|
|
|
42 |
$coll = Doctrine_Collection::create($component);
|
|
|
43 |
$this->_collections[] = $coll;
|
|
|
44 |
|
|
|
45 |
return $coll;
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
public function initRelated(&$record, $name, $keyColumn = null)
|
|
|
49 |
{
|
|
|
50 |
if ( ! isset($this->_initializedRelations[$record->getOid()][$name])) {
|
|
|
51 |
$relation = $record->getTable()->getRelation($name);
|
|
|
52 |
$coll = Doctrine_Collection::create($relation->getTable()->getComponentName(), $keyColumn);
|
|
|
53 |
$coll->setReference($record, $relation);
|
|
|
54 |
$record[$name] = $coll;
|
|
|
55 |
$this->_initializedRelations[$record->getOid()][$name] = true;
|
|
|
56 |
}
|
|
|
57 |
return true;
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
public function registerCollection($coll)
|
|
|
61 |
{
|
|
|
62 |
$this->_collections[] = $coll;
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
public function getNullPointer()
|
|
|
66 |
{
|
|
|
67 |
return self::$_null;
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
public function getElement(array $data, $component)
|
|
|
71 |
{
|
|
|
72 |
$component = $this->_getClassNameToReturn($data, $component);
|
|
|
73 |
|
|
|
74 |
$this->_tables[$component]->setData($data);
|
|
|
75 |
$record = $this->_tables[$component]->getRecord();
|
|
|
76 |
|
|
|
77 |
return $record;
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
public function getLastKey(&$coll)
|
|
|
81 |
{
|
|
|
82 |
$coll->end();
|
|
|
83 |
|
|
|
84 |
return $coll->key();
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
/**
|
|
|
88 |
* sets the last element of given data array / collection
|
|
|
89 |
* as previous element
|
|
|
90 |
*
|
|
|
91 |
* @param boolean|integer $index
|
|
|
92 |
* @return void
|
|
|
93 |
* @todo Detailed documentation
|
|
|
94 |
*/
|
|
|
95 |
public function setLastElement(&$prev, &$coll, $index, $dqlAlias, $oneToOne)
|
|
|
96 |
{
|
|
|
97 |
if ($coll === self::$_null) {
|
|
|
98 |
unset($prev[$dqlAlias]); // Ticket #1228
|
|
|
99 |
return;
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
if ($index !== false) {
|
|
|
103 |
// Link element at $index to previous element for the component
|
|
|
104 |
// identified by the DQL alias $alias
|
|
|
105 |
$prev[$dqlAlias] = $coll[$index];
|
|
|
106 |
return;
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
if (count($coll) > 0) {
|
|
|
110 |
$prev[$dqlAlias] = $coll->getLast();
|
|
|
111 |
}
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
public function flush()
|
|
|
115 |
{
|
|
|
116 |
// take snapshots from all initialized collections
|
|
|
117 |
foreach ($this->_collections as $key => $coll) {
|
|
|
118 |
$coll->takeSnapshot();
|
|
|
119 |
}
|
|
|
120 |
$this->_initializedRelations = null;
|
|
|
121 |
$this->_collections = null;
|
|
|
122 |
$this->_tables = null;
|
|
|
123 |
}
|
|
|
124 |
}
|