承接 vatradar/env 相关项目开发

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

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

vatradar/env

最新稳定版本:0.6.0

Composer 安装命令:

composer require vatradar/env

包简介

An environment variable convenience library extension for vlucas/phpdotenv

README 文档

README

This package is fairly simple - it's meant to standardize access to environment variables without having to resort to accessing $_ENV['SOME_VAR'] directly. Yes, this is more of a preference thing rather than actually addressing a technical deficiency. And that's okay.

It encapsulates vlucas/phpdotenv package and provides access to that package's instance for custom configuration as well as a convenience method to access environment variables. It is also opinionated, so it initializes as immutable by default. It is also not meant for super-complex configurations with multiple .env files. For that, just use dotenv directly.

Quick install

composer require vatradar/env

Env attempts to follow semantic versioning principles but is also part of a larger private monorepo and shared codebase – due to this, version bumps of this package may happen even if no package-specific changes occur.

Quick Start

<?php

use VatRadar\Env\Env;

require __DIR__.'/vendor/autoload.php';

// Can be used without initializing to grab normally-existing environment vars
Env::get('USER');

// Initialize using path to directory that will contain your .env file
// and then access environment variables
Env::init(__DIR__);
$myVar = Env::get('MY_ENV_VAR');

// Pass a repository if needed
$repository = Dotenv\Repository\RepositoryBuilder::createWithDefaultAdapters()
    ->allowList(['FOO', 'BAR'])
    ->make();
Env::init(__DIR__, $repository);

// Customize dotenv configuration
$dotenv = Env::create(__DIR__);
$dotenv->required(['DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS']);
Env::init($dotenv);
$dbHost = Env::get('DB_HOST');

// You can also add the repository
$dotenv = Env::create(__DIR__, $repository);
$dotenv->required(['DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS']);
Env::init($dotenv);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: LGPL-3.0
  • 更新时间: 2023-03-07