dbtlr/php-env-builder 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

dbtlr/php-env-builder

Composer 安装命令:

composer require dbtlr/php-env-builder

包简介

A PHP library that assists in automating the building of .env files.

README 文档

README

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads

Makes building .env files from the command-line simple.

For loading and using .env files in your development workflow, I highly suggest looking to the vlucas/phpdotenv package, which helps abstract out the process of loading environmental variables. This library is designed to help you build a local .env library that you can add to your .gitignore file, without the extra .env.example file that most people add to document how to build it.

Why .env?

Installation

The recommended method of installing this library is via Composer.

Run the following command from your project root:

$ composer require --dev dbtlr/php-env-builder

Usage as a Composer Script

Because Composer provides its own way of working with the console IO, the extra.php-env-builder config is the proper way of setting up your questions and variable names in this use case.

In order to have your .env file built when you run composer install or composer update you should provide config similar to this:

{
    "scripts": {
        "build-env": "Dbtlr\\PHPEnvBuilder\\ComposerScriptRunner::build",
        "post-install-cmd": "@build-env",
        "post-update-cmd": "@build-env"
    },
    "extra": {
        "php-env-builder": {
            "envFile": ".env",
            "questions": [
                {
                    "name": "MYSQL_HOST",
                    "prompt": "What is the hostname for the MySQL server?",
                    "default": "127.0.0.1",
                    "required": true
                },
                {
                    "name": "MYSQL_PORT",
                    "prompt": "The port for the MySQL server?",
                    "default": "3306",
                    "required": true
                },
                {
                    "name": "MYSQL_USER",
                    "prompt": "What is the MySQL user?",
                    "default": "app",
                    "required": true
                },
                {
                    "name": "MYSQL_PASSWORD",
                    "prompt": "What is the MySQL password?",
                    "default": "app-password",
                    "required": true
                }
            ]
        }
    }
}

All extra.php-env-builder options

  • questions - default: [] (required) // An array of questions that contain at least the name and prompt elements.
  • envFile - default: .env // Either the absolute location or one that is relative to your package.json file.
  • clobber - default: false // Will an existing .env file be overwritten on build?
  • loadEnv - default: false // If an existing file is being clobbered, will it be loaded to provide defaults?
  • verbose - default: false // Extra output

General Usage

If you would like to roll your own script, the syntax itself is fairly straightforward.

Note: This is a less expected use case, since the console IO needs to be provided by Composer, in order for it to accept input from inside a Composer script. This may be useful if you want to run this instead from a Makefile or an npm run postinstall

require_once __DIR__ . "/vendor/autoload.php";

$config = [
    'verbose' => true,
    'loadEnv' => true,
];

$builder = new \Dbtlr\PHPEnvBuilder\Builder('/path/to/.env', $config);

$builder->ask(
    'name',              // ENV variable name
    'What is your name?' // Command prompt
    '',                  // Default answer
    true                 // Is required?
);

$builder->run(); // Run the builder and return the answers.
$builder->write(); // Write the answers to the file.

Running tests?

All tests are run using PHPUnit. Make sure you have at least PHP 7.1 installed, as well as Composer.

To run tests, simply run:

composer install
composer test

Want to contribute?

Read more here

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-08-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固