@@ -42,10 +42,10 @@ private static function initConnection() {
42
42
PDO ::ATTR_ERRMODE => (DEBUG ? PDO ::ERRMODE_EXCEPTION : PDO ::ERRMODE_SILENT ),
43
43
];
44
44
if (isset ($ CONFIG ['db ' ]['unix_socket ' ])) {
45
- static ::$ connection = new PDO ('mysql:unix_socket= ' . $ CONFIG ['db ' ]['unix_socket ' ] . ';dbname= ' . $ CONFIG ['db ' ]['dbname ' ],
45
+ self ::$ connection = new PDO ('mysql:unix_socket= ' . $ CONFIG ['db ' ]['unix_socket ' ] . ';dbname= ' . $ CONFIG ['db ' ]['dbname ' ],
46
46
$ CONFIG ['db ' ]['username ' ], $ CONFIG ['db ' ]['password ' ], $ _options );
47
47
} else {
48
- static ::$ connection = new PDO ('mysql:host= ' . $ CONFIG ['db ' ]['host ' ] . ';port= ' . $ CONFIG ['db ' ]['port ' ] . ';dbname= ' . $ CONFIG ['db ' ]['dbname ' ],
48
+ self ::$ connection = new PDO ('mysql:host= ' . $ CONFIG ['db ' ]['host ' ] . ';port= ' . $ CONFIG ['db ' ]['port ' ] . ';dbname= ' . $ CONFIG ['db ' ]['dbname ' ],
49
49
$ CONFIG ['db ' ]['username ' ], $ CONFIG ['db ' ]['password ' ], $ _options );
50
50
}
51
51
}
@@ -55,21 +55,21 @@ public static function getLastInsertId() {
55
55
}
56
56
57
57
public static function getConnection () {
58
- if (static ::$ connection == null ) {
59
- static ::initConnection ();
60
- static ::$ lastConnection = strtotime ('now ' );
61
- } elseif (static ::$ lastConnection + 120 < strtotime ('now ' )) {
58
+ if (self ::$ connection == null ) {
59
+ self ::initConnection ();
60
+ self ::$ lastConnection = strtotime ('now ' );
61
+ } elseif (self ::$ lastConnection + 120 < strtotime ('now ' )) {
62
62
try {
63
- $ result = @static ::$ connection ->query ('select 1; ' );
63
+ $ result = @self ::$ connection ->query ('select 1; ' );
64
64
if (!$ result ) {
65
- static ::initConnection ();
65
+ self ::initConnection ();
66
66
}
67
67
} catch (Exception $ e ) {
68
- static ::initConnection ();
68
+ self ::initConnection ();
69
69
}
70
- static ::$ lastConnection = strtotime ('now ' );
70
+ self ::$ lastConnection = strtotime ('now ' );
71
71
}
72
- return static ::$ connection ;
72
+ return self ::$ connection ;
73
73
}
74
74
75
75
public static function &CallStoredProc ($ _procName , $ _params , $ _fetch_type , $ _className = NULL , $ _fetch_opt = NULL ) {
@@ -94,10 +94,10 @@ public static function &Prepare($_query, $_params, $_fetchType = self::FETCH_TYP
94
94
if (preg_match ('/^update|^replace|^delete|^create|^drop|^alter|^truncate/i ' , $ _query )){
95
95
$ errorInfo = $ stmt ->errorInfo ();
96
96
if ($ errorInfo [0 ] != 0000 ) {
97
- static ::$ lastConnection = 0 ;
97
+ self ::$ lastConnection = 0 ;
98
98
throw new Exception ('[MySQL] Error code : ' . $ errorInfo [0 ] . ' ( ' . $ errorInfo [1 ] . '). ' . $ errorInfo [2 ] . ' : ' . $ _query );
99
99
}
100
- static ::$ lastConnection = strtotime ('now ' );
100
+ self ::$ lastConnection = strtotime ('now ' );
101
101
return $ res ;
102
102
}
103
103
if ($ _fetchType == static ::FETCH_TYPE_ROW ) {
@@ -116,10 +116,10 @@ public static function &Prepare($_query, $_params, $_fetchType = self::FETCH_TYP
116
116
}
117
117
$ errorInfo = $ stmt ->errorInfo ();
118
118
if ($ errorInfo [0 ] != 0000 ) {
119
- static ::$ lastConnection = 0 ;
119
+ self ::$ lastConnection = 0 ;
120
120
throw new Exception ('[MySQL] Error code : ' . $ errorInfo [0 ] . ' ( ' . $ errorInfo [1 ] . '). ' . $ errorInfo [2 ] . ' : ' . $ _query );
121
121
}
122
- static ::$ lastConnection = strtotime ('now ' );
122
+ self ::$ lastConnection = strtotime ('now ' );
123
123
if ($ _fetch_param == PDO ::FETCH_CLASS ) {
124
124
if (is_array ($ res ) && count ($ res ) > 0 ) {
125
125
foreach ($ res as &$ obj ) {
@@ -186,29 +186,29 @@ public static function save($object, $_direct = false, $_replace = false) {
186
186
if (!$ _direct && method_exists ($ object , 'preSave ' )) {
187
187
$ object ->preSave ();
188
188
}
189
- if (!static ::getField ($ object , 'id ' )) {
189
+ if (!self ::getField ($ object , 'id ' )) {
190
190
//New object to save.
191
- $ fields = static ::getFields ($ object );
191
+ $ fields = self ::getFields ($ object );
192
192
if (in_array ('id ' , $ fields )) {
193
- static ::setField ($ object , 'id ' , null );
193
+ self ::setField ($ object , 'id ' , null );
194
194
}
195
195
if (!$ _direct && method_exists ($ object , 'preInsert ' )) {
196
196
$ object ->preInsert ();
197
197
}
198
198
if (method_exists ($ object , 'encrypt ' )) {
199
199
$ object ->encrypt ();
200
200
}
201
- list ($ sql , $ parameters ) = static ::buildQuery ($ object );
201
+ list ($ sql , $ parameters ) = self ::buildQuery ($ object );
202
202
if ($ _replace ) {
203
- $ sql = 'REPLACE INTO ` ' . static ::getTableName ($ object ) . '` SET ' . implode (', ' , $ sql );
203
+ $ sql = 'REPLACE INTO ` ' . self ::getTableName ($ object ) . '` SET ' . implode (', ' , $ sql );
204
204
} else {
205
- $ sql = 'INSERT INTO ` ' . static ::getTableName ($ object ) . '` SET ' . implode (', ' , $ sql );
205
+ $ sql = 'INSERT INTO ` ' . self ::getTableName ($ object ) . '` SET ' . implode (', ' , $ sql );
206
206
}
207
207
$ res = static ::Prepare ($ sql , $ parameters , DB ::FETCH_TYPE_ROW );
208
- $ reflection = static ::getReflectionClass ($ object );
208
+ $ reflection = self ::getReflectionClass ($ object );
209
209
if ($ reflection ->hasProperty ('id ' )) {
210
210
try {
211
- static ::setField ($ object , 'id ' , static ::getLastInsertId ());
211
+ self ::setField ($ object , 'id ' , static ::getLastInsertId ());
212
212
} catch (Exception $ exc ) {
213
213
trigger_error ($ exc ->getMessage (), E_USER_NOTICE );
214
214
} catch (InvalidArgumentException $ ex ) {
@@ -234,14 +234,14 @@ public static function save($object, $_direct = false, $_replace = false) {
234
234
if (method_exists ($ object , 'encrypt ' )) {
235
235
$ object ->encrypt ();
236
236
}
237
- list ($ sql , $ parameters ) = static ::buildQuery ($ object );
237
+ list ($ sql , $ parameters ) = self ::buildQuery ($ object );
238
238
if (!$ _direct && method_exists ($ object , 'getId ' )) {
239
239
$ parameters ['id ' ] = $ object ->getId (); //override if necessary
240
240
}
241
241
if ($ _replace ) {
242
- $ sql = 'REPLACE INTO ` ' . static ::getTableName ($ object ) . '` SET ' . implode (', ' , $ sql );
242
+ $ sql = 'REPLACE INTO ` ' . self ::getTableName ($ object ) . '` SET ' . implode (', ' , $ sql );
243
243
} else {
244
- $ sql = 'UPDATE ` ' . static ::getTableName ($ object ) . '` SET ' . implode (', ' , $ sql ) . ' WHERE id = :id ' ;
244
+ $ sql = 'UPDATE ` ' . self ::getTableName ($ object ) . '` SET ' . implode (', ' , $ sql ) . ' WHERE id = :id ' ;
245
245
}
246
246
$ res = static ::Prepare ($ sql , $ parameters , DB ::FETCH_TYPE_ROW );
247
247
} else {
@@ -264,12 +264,12 @@ public static function save($object, $_direct = false, $_replace = false) {
264
264
}
265
265
266
266
public static function refresh ($ object ) {
267
- if (!static ::getField ($ object , 'id ' )) {
267
+ if (!self ::getField ($ object , 'id ' )) {
268
268
throw new Exception ('Can \'t refresh DB object without its ID ' );
269
269
}
270
- $ parameters = array ('id ' => static ::getField ($ object , 'id ' ));
270
+ $ parameters = array ('id ' => self ::getField ($ object , 'id ' ));
271
271
$ sql = 'SELECT ' . static ::buildField (get_class ($ object )) .
272
- ' FROM ` ' . static ::getTableName ($ object ) . '` ' .
272
+ ' FROM ` ' . self ::getTableName ($ object ) . '` ' .
273
273
' WHERE ' ;
274
274
foreach ($ parameters as $ field => $ value ) {
275
275
if ($ value != '' ) {
@@ -283,14 +283,14 @@ public static function refresh($object) {
283
283
if (!is_object ($ newObject )) {
284
284
return false ;
285
285
}
286
- foreach (static ::getFields ($ object ) as $ field ) {
287
- $ reflection = static ::getReflectionClass ($ object );
286
+ foreach (self ::getFields ($ object ) as $ field ) {
287
+ $ reflection = self ::getReflectionClass ($ object );
288
288
$ property = $ reflection ->getProperty ($ field );
289
289
if (!$ reflection ->hasProperty ($ field )) {
290
290
throw new InvalidArgumentException ('Unknown field ' . get_class ($ object ) . ':: ' . $ field );
291
291
}
292
292
$ property ->setAccessible (true );
293
- $ property ->setValue ($ object , static ::getField ($ newObject , $ field ));
293
+ $ property ->setValue ($ object , self ::getField ($ newObject , $ field ));
294
294
$ property ->setAccessible (false );
295
295
}
296
296
return true ;
@@ -300,13 +300,13 @@ public static function refresh($object) {
300
300
* Retourne une liste d'objets ou un objet en fonction de filtres
301
301
* @param $_filters Filtres à appliquer
302
302
* @param $_object Objet sur lequel appliquer les filtres
303
- * @return Objet ou liste d'objets correspondant à la requête
303
+ * @return array<mixed>|null Objet ou liste d'objets correspondant à la requête
304
304
*/
305
305
public static function getWithFilter (array $ _filters , $ _object ) {
306
306
// operators have to remain in this order. If you put '<' before '<=', algorithm won't make the difference & will think a '<=' is a '<'
307
307
$ operators = array ('!= ' , '<= ' , '>= ' , '< ' , '> ' , 'NOT LIKE ' , 'LIKE ' , '= ' );
308
- $ fields = static ::getFields ($ _object );
309
- $ class = static ::getReflectionClass ($ _object )->getName ();
308
+ $ fields = self ::getFields ($ _object );
309
+ $ class = self ::getReflectionClass ($ _object )->getName ();
310
310
// create query
311
311
$ query = 'SELECT ' . static ::buildField ($ class ) . ' FROM ' . $ class . '' ;
312
312
$ values = array ();
@@ -365,8 +365,8 @@ public static function remove($object) {
365
365
return false ;
366
366
}
367
367
}
368
- list ($ sql , $ parameters ) = static ::buildQuery ($ object );
369
- $ sql = 'DELETE FROM ` ' . static ::getTableName ($ object ) . '` WHERE ' ;
368
+ list ($ sql , $ parameters ) = self ::buildQuery ($ object );
369
+ $ sql = 'DELETE FROM ` ' . self ::getTableName ($ object ) . '` WHERE ' ;
370
370
if (isset ($ parameters ['id ' ])) {
371
371
$ sql .= '`id`=:id AND ' ;
372
372
$ parameters = array ('id ' => $ parameters ['id ' ]);
@@ -381,9 +381,9 @@ public static function remove($object) {
381
381
}
382
382
$ sql .= '1 ' ;
383
383
$ res = static ::Prepare ($ sql , $ parameters , DB ::FETCH_TYPE_ROW );
384
- $ reflection = static ::getReflectionClass ($ object );
384
+ $ reflection = self ::getReflectionClass ($ object );
385
385
if ($ reflection ->hasProperty ('id ' )) {
386
- static ::setField ($ object , 'id ' , null );
386
+ self ::setField ($ object , 'id ' , null );
387
387
}
388
388
if (method_exists ($ object , 'postRemove ' )) {
389
389
$ object ->postRemove ();
@@ -409,8 +409,8 @@ public static function lock($object) {
409
409
return false ;
410
410
}
411
411
}
412
- list ($ sql , $ parameters ) = static ::buildQuery ($ object );
413
- $ sql = 'SELECT * FROM ' . static ::getTableName ($ object ) . ' WHERE ' ;
412
+ list ($ sql , $ parameters ) = self ::buildQuery ($ object );
413
+ $ sql = 'SELECT * FROM ' . self ::getTableName ($ object ) . ' WHERE ' ;
414
414
foreach ($ parameters as $ field => $ value ) {
415
415
if ($ value != '' ) {
416
416
$ sql .= '` ' . $ field . '`=: ' . $ field . ' AND ' ;
@@ -445,23 +445,23 @@ private static function getTableName($object) {
445
445
* @throws RuntimeException
446
446
*/
447
447
private static function getFields ($ object ) {
448
- $ table = is_string ($ object ) ? $ object : static ::getTableName ($ object );
449
- if (isset (static ::$ fields [$ table ])) {
450
- return static ::$ fields [$ table ];
448
+ $ table = is_string ($ object ) ? $ object : self ::getTableName ($ object );
449
+ if (isset (self ::$ fields [$ table ])) {
450
+ return self ::$ fields [$ table ];
451
451
}
452
- $ reflection = is_object ($ object ) ? static ::getReflectionClass ($ object ) : new ReflectionClass ($ object );
452
+ $ reflection = is_object ($ object ) ? self ::getReflectionClass ($ object ) : new ReflectionClass ($ object );
453
453
$ properties = $ reflection ->getProperties ();
454
- static ::$ fields [$ table ] = array ();
454
+ self ::$ fields [$ table ] = array ();
455
455
foreach ($ properties as $ property ) {
456
456
$ name = $ property ->getName ();
457
457
if ('_ ' !== $ name [0 ]) {
458
- static ::$ fields [$ table ][] = $ name ;
458
+ self ::$ fields [$ table ][] = $ name ;
459
459
}
460
460
}
461
- if (empty (static ::$ fields [$ table ])) {
461
+ if (empty (self ::$ fields [$ table ])) {
462
462
throw new RuntimeException ('No fields found for class ' . get_class ($ object ));
463
463
}
464
- return static ::$ fields [$ table ];
464
+ return self ::$ fields [$ table ];
465
465
}
466
466
467
467
/**
@@ -477,7 +477,7 @@ private static function setField($object, $field, $value) {
477
477
if (method_exists ($ object , $ method )) {
478
478
$ object ->$ method ($ value );
479
479
} else {
480
- $ reflection = static ::getReflectionClass ($ object );
480
+ $ reflection = self ::getReflectionClass ($ object );
481
481
if (!$ reflection ->hasProperty ($ field )) {
482
482
throw new InvalidArgumentException ('Unknown field ' . get_class ($ object ) . ':: ' . $ field );
483
483
}
@@ -499,9 +499,9 @@ private static function setField($object, $field, $value) {
499
499
private static function buildQuery ($ object ) {
500
500
$ parameters = array ();
501
501
$ sql = array ();
502
- foreach (static ::getFields ($ object ) as $ field ) {
502
+ foreach (self ::getFields ($ object ) as $ field ) {
503
503
$ sql [] = '` ' . $ field . '` = : ' . $ field ;
504
- $ parameters [$ field ] = static ::getField ($ object , $ field );
504
+ $ parameters [$ field ] = self ::getField ($ object , $ field );
505
505
}
506
506
return array ($ sql , $ parameters );
507
507
}
@@ -521,7 +521,7 @@ private static function getField($object, $field) {
521
521
if (method_exists ($ object , $ method )) {
522
522
$ retval = $ object ->$ method ();
523
523
} else {
524
- $ reflection = static ::getReflectionClass ($ object );
524
+ $ reflection = self ::getReflectionClass ($ object );
525
525
if ($ reflection ->hasProperty ($ field )) {
526
526
$ property = $ reflection ->getProperty ($ field );
527
527
$ property ->setAccessible (true );
@@ -552,7 +552,7 @@ private static function getReflectionClass($object) {
552
552
553
553
public static function buildField ($ _class , $ _prefix = '' ) {
554
554
$ fields = array ();
555
- foreach (static ::getFields ($ _class ) as $ field ) {
555
+ foreach (self ::getFields ($ _class ) as $ field ) {
556
556
if ('_ ' !== $ field [0 ]) {
557
557
if ($ _prefix != '' ) {
558
558
$ fields [] = '` ' . $ _prefix . '`. ' . '` ' . $ field . '` ' ;
0 commit comments