25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

40 lines
1.2 KiB

  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: liu21st <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. namespace think;
  12. class Env
  13. {
  14. /**
  15. * 获取环境变量值
  16. * @access public
  17. * @param string $name 环境变量名(支持二级 . 号分割)
  18. * @param string $default 默认值
  19. * @return mixed
  20. */
  21. public static function get($name, $default = null)
  22. {
  23. $result = getenv(ENV_PREFIX . strtoupper(str_replace('.', '_', $name)));
  24. if (false !== $result) {
  25. if ('false' === $result) {
  26. $result = false;
  27. } elseif ('true' === $result) {
  28. $result = true;
  29. }
  30. return $result;
  31. }
  32. return $default;
  33. }
  34. }