From a7707e1843b7841772cf2a112dd10d3150fee492 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 31 Aug 2016 18:49:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Env=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Env.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 library/think/Env.php diff --git a/library/think/Env.php b/library/think/Env.php new file mode 100644 index 00000000..a23d9925 --- /dev/null +++ b/library/think/Env.php @@ -0,0 +1,31 @@ + +// +---------------------------------------------------------------------- + +namespace think; + +class Env +{ + /** + * 获取环境变量值 + * @param string $name 环境变量名(支持二级 .号分割) + * @param string $default 默认值 + * @return mixed + */ + public static function get($name, $default = null) + { + $result = getenv(ENV_PREFIX . strtoupper(str_replace('.', '_', $name))); + if (false !== $result) { + return $result; + } else { + return $default; + } + } +}