@@ -42,10 +42,10 @@ private static function initConnection() {
4242 PDO ::ATTR_ERRMODE => (DEBUG ? PDO ::ERRMODE_EXCEPTION : PDO ::ERRMODE_SILENT ),
4343 ];
4444 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 ' ],
4646 $ CONFIG ['db ' ]['username ' ], $ CONFIG ['db ' ]['password ' ], $ _options );
4747 } 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 ' ],
4949 $ CONFIG ['db ' ]['username ' ], $ CONFIG ['db ' ]['password ' ], $ _options );
5050 }
5151 }
@@ -55,21 +55,21 @@ public static function getLastInsertId() {
5555 }
5656
5757 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 ' )) {
6262 try {
63- $ result = @static ::$ connection ->query ('select 1; ' );
63+ $ result = @self ::$ connection ->query ('select 1; ' );
6464 if (!$ result ) {
65- static ::initConnection ();
65+ self ::initConnection ();
6666 }
6767 } catch (Exception $ e ) {
68- static ::initConnection ();
68+ self ::initConnection ();
6969 }
70- static ::$ lastConnection = strtotime ('now ' );
70+ self ::$ lastConnection = strtotime ('now ' );
7171 }
72- return static ::$ connection ;
72+ return self ::$ connection ;
7373 }
7474
7575 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
9494 if (preg_match ('/^update|^replace|^delete|^create|^drop|^alter|^truncate/i ' , $ _query )){
9595 $ errorInfo = $ stmt ->errorInfo ();
9696 if ($ errorInfo [0 ] != 0000 ) {
97- static ::$ lastConnection = 0 ;
97+ self ::$ lastConnection = 0 ;
9898 throw new Exception ('[MySQL] Error code : ' . $ errorInfo [0 ] . ' ( ' . $ errorInfo [1 ] . '). ' . $ errorInfo [2 ] . ' : ' . $ _query );
9999 }
100- static ::$ lastConnection = strtotime ('now ' );
100+ self ::$ lastConnection = strtotime ('now ' );
101101 return $ res ;
102102 }
103103 if ($ _fetchType == static ::FETCH_TYPE_ROW ) {
@@ -116,10 +116,10 @@ public static function &Prepare($_query, $_params, $_fetchType = self::FETCH_TYP
116116 }
117117 $ errorInfo = $ stmt ->errorInfo ();
118118 if ($ errorInfo [0 ] != 0000 ) {
119- static ::$ lastConnection = 0 ;
119+ self ::$ lastConnection = 0 ;
120120 throw new Exception ('[MySQL] Error code : ' . $ errorInfo [0 ] . ' ( ' . $ errorInfo [1 ] . '). ' . $ errorInfo [2 ] . ' : ' . $ _query );
121121 }
122- static ::$ lastConnection = strtotime ('now ' );
122+ self ::$ lastConnection = strtotime ('now ' );
123123 if ($ _fetch_param == PDO ::FETCH_CLASS ) {
124124 if (is_array ($ res ) && count ($ res ) > 0 ) {
125125 foreach ($ res as &$ obj ) {
@@ -186,29 +186,29 @@ public static function save($object, $_direct = false, $_replace = false) {
186186 if (!$ _direct && method_exists ($ object , 'preSave ' )) {
187187 $ object ->preSave ();
188188 }
189- if (!static ::getField ($ object , 'id ' )) {
189+ if (!self ::getField ($ object , 'id ' )) {
190190 //New object to save.
191- $ fields = static ::getFields ($ object );
191+ $ fields = self ::getFields ($ object );
192192 if (in_array ('id ' , $ fields )) {
193- static ::setField ($ object , 'id ' , null );
193+ self ::setField ($ object , 'id ' , null );
194194 }
195195 if (!$ _direct && method_exists ($ object , 'preInsert ' )) {
196196 $ object ->preInsert ();
197197 }
198198 if (method_exists ($ object , 'encrypt ' )) {
199199 $ object ->encrypt ();
200200 }
201- list ($ sql , $ parameters ) = static ::buildQuery ($ object );
201+ list ($ sql , $ parameters ) = self ::buildQuery ($ object );
202202 if ($ _replace ) {
203- $ sql = 'REPLACE INTO ` ' . static ::getTableName ($ object ) . '` SET ' . implode (', ' , $ sql );
203+ $ sql = 'REPLACE INTO ` ' . self ::getTableName ($ object ) . '` SET ' . implode (', ' , $ sql );
204204 } else {
205- $ sql = 'INSERT INTO ` ' . static ::getTableName ($ object ) . '` SET ' . implode (', ' , $ sql );
205+ $ sql = 'INSERT INTO ` ' . self ::getTableName ($ object ) . '` SET ' . implode (', ' , $ sql );
206206 }
207207 $ res = static ::Prepare ($ sql , $ parameters , DB ::FETCH_TYPE_ROW );
208- $ reflection = static ::getReflectionClass ($ object );
208+ $ reflection = self ::getReflectionClass ($ object );
209209 if ($ reflection ->hasProperty ('id ' )) {
210210 try {
211- static ::setField ($ object , 'id ' , static ::getLastInsertId ());
211+ self ::setField ($ object , 'id ' , static ::getLastInsertId ());
212212 } catch (Exception $ exc ) {
213213 trigger_error ($ exc ->getMessage (), E_USER_NOTICE );
214214 } catch (InvalidArgumentException $ ex ) {
@@ -234,14 +234,14 @@ public static function save($object, $_direct = false, $_replace = false) {
234234 if (method_exists ($ object , 'encrypt ' )) {
235235 $ object ->encrypt ();
236236 }
237- list ($ sql , $ parameters ) = static ::buildQuery ($ object );
237+ list ($ sql , $ parameters ) = self ::buildQuery ($ object );
238238 if (!$ _direct && method_exists ($ object , 'getId ' )) {
239239 $ parameters ['id ' ] = $ object ->getId (); //override if necessary
240240 }
241241 if ($ _replace ) {
242- $ sql = 'REPLACE INTO ` ' . static ::getTableName ($ object ) . '` SET ' . implode (', ' , $ sql );
242+ $ sql = 'REPLACE INTO ` ' . self ::getTableName ($ object ) . '` SET ' . implode (', ' , $ sql );
243243 } 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 ' ;
245245 }
246246 $ res = static ::Prepare ($ sql , $ parameters , DB ::FETCH_TYPE_ROW );
247247 } else {
@@ -264,12 +264,12 @@ public static function save($object, $_direct = false, $_replace = false) {
264264 }
265265
266266 public static function refresh ($ object ) {
267- if (!static ::getField ($ object , 'id ' )) {
267+ if (!self ::getField ($ object , 'id ' )) {
268268 throw new Exception ('Can \'t refresh DB object without its ID ' );
269269 }
270- $ parameters = array ('id ' => static ::getField ($ object , 'id ' ));
270+ $ parameters = array ('id ' => self ::getField ($ object , 'id ' ));
271271 $ sql = 'SELECT ' . static ::buildField (get_class ($ object )) .
272- ' FROM ` ' . static ::getTableName ($ object ) . '` ' .
272+ ' FROM ` ' . self ::getTableName ($ object ) . '` ' .
273273 ' WHERE ' ;
274274 foreach ($ parameters as $ field => $ value ) {
275275 if ($ value != '' ) {
@@ -283,14 +283,14 @@ public static function refresh($object) {
283283 if (!is_object ($ newObject )) {
284284 return false ;
285285 }
286- foreach (static ::getFields ($ object ) as $ field ) {
287- $ reflection = static ::getReflectionClass ($ object );
286+ foreach (self ::getFields ($ object ) as $ field ) {
287+ $ reflection = self ::getReflectionClass ($ object );
288288 $ property = $ reflection ->getProperty ($ field );
289289 if (!$ reflection ->hasProperty ($ field )) {
290290 throw new InvalidArgumentException ('Unknown field ' . get_class ($ object ) . ':: ' . $ field );
291291 }
292292 $ property ->setAccessible (true );
293- $ property ->setValue ($ object , static ::getField ($ newObject , $ field ));
293+ $ property ->setValue ($ object , self ::getField ($ newObject , $ field ));
294294 $ property ->setAccessible (false );
295295 }
296296 return true ;
@@ -300,13 +300,13 @@ public static function refresh($object) {
300300 * Retourne une liste d'objets ou un objet en fonction de filtres
301301 * @param $_filters Filtres à appliquer
302302 * @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
304304 */
305305 public static function getWithFilter (array $ _filters , $ _object ) {
306306 // operators have to remain in this order. If you put '<' before '<=', algorithm won't make the difference & will think a '<=' is a '<'
307307 $ 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 ();
310310 // create query
311311 $ query = 'SELECT ' . static ::buildField ($ class ) . ' FROM ' . $ class . '' ;
312312 $ values = array ();
@@ -365,8 +365,8 @@ public static function remove($object) {
365365 return false ;
366366 }
367367 }
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 ' ;
370370 if (isset ($ parameters ['id ' ])) {
371371 $ sql .= '`id`=:id AND ' ;
372372 $ parameters = array ('id ' => $ parameters ['id ' ]);
@@ -381,9 +381,9 @@ public static function remove($object) {
381381 }
382382 $ sql .= '1 ' ;
383383 $ res = static ::Prepare ($ sql , $ parameters , DB ::FETCH_TYPE_ROW );
384- $ reflection = static ::getReflectionClass ($ object );
384+ $ reflection = self ::getReflectionClass ($ object );
385385 if ($ reflection ->hasProperty ('id ' )) {
386- static ::setField ($ object , 'id ' , null );
386+ self ::setField ($ object , 'id ' , null );
387387 }
388388 if (method_exists ($ object , 'postRemove ' )) {
389389 $ object ->postRemove ();
@@ -409,8 +409,8 @@ public static function lock($object) {
409409 return false ;
410410 }
411411 }
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 ' ;
414414 foreach ($ parameters as $ field => $ value ) {
415415 if ($ value != '' ) {
416416 $ sql .= '` ' . $ field . '`=: ' . $ field . ' AND ' ;
@@ -445,23 +445,23 @@ private static function getTableName($object) {
445445 * @throws RuntimeException
446446 */
447447 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 ];
451451 }
452- $ reflection = is_object ($ object ) ? static ::getReflectionClass ($ object ) : new ReflectionClass ($ object );
452+ $ reflection = is_object ($ object ) ? self ::getReflectionClass ($ object ) : new ReflectionClass ($ object );
453453 $ properties = $ reflection ->getProperties ();
454- static ::$ fields [$ table ] = array ();
454+ self ::$ fields [$ table ] = array ();
455455 foreach ($ properties as $ property ) {
456456 $ name = $ property ->getName ();
457457 if ('_ ' !== $ name [0 ]) {
458- static ::$ fields [$ table ][] = $ name ;
458+ self ::$ fields [$ table ][] = $ name ;
459459 }
460460 }
461- if (empty (static ::$ fields [$ table ])) {
461+ if (empty (self ::$ fields [$ table ])) {
462462 throw new RuntimeException ('No fields found for class ' . get_class ($ object ));
463463 }
464- return static ::$ fields [$ table ];
464+ return self ::$ fields [$ table ];
465465 }
466466
467467 /**
@@ -477,7 +477,7 @@ private static function setField($object, $field, $value) {
477477 if (method_exists ($ object , $ method )) {
478478 $ object ->$ method ($ value );
479479 } else {
480- $ reflection = static ::getReflectionClass ($ object );
480+ $ reflection = self ::getReflectionClass ($ object );
481481 if (!$ reflection ->hasProperty ($ field )) {
482482 throw new InvalidArgumentException ('Unknown field ' . get_class ($ object ) . ':: ' . $ field );
483483 }
@@ -499,9 +499,9 @@ private static function setField($object, $field, $value) {
499499 private static function buildQuery ($ object ) {
500500 $ parameters = array ();
501501 $ sql = array ();
502- foreach (static ::getFields ($ object ) as $ field ) {
502+ foreach (self ::getFields ($ object ) as $ field ) {
503503 $ sql [] = '` ' . $ field . '` = : ' . $ field ;
504- $ parameters [$ field ] = static ::getField ($ object , $ field );
504+ $ parameters [$ field ] = self ::getField ($ object , $ field );
505505 }
506506 return array ($ sql , $ parameters );
507507 }
@@ -521,7 +521,7 @@ private static function getField($object, $field) {
521521 if (method_exists ($ object , $ method )) {
522522 $ retval = $ object ->$ method ();
523523 } else {
524- $ reflection = static ::getReflectionClass ($ object );
524+ $ reflection = self ::getReflectionClass ($ object );
525525 if ($ reflection ->hasProperty ($ field )) {
526526 $ property = $ reflection ->getProperty ($ field );
527527 $ property ->setAccessible (true );
@@ -552,7 +552,7 @@ private static function getReflectionClass($object) {
552552
553553 public static function buildField ($ _class , $ _prefix = '' ) {
554554 $ fields = array ();
555- foreach (static ::getFields ($ _class ) as $ field ) {
555+ foreach (self ::getFields ($ _class ) as $ field ) {
556556 if ('_ ' !== $ field [0 ]) {
557557 if ($ _prefix != '' ) {
558558 $ fields [] = '` ' . $ _prefix . '`. ' . '` ' . $ field . '` ' ;
0 commit comments