4
4
use Automatorm \Exception ;
5
5
6
6
/* MVC Model Class giving a lightweight ORM interface with an indirect active record pattern.
7
- * The rationale for this superclass is to make it trivial to create an object representing a single row in a database table (and a class
8
- * representing a database table).
7
+ * The rationale for this superclass is to make it trivial to create an object representing
8
+ * a single row in a database table (and a class representing a database table).
9
9
*
10
10
* Features:
11
11
* * Auto generation of object properties - TableName::get($id)->column_name syntax
@@ -24,8 +24,8 @@ class Model implements \JsonSerializable
24
24
// Flags
25
25
const COUNT_ONLY = 1 ;
26
26
27
- public static $ tablename ; // Override table associated with this class
28
- protected static $ instance ; // An internal store of already created objects so that objects for each row only get created once
27
+ public static $ tablename ; // Override table associated with this class
28
+ protected static $ instance ; // An internal store of created objects so that objects for each row only get created once
29
29
30
30
/* PUBLIC CONSTRUCTION METHODS */
31
31
/**
@@ -146,7 +146,7 @@ final public static function factory($where, $classOrTablename = null, $schema =
146
146
final public static function factoryObjectCache ($ ids , $ classOrTable = null , Schema $ schema = null , $ forceRefresh = false )
147
147
{
148
148
$ schema = $ schema ?: Schema::get (static ::getNamespace ());
149
- list ($ class , $ table ) = $ schema ->guessContext ($ classOrTable ?: get_called_class ());
149
+ list (, $ table ) = $ schema ->guessContext ($ classOrTable ?: get_called_class ());
150
150
$ namespace = $ schema ->namespace ;
151
151
152
152
// If we have a single id
@@ -200,21 +200,13 @@ final public static function factoryObjectCache($ids, $classOrTable = null, Sche
200
200
// Get data from database from which we can construct Model objects
201
201
final public static function factoryData ($ where , $ table , Schema $ schema , array $ options = null )
202
202
{
203
- return $ schema ->connection ->getDataAccessor ()->getData (
204
- $ table ,
205
- $ where ,
206
- $ options
207
- );
203
+ return $ schema ->connection ->getDataAccessor ()->getData ($ table , $ where , $ options );
208
204
}
209
205
210
206
// Get data from database from which we can construct Model objects
211
207
final public static function factoryDataCount ($ where , $ table , Schema $ schema , array $ options = null )
212
208
{
213
- return $ schema ->connection ->getDataAccessor ()->getDataCount (
214
- $ table ,
215
- $ where ,
216
- $ options
217
- );
209
+ return $ schema ->connection ->getDataAccessor ()->getDataCount ($ table , $ where , $ options );
218
210
}
219
211
220
212
// Return an empty Model_Data object for this class/table so that a new object can be constructed (and a new row entered in the table).
@@ -382,7 +374,7 @@ public function __wakeup()
382
374
383
375
final public function data ()
384
376
{
385
- return clone $ this ->_data ;
377
+ return clone $ this ->_data ;
386
378
}
387
379
388
380
final public function dataOriginal ()
@@ -403,7 +395,7 @@ final public function dataClearCache()
403
395
$ modelschema = $ this ->_data ->getModel ();
404
396
405
397
// Clean out cached column data
406
- foreach ($ modelschema ['columns ' ] as $ column => $ type ) {
398
+ foreach (array_keys ( $ modelschema ['columns ' ]) as $ column ) {
407
399
if ($ column != 'id ' && property_exists ($ this , $ column )) {
408
400
unset($ this ->{$ column });
409
401
}
@@ -419,7 +411,7 @@ final public function dataClearCache()
419
411
420
412
// Clean out cached external data
421
413
$ foreignkeys = (array ) $ modelschema ['one-to-one ' ] + (array ) $ modelschema ['one-to-many ' ] + (array ) $ modelschema ['many-to-many ' ] + (array ) $ modelschema ['many-to-one ' ];
422
- foreach ($ foreignkeys as $ column => $ value ) {
414
+ foreach (array_keys ( $ foreignkeys) as $ column ) {
423
415
if ($ column && $ column != 'id ' ) {
424
416
unset($ this ->{$ column });
425
417
}
0 commit comments