GlobConfigs.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace app\lib;
  3. /**
  4. * Created by PhpStorm.
  5. * User: Administrator
  6. * Date: 2019/5/20
  7. * Time: 9:17
  8. */
  9. class GlobConfigs {
  10. public static $file = '';
  11. public static $configs = [] ;
  12. public static $isload = false ;
  13. private static $instance = null ;
  14. public static function getInstance(){
  15. if (self::$instance){
  16. return self::$instance;
  17. }
  18. self::$instance = new GlobConfigs();
  19. return self::$instance ;
  20. }
  21. public static function getKey($key,$default=''){
  22. if (!self::$isload) { self::load(); }
  23. if (isset(self::$configs[$key])){
  24. return self::$configs[$key];
  25. }
  26. return $default ;
  27. }
  28. public static function setKey($key,$val){
  29. if (!self::$isload) { self::load(); }
  30. self::$configs[$key] = $val;
  31. }
  32. public static function getAll(){
  33. if (!self::$isload) { self::load(); }
  34. return self::$configs ;
  35. }
  36. public static function load($file=''){
  37. if ( self::$isload ){ return true ; }
  38. if (empty($file)){
  39. $file = CONFIG_PATH.DS.'configs.php';
  40. }
  41. self::$configs = require_once ($file);
  42. self::$isload = true ;
  43. }
  44. }