felixdorn/dot-env

此包已被弃用且不再维护。作者建议使用vlucas/phpdotenv包。

PHP最轻量级的.env解析器。支持连接。

1.2.1 2019-08-26 23:06 UTC

This package is auto-updated.

Last update: 2020-05-26 08:17:25 UTC


README

composer require felixdorn/dot-env

比你想的更容易!

use Felix\DotEnv;
DotEnv::register('.env');

注意,您可以注册多个.env

.env

FOO=BAR # You can access to FOO by typing $_SERVER['FOO'] or $_ENV['FOO'] or getenv('FOO')
NAME=Hello${FOO} #  Will print HelloBar
NICKNAME=Felix
# You can write comment ! Yeah !
SENTENCE="Hey Guys" # space allowed only when value is in parentheses
ANOTHER_SENTENCES="Hey ${NICKNAME}" # will print Hey Felix
baDCase=DUMMY_VALUE # baDCase became BADCASE when parsing so access to baDCase value with $_SERVER['BADCASE']
something # To make workflow more simple, this will output an empty value like $_ENV['SOMETHING']
fdsldjs=${UNEXISTING} # This will be simply removed while this value doesn't exist 

仅解析

如果您只想解析env文件,而不将值放入ENV中

$content = (new DotEnv)->setFilename('../tests/.env.test')->parseOnly();