bubblegum-php/bubblegum-environment
最新稳定版本:1.0.0
Composer 安装命令:
composer require bubblegum-php/bubblegum-environment
包简介
Environment manager module for BUBBLEGUM.
README 文档
README
.env configuration module for BUBBLEGUM
Installation
Require this module with composer
composer require bubblegum-php/bubblegum-environment
Usage
Load environment
Getting environment variables
You can simply use the env helper to get the environment variable.
env('VARIABLE_NAME', 'DefaultValue')
You can define a default value for a variable, which will be returned if the environment variable with the same name is not set.
If neither a default value nor an environment variable is set, this method returns null.
Get or Throw
Throws an exception if an environment variable is not found.
use Bubblegum\Environment; Environment::getOrThrow('VARIABLE_NAME'); // Throws an EnvironmentException if there is no variable named 'VARIABLE_NAME'
Basic Load
use Bubblegum\Environment; Environment::loadFromFile('path/to/env/file');
Load if not prevented
You can prevent the .env file loading if the environment already have the PREVENT_ENV_FILE_LOADING variable set to true.
name: bubblegum services: php: build: context: ./docker/ dockerfile: php.dockerfile env_file: - ./.env # we already have environment loading here environment: PREVENT_ENV_FILE_LOADING: true # so we don't need to load it
If loading is NOT prevented, this method will load the environment.
use Bubblegum\Environment; Environment::loadIfNotPrevented('path/to/env/file');
Put variables locally
You can put variables locally without saving them to a file.
use Bubblegum\Environment; $value = 'Hello There!' Environment::put('VARIABLE_NAME', $value); env(VARIABLE_NAME) // returns 'Hello There!'
统计信息
- 总下载量: 46
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-26