into-the-void/env
最新稳定版本:1.0
Composer 安装命令:
composer require into-the-void/env
包简介
Read, parse and modify environment variables
README 文档
README
Read, parse and modify environment variables
Installation
You can install this library via composer:
composer require into-the-void/env
Example
use IntoTheVoid\Env\Env; getenv('APP_DEBUG'); // string(4) "true" Env::get('APP_DEBUG'); // bool(true) getenv('DB_PORT'); // string(4) "5432" Env::get('DB_PORT'); // int(5432) Env::getString('DB_HOST'); // string(9) "localhost" Env::getBool('APP_DEBUG'); // bool(true) Env::getInt('DB_PORT'); // int(5432) Env::getFloat('APP_MUL'); // double(1.25) Env::getList('PATH', ':'); // array(2) { "/usr/local/bin", "/usr/bin" } Env::has('DB_PORT'); // bool(true) Env::set('DB_PORT', 3306); Env::remove('DB_PORT');
You may also use the helper function instead of calling Env::get():
use function IntoTheVoid\Env\env; env('APP_DEBUG'); // bool(true)
Behaviour
Env::getBool('NO_SUCH_VAR'); // NULL Env::getRequiredBool('NO_SUCH_VAR'); // Fatal error: MissingEnvironmentVariable Env::getBool('NOT_A_BOOL'); // Fatal error: UnparsableValue Env::getBool('NOT_A_BOOL', strict: false); // NULL
Repository
By default, environment variables are read via getenv(local_only: true) and getenv(). They are written via putenv(), $_ENV and $_SERVER.
You may change this behaviour using Env::setRepository(). Have a look at src/Repository for available Repositories.
Normalizer
If you want to strip spaces or quotes from your environment variables, then you may configure this via Env::setNormalizer(). Have a look at src/Normalizer for available Normalizers.
This is not done by default, because your environment variables should not contain any unwanted spaces or quotes. If they do you probably should fix the declaration of those environment variables instead.
Parser
Nullish values (case insensitive): '', 'null', 'nil', 'none', 'undefined', 'empty'
Truthy values (case insensitive): '1', 'true', 'y', 'yes', 'on'
Falsy values (case insensitive): '0', 'false', 'n', 'no', 'off'
License
Copyright (C) Oliver Amann
This project is licensed under the MIT License (MIT). Please see LICENSE for more information.
统计信息
- 总下载量: 23
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-12-07