From d9cadb6971ae92ff85ba5f2be77a40b0ad5718fb Mon Sep 17 00:00:00 2001 From: ThinkPHP Date: Fri, 31 Dec 2021 17:14:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E7=9A=84=E5=B8=83=E5=B0=94=E5=80=BC=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/think/Env.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/think/Env.php b/src/think/Env.php index 21fd25015d..1046bc4845 100644 --- a/src/think/Env.php +++ b/src/think/Env.php @@ -26,6 +26,17 @@ class Env implements ArrayAccess */ protected $data = []; + /** + * 数据转换映射 + * @var array + */ + protected $convert = [ + 'true' => true, + 'false' => false, + 'off' => false, + 'on' => true, + ]; + public function __construct() { $this->data = $_ENV; @@ -57,9 +68,14 @@ public function get(string $name = null, $default = null) } $name = strtoupper(str_replace('.', '_', $name)); - if (isset($this->data[$name])) { - return $this->data[$name]; + $result = $this->data[$name]; + + if (is_string($result) && isset($this->convert[$result])) { + return $this->convert[$result]; + } + + return $result; } return $this->getEnv($name, $default);