Env.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. }