PageRenderTime 48ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Stat.php

https://github.com/aimxhaisse/kenavo
PHP | 35 lines | 26 code | 5 blank | 4 comment | 2 complexity | 41505c223e83edef8487ec8ef9363896 MD5 | raw file
  1. <?php
  2. class Stat
  3. {
  4. // Very simple logger, to be upgraded...
  5. // Loads the database from the Stat file
  6. public static function loadDb()
  7. {
  8. if (!file_exists(STATS))
  9. {
  10. return array();
  11. }
  12. return unserialize(file_get_contents(STATS));
  13. }
  14. // Save the database to the Stat file
  15. private static function saveDb($db)
  16. {
  17. file_put_contents(STATS, serialize($db));
  18. }
  19. // Let's log the request
  20. public static function log()
  21. {
  22. $db = self::loadDb();
  23. if (!isset($db['total_pages']))
  24. {
  25. $db['total_pages'] = 0;
  26. }
  27. $db['total_pages']++;
  28. self::saveDb($db);
  29. }
  30. }