承接 tiny-blocks/environment-variable 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

tiny-blocks/environment-variable

最新稳定版本:1.1.1

Composer 安装命令:

composer require tiny-blocks/environment-variable

包简介

Provides a simple and flexible solution for managing environment variables, with easy access, type conversions, and validation handling.

README 文档

README

License

Overview

Provides a simple and flexible solution for managing environment variables, with easy access, type conversions, and validation handling.

Installation

composer require tiny-blocks/environment-variable

How to use

Creating an environment variable

To create and work with environment variables, use the from method to get an instance of the environment variable.

EnvironmentVariable::from(name: 'MY_VAR');

To retrieve an environment variable with the option of providing a default value in case the variable does not exist, use the fromOrDefault method.

If the environment variable is not found, the method will return the provided default value instead of throwing an exception.

EnvironmentVariable::fromOrDefault(name: 'MY_VAR', defaultValueIfNotFound: 'default_value');

Conversions

Once you have an instance of the environment variable, you can convert its value into various types.

Convert to string

To convert the environment variable to a string.

$environmentVariable = EnvironmentVariable::from(name: 'MY_VAR');
$environmentVariable->toString();

Convert to integer

To convert the environment variable to an integer.

$environmentVariable = EnvironmentVariable::from(name: 'MY_VAR');
$environmentVariable->toInteger();

Convert to boolean

To convert the environment variable to a boolean.

$environmentVariable = EnvironmentVariable::from(name: 'MY_VAR');
$environmentVariable->toBoolean();

Check if the environment variable has a value

Checks if the environment variable has a value. Values like false, 0, and -1 are valid and non-empty.

$environmentVariable = EnvironmentVariable::from(name: 'MY_VAR');
$environmentVariable->hasValue();

License

Environment variable is licensed under MIT.

Contributing

Please follow the contributing guidelines to contribute to the project.

统计信息

  • 总下载量: 417
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-09