Completed
Pull Request — 4.1 (#105)
by David
08:15 queued 03:37
created
src/Mouf/Database/TDBM/TDBMSchemaAnalyzer.php 2 patches
Indentation   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -14,138 +14,138 @@
 block discarded – undo
14 14
  */
15 15
 class TDBMSchemaAnalyzer
16 16
 {
17
-    private $connection;
18
-
19
-    /**
20
-     * @var Schema
21
-     */
22
-    private $schema;
23
-
24
-    /**
25
-     * @var string
26
-     */
27
-    private $cachePrefix;
28
-
29
-    /**
30
-     * @var Cache
31
-     */
32
-    private $cache;
33
-
34
-    /**
35
-     * @var SchemaAnalyzer
36
-     */
37
-    private $schemaAnalyzer;
38
-
39
-    /**
40
-     * @param Connection     $connection     The DBAL DB connection to use
41
-     * @param Cache          $cache          A cache service to be used
42
-     * @param SchemaAnalyzer $schemaAnalyzer The schema analyzer that will be used to find shortest paths...
43
-     *                                       Will be automatically created if not passed
44
-     */
45
-    public function __construct(Connection $connection, Cache $cache, SchemaAnalyzer $schemaAnalyzer)
46
-    {
47
-        $this->connection = $connection;
48
-        $this->cache = $cache;
49
-        $this->schemaAnalyzer = $schemaAnalyzer;
50
-    }
51
-
52
-    /**
53
-     * Returns a unique ID for the current connection. Useful for namespacing cache entries in the current connection.
54
-     *
55
-     * @return string
56
-     */
57
-    public function getCachePrefix()
58
-    {
59
-        if ($this->cachePrefix === null) {
60
-            $this->cachePrefix = hash('md4', $this->connection->getHost().'-'.$this->connection->getPort().'-'.$this->connection->getDatabase().'-'.$this->connection->getDriver()->getName());
61
-        }
62
-
63
-        return $this->cachePrefix;
64
-    }
65
-
66
-    /**
67
-     * Returns the (cached) schema.
68
-     *
69
-     * @return Schema
70
-     */
71
-    public function getSchema()
72
-    {
73
-        if ($this->schema === null) {
74
-            $cacheKey = $this->getCachePrefix().'_schema';
75
-            if ($this->cache->contains($cacheKey)) {
76
-                $this->schema = $this->cache->fetch($cacheKey);
77
-            } else {
78
-                $this->schema = $this->connection->getSchemaManager()->createSchema();
79
-                $this->cache->save($cacheKey, $this->schema);
80
-            }
81
-        }
82
-
83
-        return $this->schema;
84
-    }
85
-
86
-    /**
87
-     * Returns the list of pivot tables linked to table $tableName.
88
-     *
89
-     * @param string $tableName
90
-     *
91
-     * @return array|string[]
92
-     */
93
-    public function getPivotTableLinkedToTable($tableName)
94
-    {
95
-        $cacheKey = $this->getCachePrefix().'_pivottables_link_'.$tableName;
96
-        if ($this->cache->contains($cacheKey)) {
97
-            return $this->cache->fetch($cacheKey);
98
-        }
99
-
100
-        $pivotTables = [];
101
-
102
-        $junctionTables = $this->schemaAnalyzer->detectJunctionTables(true);
103
-        foreach ($junctionTables as $table) {
104
-            $fks = $table->getForeignKeys();
105
-            foreach ($fks as $fk) {
106
-                if ($fk->getForeignTableName() == $tableName) {
107
-                    $pivotTables[] = $table->getName();
108
-                    break;
109
-                }
110
-            }
111
-        }
112
-
113
-        $this->cache->save($cacheKey, $pivotTables);
114
-
115
-        return $pivotTables;
116
-    }
117
-
118
-    /**
119
-     * Returns the list of foreign keys pointing to the table represented by this bean, excluding foreign keys
120
-     * from junction tables and from inheritance.
121
-     *
122
-     * @return ForeignKeyConstraint[]
123
-     */
124
-    public function getIncomingForeignKeys($tableName)
125
-    {
126
-        $junctionTables = $this->schemaAnalyzer->detectJunctionTables(true);
127
-        $junctionTableNames = array_map(function (Table $table) {
128
-            return $table->getName();
129
-        }, $junctionTables);
130
-        $childrenRelationships = $this->schemaAnalyzer->getChildrenRelationships($tableName);
131
-
132
-        $fks = [];
133
-        foreach ($this->getSchema()->getTables() as $table) {
134
-            foreach ($table->getForeignKeys() as $fk) {
135
-                if ($fk->getForeignTableName() === $tableName) {
136
-                    if (in_array($fk->getLocalTableName(), $junctionTableNames)) {
137
-                        continue;
138
-                    }
139
-                    foreach ($childrenRelationships as $childFk) {
140
-                        if ($fk->getLocalTableName() === $childFk->getLocalTableName() && $fk->getLocalColumns() === $childFk->getLocalColumns()) {
141
-                            continue 2;
142
-                        }
143
-                    }
144
-                    $fks[] = $fk;
145
-                }
146
-            }
147
-        }
148
-
149
-        return $fks;
150
-    }
17
+	private $connection;
18
+
19
+	/**
20
+	 * @var Schema
21
+	 */
22
+	private $schema;
23
+
24
+	/**
25
+	 * @var string
26
+	 */
27
+	private $cachePrefix;
28
+
29
+	/**
30
+	 * @var Cache
31
+	 */
32
+	private $cache;
33
+
34
+	/**
35
+	 * @var SchemaAnalyzer
36
+	 */
37
+	private $schemaAnalyzer;
38
+
39
+	/**
40
+	 * @param Connection     $connection     The DBAL DB connection to use
41
+	 * @param Cache          $cache          A cache service to be used
42
+	 * @param SchemaAnalyzer $schemaAnalyzer The schema analyzer that will be used to find shortest paths...
43
+	 *                                       Will be automatically created if not passed
44
+	 */
45
+	public function __construct(Connection $connection, Cache $cache, SchemaAnalyzer $schemaAnalyzer)
46
+	{
47
+		$this->connection = $connection;
48
+		$this->cache = $cache;
49
+		$this->schemaAnalyzer = $schemaAnalyzer;
50
+	}
51
+
52
+	/**
53
+	 * Returns a unique ID for the current connection. Useful for namespacing cache entries in the current connection.
54
+	 *
55
+	 * @return string
56
+	 */
57
+	public function getCachePrefix()
58
+	{
59
+		if ($this->cachePrefix === null) {
60
+			$this->cachePrefix = hash('md4', $this->connection->getHost().'-'.$this->connection->getPort().'-'.$this->connection->getDatabase().'-'.$this->connection->getDriver()->getName());
61
+		}
62
+
63
+		return $this->cachePrefix;
64
+	}
65
+
66
+	/**
67
+	 * Returns the (cached) schema.
68
+	 *
69
+	 * @return Schema
70
+	 */
71
+	public function getSchema()
72
+	{
73
+		if ($this->schema === null) {
74
+			$cacheKey = $this->getCachePrefix().'_schema';
75
+			if ($this->cache->contains($cacheKey)) {
76
+				$this->schema = $this->cache->fetch($cacheKey);
77
+			} else {
78
+				$this->schema = $this->connection->getSchemaManager()->createSchema();
79
+				$this->cache->save($cacheKey, $this->schema);
80
+			}
81
+		}
82
+
83
+		return $this->schema;
84
+	}
85
+
86
+	/**
87
+	 * Returns the list of pivot tables linked to table $tableName.
88
+	 *
89
+	 * @param string $tableName
90
+	 *
91
+	 * @return array|string[]
92
+	 */
93
+	public function getPivotTableLinkedToTable($tableName)
94
+	{
95
+		$cacheKey = $this->getCachePrefix().'_pivottables_link_'.$tableName;
96
+		if ($this->cache->contains($cacheKey)) {
97
+			return $this->cache->fetch($cacheKey);
98
+		}
99
+
100
+		$pivotTables = [];
101
+
102
+		$junctionTables = $this->schemaAnalyzer->detectJunctionTables(true);
103
+		foreach ($junctionTables as $table) {
104
+			$fks = $table->getForeignKeys();
105
+			foreach ($fks as $fk) {
106
+				if ($fk->getForeignTableName() == $tableName) {
107
+					$pivotTables[] = $table->getName();
108
+					break;
109
+				}
110
+			}
111
+		}
112
+
113
+		$this->cache->save($cacheKey, $pivotTables);
114
+
115
+		return $pivotTables;
116
+	}
117
+
118
+	/**
119
+	 * Returns the list of foreign keys pointing to the table represented by this bean, excluding foreign keys
120
+	 * from junction tables and from inheritance.
121
+	 *
122
+	 * @return ForeignKeyConstraint[]
123
+	 */
124
+	public function getIncomingForeignKeys($tableName)
125
+	{
126
+		$junctionTables = $this->schemaAnalyzer->detectJunctionTables(true);
127
+		$junctionTableNames = array_map(function (Table $table) {
128
+			return $table->getName();
129
+		}, $junctionTables);
130
+		$childrenRelationships = $this->schemaAnalyzer->getChildrenRelationships($tableName);
131
+
132
+		$fks = [];
133
+		foreach ($this->getSchema()->getTables() as $table) {
134
+			foreach ($table->getForeignKeys() as $fk) {
135
+				if ($fk->getForeignTableName() === $tableName) {
136
+					if (in_array($fk->getLocalTableName(), $junctionTableNames)) {
137
+						continue;
138
+					}
139
+					foreach ($childrenRelationships as $childFk) {
140
+						if ($fk->getLocalTableName() === $childFk->getLocalTableName() && $fk->getLocalColumns() === $childFk->getLocalColumns()) {
141
+							continue 2;
142
+						}
143
+					}
144
+					$fks[] = $fk;
145
+				}
146
+			}
147
+		}
148
+
149
+		return $fks;
150
+	}
151 151
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -124,7 +124,7 @@
 block discarded – undo
124 124
     public function getIncomingForeignKeys($tableName)
125 125
     {
126 126
         $junctionTables = $this->schemaAnalyzer->detectJunctionTables(true);
127
-        $junctionTableNames = array_map(function (Table $table) {
127
+        $junctionTableNames = array_map(function(Table $table) {
128 128
             return $table->getName();
129 129
         }, $junctionTables);
130 130
         $childrenRelationships = $this->schemaAnalyzer->getChildrenRelationships($tableName);
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/InnerResultIterator.php 1 patch
Indentation   +257 added lines, -257 removed lines patch added patch discarded remove patch
@@ -29,261 +29,261 @@
 block discarded – undo
29 29
  */
30 30
 class InnerResultIterator implements \Iterator, \Countable, \ArrayAccess
31 31
 {
32
-    /**
33
-     * @var Statement
34
-     */
35
-    protected $statement;
36
-
37
-    protected $fetchStarted = false;
38
-    private $objectStorage;
39
-    private $className;
40
-
41
-    private $tdbmService;
42
-    private $magicSql;
43
-    private $parameters;
44
-    private $limit;
45
-    private $offset;
46
-    private $columnDescriptors;
47
-    private $magicQuery;
48
-
49
-    /**
50
-     * The key of the current retrieved object.
51
-     *
52
-     * @var int
53
-     */
54
-    protected $key = -1;
55
-
56
-    protected $current = null;
57
-
58
-    private $databasePlatform;
59
-
60
-    /**
61
-     * @var LoggerInterface
62
-     */
63
-    private $logger;
64
-
65
-    public function __construct($magicSql, array $parameters, $limit, $offset, array $columnDescriptors, $objectStorage, $className, TDBMService $tdbmService, MagicQuery $magicQuery, LoggerInterface $logger)
66
-    {
67
-        $this->magicSql = $magicSql;
68
-        $this->objectStorage = $objectStorage;
69
-        $this->className = $className;
70
-        $this->tdbmService = $tdbmService;
71
-        $this->parameters = $parameters;
72
-        $this->limit = $limit;
73
-        $this->offset = $offset;
74
-        $this->columnDescriptors = $columnDescriptors;
75
-        $this->magicQuery = $magicQuery;
76
-        $this->databasePlatform = $this->tdbmService->getConnection()->getDatabasePlatform();
77
-        $this->logger = $logger;
78
-    }
79
-
80
-    protected function executeQuery()
81
-    {
82
-        $sql = $this->magicQuery->build($this->magicSql, $this->parameters);
83
-        $sql = $this->tdbmService->getConnection()->getDatabasePlatform()->modifyLimitQuery($sql, $this->limit, $this->offset);
84
-
85
-        $this->logger->debug('Running SQL request: '.$sql);
86
-
87
-        $this->statement = $this->tdbmService->getConnection()->executeQuery($sql, $this->parameters);
88
-
89
-        $this->fetchStarted = true;
90
-    }
91
-
92
-    /**
93
-     * Counts found records (this is the number of records fetched, taking into account the LIMIT and OFFSET settings).
94
-     *
95
-     * @return int
96
-     */
97
-    public function count()
98
-    {
99
-        if (!$this->fetchStarted) {
100
-            $this->executeQuery();
101
-        }
102
-
103
-        return $this->statement->rowCount();
104
-    }
105
-
106
-    /**
107
-     * Fetches record at current cursor.
108
-     *
109
-     * @return AbstractTDBMObject|null
110
-     */
111
-    public function current()
112
-    {
113
-        return $this->current;
114
-    }
115
-
116
-    /**
117
-     * Returns the current result's key.
118
-     *
119
-     * @return int
120
-     */
121
-    public function key()
122
-    {
123
-        return $this->key;
124
-    }
125
-
126
-    /**
127
-     * Advances the cursor to the next result.
128
-     * Casts the database result into one (or several) beans.
129
-     */
130
-    public function next()
131
-    {
132
-        $row = $this->statement->fetch(\PDO::FETCH_NUM);
133
-        if ($row) {
134
-
135
-            // array<tablegroup, array<table, array<column, value>>>
136
-            $beansData = [];
137
-            foreach ($row as $i => $value) {
138
-                $columnDescriptor = $this->columnDescriptors[$i];
139
-                // Let's cast the value according to its type
140
-                $value = $columnDescriptor['type']->convertToPHPValue($value, $this->databasePlatform);
141
-
142
-                $beansData[$columnDescriptor['tableGroup']][$columnDescriptor['table']][$columnDescriptor['column']] = $value;
143
-            }
144
-
145
-            $reflectionClassCache = [];
146
-            $firstBean = true;
147
-            foreach ($beansData as $beanData) {
148
-
149
-                // Let's find the bean class name associated to the bean.
150
-
151
-                list($actualClassName, $mainBeanTableName, $tablesUsed) = $this->tdbmService->_getClassNameFromBeanData($beanData);
152
-
153
-                if ($this->className !== null) {
154
-                    $actualClassName = $this->className;
155
-                }
156
-
157
-                // Let's filter out the beanData that is not used (because it belongs to a part of the hierarchy that is not fetched:
158
-                foreach ($beanData as $tableName => $descriptors) {
159
-                    if (!in_array($tableName, $tablesUsed)) {
160
-                        unset($beanData[$tableName]);
161
-                    }
162
-                }
163
-
164
-                // Must we create the bean? Let's see in the cache if we have a mapping DbRow?
165
-                // Let's get the first object mapping a row:
166
-                // We do this loop only for the first table
167
-
168
-                $primaryKeys = $this->tdbmService->_getPrimaryKeysFromObjectData($mainBeanTableName, $beanData[$mainBeanTableName]);
169
-                $hash = $this->tdbmService->getObjectHash($primaryKeys);
170
-
171
-                if ($this->objectStorage->has($mainBeanTableName, $hash)) {
172
-                    $dbRow = $this->objectStorage->get($mainBeanTableName, $hash);
173
-                    $bean = $dbRow->getTDBMObject();
174
-                } else {
175
-                    // Let's construct the bean
176
-                    if (!isset($reflectionClassCache[$actualClassName])) {
177
-                        $reflectionClassCache[$actualClassName] = new \ReflectionClass($actualClassName);
178
-                    }
179
-                    // Let's bypass the constructor when creating the bean!
180
-                    $bean = $reflectionClassCache[$actualClassName]->newInstanceWithoutConstructor();
181
-                    $bean->_constructFromData($beanData, $this->tdbmService);
182
-                }
183
-
184
-                // The first bean is the one containing the main table.
185
-                if ($firstBean) {
186
-                    $firstBean = false;
187
-                    $this->current = $bean;
188
-                }
189
-            }
190
-
191
-            ++$this->key;
192
-        } else {
193
-            $this->current = null;
194
-        }
195
-    }
196
-
197
-    /**
198
-     * Moves the cursor to the beginning of the result set.
199
-     */
200
-    public function rewind()
201
-    {
202
-        $this->executeQuery();
203
-        $this->key = -1;
204
-        $this->next();
205
-    }
206
-    /**
207
-     * Checks if the cursor is reading a valid result.
208
-     *
209
-     * @return bool
210
-     */
211
-    public function valid()
212
-    {
213
-        return $this->current !== null;
214
-    }
215
-
216
-    /**
217
-     * Whether a offset exists.
218
-     *
219
-     * @link http://php.net/manual/en/arrayaccess.offsetexists.php
220
-     *
221
-     * @param mixed $offset <p>
222
-     *                      An offset to check for.
223
-     *                      </p>
224
-     *
225
-     * @return bool true on success or false on failure.
226
-     *              </p>
227
-     *              <p>
228
-     *              The return value will be casted to boolean if non-boolean was returned
229
-     *
230
-     * @since 5.0.0
231
-     */
232
-    public function offsetExists($offset)
233
-    {
234
-        throw new TDBMInvalidOperationException('You cannot access this result set via index because it was fetched in CURSOR mode. Use ARRAY_MODE instead.');
235
-    }
236
-
237
-    /**
238
-     * Offset to retrieve.
239
-     *
240
-     * @link http://php.net/manual/en/arrayaccess.offsetget.php
241
-     *
242
-     * @param mixed $offset <p>
243
-     *                      The offset to retrieve.
244
-     *                      </p>
245
-     *
246
-     * @return mixed Can return all value types
247
-     *
248
-     * @since 5.0.0
249
-     */
250
-    public function offsetGet($offset)
251
-    {
252
-        throw new TDBMInvalidOperationException('You cannot access this result set via index because it was fetched in CURSOR mode. Use ARRAY_MODE instead.');
253
-    }
254
-
255
-    /**
256
-     * Offset to set.
257
-     *
258
-     * @link http://php.net/manual/en/arrayaccess.offsetset.php
259
-     *
260
-     * @param mixed $offset <p>
261
-     *                      The offset to assign the value to.
262
-     *                      </p>
263
-     * @param mixed $value  <p>
264
-     *                      The value to set.
265
-     *                      </p>
266
-     *
267
-     * @since 5.0.0
268
-     */
269
-    public function offsetSet($offset, $value)
270
-    {
271
-        throw new TDBMInvalidOperationException('You can set values in a TDBM result set.');
272
-    }
273
-
274
-    /**
275
-     * Offset to unset.
276
-     *
277
-     * @link http://php.net/manual/en/arrayaccess.offsetunset.php
278
-     *
279
-     * @param mixed $offset <p>
280
-     *                      The offset to unset.
281
-     *                      </p>
282
-     *
283
-     * @since 5.0.0
284
-     */
285
-    public function offsetUnset($offset)
286
-    {
287
-        throw new TDBMInvalidOperationException('You can unset values in a TDBM result set.');
288
-    }
32
+	/**
33
+	 * @var Statement
34
+	 */
35
+	protected $statement;
36
+
37
+	protected $fetchStarted = false;
38
+	private $objectStorage;
39
+	private $className;
40
+
41
+	private $tdbmService;
42
+	private $magicSql;
43
+	private $parameters;
44
+	private $limit;
45
+	private $offset;
46
+	private $columnDescriptors;
47
+	private $magicQuery;
48
+
49
+	/**
50
+	 * The key of the current retrieved object.
51
+	 *
52
+	 * @var int
53
+	 */
54
+	protected $key = -1;
55
+
56
+	protected $current = null;
57
+
58
+	private $databasePlatform;
59
+
60
+	/**
61
+	 * @var LoggerInterface
62
+	 */
63
+	private $logger;
64
+
65
+	public function __construct($magicSql, array $parameters, $limit, $offset, array $columnDescriptors, $objectStorage, $className, TDBMService $tdbmService, MagicQuery $magicQuery, LoggerInterface $logger)
66
+	{
67
+		$this->magicSql = $magicSql;
68
+		$this->objectStorage = $objectStorage;
69
+		$this->className = $className;
70
+		$this->tdbmService = $tdbmService;
71
+		$this->parameters = $parameters;
72
+		$this->limit = $limit;
73
+		$this->offset = $offset;
74
+		$this->columnDescriptors = $columnDescriptors;
75
+		$this->magicQuery = $magicQuery;
76
+		$this->databasePlatform = $this->tdbmService->getConnection()->getDatabasePlatform();
77
+		$this->logger = $logger;
78
+	}
79
+
80
+	protected function executeQuery()
81
+	{
82
+		$sql = $this->magicQuery->build($this->magicSql, $this->parameters);
83
+		$sql = $this->tdbmService->getConnection()->getDatabasePlatform()->modifyLimitQuery($sql, $this->limit, $this->offset);
84
+
85
+		$this->logger->debug('Running SQL request: '.$sql);
86
+
87
+		$this->statement = $this->tdbmService->getConnection()->executeQuery($sql, $this->parameters);
88
+
89
+		$this->fetchStarted = true;
90
+	}
91
+
92
+	/**
93
+	 * Counts found records (this is the number of records fetched, taking into account the LIMIT and OFFSET settings).
94
+	 *
95
+	 * @return int
96
+	 */
97
+	public function count()
98
+	{
99
+		if (!$this->fetchStarted) {
100
+			$this->executeQuery();
101
+		}
102
+
103
+		return $this->statement->rowCount();
104
+	}
105
+
106
+	/**
107
+	 * Fetches record at current cursor.
108
+	 *
109
+	 * @return AbstractTDBMObject|null
110
+	 */
111
+	public function current()
112
+	{
113
+		return $this->current;
114
+	}
115
+
116
+	/**
117
+	 * Returns the current result's key.
118
+	 *
119
+	 * @return int
120
+	 */
121
+	public function key()
122
+	{
123
+		return $this->key;
124
+	}
125
+
126
+	/**
127
+	 * Advances the cursor to the next result.
128
+	 * Casts the database result into one (or several) beans.
129
+	 */
130
+	public function next()
131
+	{
132
+		$row = $this->statement->fetch(\PDO::FETCH_NUM);
133
+		if ($row) {
134
+
135
+			// array<tablegroup, array<table, array<column, value>>>
136
+			$beansData = [];
137
+			foreach ($row as $i => $value) {
138
+				$columnDescriptor = $this->columnDescriptors[$i];
139
+				// Let's cast the value according to its type
140
+				$value = $columnDescriptor['type']->convertToPHPValue($value, $this->databasePlatform);
141
+
142
+				$beansData[$columnDescriptor['tableGroup']][$columnDescriptor['table']][$columnDescriptor['column']] = $value;
143
+			}
144
+
145
+			$reflectionClassCache = [];
146
+			$firstBean = true;
147
+			foreach ($beansData as $beanData) {
148
+
149
+				// Let's find the bean class name associated to the bean.
150
+
151
+				list($actualClassName, $mainBeanTableName, $tablesUsed) = $this->tdbmService->_getClassNameFromBeanData($beanData);
152
+
153
+				if ($this->className !== null) {
154
+					$actualClassName = $this->className;
155
+				}
156
+
157
+				// Let's filter out the beanData that is not used (because it belongs to a part of the hierarchy that is not fetched:
158
+				foreach ($beanData as $tableName => $descriptors) {
159
+					if (!in_array($tableName, $tablesUsed)) {
160
+						unset($beanData[$tableName]);
161
+					}
162
+				}
163
+
164
+				// Must we create the bean? Let's see in the cache if we have a mapping DbRow?
165
+				// Let's get the first object mapping a row:
166
+				// We do this loop only for the first table
167
+
168
+				$primaryKeys = $this->tdbmService->_getPrimaryKeysFromObjectData($mainBeanTableName, $beanData[$mainBeanTableName]);
169
+				$hash = $this->tdbmService->getObjectHash($primaryKeys);
170
+
171
+				if ($this->objectStorage->has($mainBeanTableName, $hash)) {
172
+					$dbRow = $this->objectStorage->get($mainBeanTableName, $hash);
173
+					$bean = $dbRow->getTDBMObject();
174
+				} else {
175
+					// Let's construct the bean
176
+					if (!isset($reflectionClassCache[$actualClassName])) {
177
+						$reflectionClassCache[$actualClassName] = new \ReflectionClass($actualClassName);
178
+					}
179
+					// Let's bypass the constructor when creating the bean!
180
+					$bean = $reflectionClassCache[$actualClassName]->newInstanceWithoutConstructor();
181
+					$bean->_constructFromData($beanData, $this->tdbmService);
182
+				}
183
+
184
+				// The first bean is the one containing the main table.
185
+				if ($firstBean) {
186
+					$firstBean = false;
187
+					$this->current = $bean;
188
+				}
189
+			}
190
+
191
+			++$this->key;
192
+		} else {
193
+			$this->current = null;
194
+		}
195
+	}
196
+
197
+	/**
198
+	 * Moves the cursor to the beginning of the result set.
199
+	 */
200
+	public function rewind()
201
+	{
202
+		$this->executeQuery();
203
+		$this->key = -1;
204
+		$this->next();
205
+	}
206
+	/**
207
+	 * Checks if the cursor is reading a valid result.
208
+	 *
209
+	 * @return bool
210
+	 */
211
+	public function valid()
212
+	{
213
+		return $this->current !== null;
214
+	}
215
+
216
+	/**
217
+	 * Whether a offset exists.
218
+	 *
219
+	 * @link http://php.net/manual/en/arrayaccess.offsetexists.php
220
+	 *
221
+	 * @param mixed $offset <p>
222
+	 *                      An offset to check for.
223
+	 *                      </p>
224
+	 *
225
+	 * @return bool true on success or false on failure.
226
+	 *              </p>
227
+	 *              <p>
228
+	 *              The return value will be casted to boolean if non-boolean was returned
229
+	 *
230
+	 * @since 5.0.0
231
+	 */
232
+	public function offsetExists($offset)
233
+	{
234
+		throw new TDBMInvalidOperationException('You cannot access this result set via index because it was fetched in CURSOR mode. Use ARRAY_MODE instead.');
235
+	}
236
+
237
+	/**
238
+	 * Offset to retrieve.
239
+	 *
240
+	 * @link http://php.net/manual/en/arrayaccess.offsetget.php
241
+	 *
242
+	 * @param mixed $offset <p>
243
+	 *                      The offset to retrieve.
244
+	 *                      </p>
245
+	 *
246
+	 * @return mixed Can return all value types
247
+	 *
248
+	 * @since 5.0.0
249
+	 */
250
+	public function offsetGet($offset)
251
+	{
252
+		throw new TDBMInvalidOperationException('You cannot access this result set via index because it was fetched in CURSOR mode. Use ARRAY_MODE instead.');
253
+	}
254
+
255
+	/**
256
+	 * Offset to set.
257
+	 *
258
+	 * @link http://php.net/manual/en/arrayaccess.offsetset.php
259
+	 *
260
+	 * @param mixed $offset <p>
261
+	 *                      The offset to assign the value to.
262
+	 *                      </p>
263
+	 * @param mixed $value  <p>
264
+	 *                      The value to set.
265
+	 *                      </p>
266
+	 *
267
+	 * @since 5.0.0
268
+	 */
269
+	public function offsetSet($offset, $value)
270
+	{
271
+		throw new TDBMInvalidOperationException('You can set values in a TDBM result set.');
272
+	}
273
+
274
+	/**
275
+	 * Offset to unset.
276
+	 *
277
+	 * @link http://php.net/manual/en/arrayaccess.offsetunset.php
278
+	 *
279
+	 * @param mixed $offset <p>
280
+	 *                      The offset to unset.
281
+	 *                      </p>
282
+	 *
283
+	 * @since 5.0.0
284
+	 */
285
+	public function offsetUnset($offset)
286
+	{
287
+		throw new TDBMInvalidOperationException('You can unset values in a TDBM result set.');
288
+	}
289 289
 }
Please login to merge, or discard this patch.
src/Mouf/Database/TDBM/TDBMObject.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -33,42 +33,42 @@
 block discarded – undo
33 33
  */
34 34
 class TDBMObject extends AbstractTDBMObject
35 35
 {
36
-    public function getProperty($var, $tableName = null)
37
-    {
38
-        return $this->get($var, $tableName);
39
-    }
36
+	public function getProperty($var, $tableName = null)
37
+	{
38
+		return $this->get($var, $tableName);
39
+	}
40 40
 
41
-    public function setProperty($var, $value, $tableName = null)
42
-    {
43
-        $this->set($var, $value, $tableName);
44
-    }
41
+	public function setProperty($var, $value, $tableName = null)
42
+	{
43
+		$this->set($var, $value, $tableName);
44
+	}
45 45
 
46
-    /**
47
-     * Specify data which should be serialized to JSON.
48
-     *
49
-     * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
50
-     *
51
-     * @return mixed data which can be serialized by <b>json_encode</b>,
52
-     *               which is a value of any type other than a resource
53
-     *
54
-     * @since 5.4.0
55
-     */
56
-    public function jsonSerialize()
57
-    {
58
-        throw new TDBMException('Json serialization is only implemented for generated beans.');
59
-    }
46
+	/**
47
+	 * Specify data which should be serialized to JSON.
48
+	 *
49
+	 * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
50
+	 *
51
+	 * @return mixed data which can be serialized by <b>json_encode</b>,
52
+	 *               which is a value of any type other than a resource
53
+	 *
54
+	 * @since 5.4.0
55
+	 */
56
+	public function jsonSerialize()
57
+	{
58
+		throw new TDBMException('Json serialization is only implemented for generated beans.');
59
+	}
60 60
 
61
-    /**
62
-     * Returns an array of used tables by this bean (from parent to child relationship).
63
-     *
64
-     * @return string[]
65
-     */
66
-    protected function getUsedTables()
67
-    {
68
-        $tableNames = array_keys($this->dbRows);
69
-        $tableNames = $this->tdbmService->_getLinkBetweenInheritedTables($tableNames);
70
-        $tableNames = array_reverse($tableNames);
61
+	/**
62
+	 * Returns an array of used tables by this bean (from parent to child relationship).
63
+	 *
64
+	 * @return string[]
65
+	 */
66
+	protected function getUsedTables()
67
+	{
68
+		$tableNames = array_keys($this->dbRows);
69
+		$tableNames = $this->tdbmService->_getLinkBetweenInheritedTables($tableNames);
70
+		$tableNames = array_reverse($tableNames);
71 71
 
72
-        return $tableNames;
73
-    }
72
+		return $tableNames;
73
+	}
74 74
 }
Please login to merge, or discard this patch.