Env.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006~2017 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. * @param string $name 环境变量名(支持二级 .号分割)
  17. * @param string $default 默认值
  18. * @return mixed
  19. */
  20. public static function get($name, $default = null)
  21. {
  22. $result = getenv(ENV_PREFIX . strtoupper(str_replace('.', '_', $name)));
  23. if (false !== $result) {
  24. if ('false' === $result) {
  25. $result = false;
  26. } elseif ('true' === $result) {
  27. $result = true;
  28. }
  29. return $result;
  30. } else {
  31. return $default;
  32. }
  33. }
  34. }