定制 into-the-void/env 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

into-the-void/env

最新稳定版本:1.0

Composer 安装命令:

composer require into-the-void/env

包简介

Read, parse and modify environment variables

README 文档

README

Latest Packagist Version Latest Packagist License

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-12-07