<?php
namespace  app\lib;
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/5/20
 * Time: 9:17
 */


class GlobConfigs {
    public static $file = '';
    public static $configs = [] ;
    public static $isload = false ;
    private static $instance = null ;

    public static function  getInstance(){
        if (self::$instance){
            return self::$instance;
        }
        self::$instance = new  GlobConfigs();
        return   self::$instance ;
    }

    public static function  getKey($key,$default=''){
         if (!self::$isload) { self::load();  }
         if (isset(self::$configs[$key])){
             return self::$configs[$key];
         }
         return $default ;
    }
    public static  function  setKey($key,$val){
        if (!self::$isload) { self::load();  }
        self::$configs[$key] = $val;
    }

    public static function getAll(){
        if (!self::$isload) { self::load();  }
        return self::$configs ;
    }

    public static function  load($file=''){
        if ( self::$isload  ){            return true ;       }

        if (empty($file)){
            $file =  CONFIG_PATH.DS.'configs.php';
        }
        self::$configs = require_once ($file);
        self::$isload = true ;
    }


}