Skip to content

Commit

Permalink
修正环境变量的布尔值解析
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Dec 31, 2021
1 parent 109ade6 commit d9cadb6
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/think/Env.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d9cadb6

Please sign in to comment.