定制 ejetar/laravel-environment 二次开发

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

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

ejetar/laravel-environment

Composer 安装命令:

composer require --dev ejetar/laravel-environment

包简介

📂 Load a custom .env file according to your environment.

README 文档

README

Table of Contents

About

Laravel Environment is a library designed to be used in conjunction with Laravel. It enables the user to load a different .env file from the original. The coolest thing about this library is that it provides different methods for you to do this.

There are currently 3 methods:

\Ejetar\LaravelEnvironment\LaravelEnvironment::fromSystemEnvironmentVariable($system_environment_variable_name, $default_value = 'local')
//Loads an environment file according to the value of a system environment variable
\Ejetar\LaravelEnvironment\LaravelEnvironment::fromFile($filename)
//Loads an environment file explicitly, stating the file path
\Ejetar\LaravelEnvironment\LaravelEnvironment::fromCustomMethod(Callable $callable)
//Enables the user to enter a custom method for loading the environment file

How it works

To use this library is very simple, just call Laravel Environment before return $app; in the bootstrap/app.php file:

...

\Ejetar\LaravelEnvironment\LaravelEnvironment::fromSystemEnvironmentVariable('MYAPP_ENV');

return $app;

Get started

Examples

From system environment variable method

First example

We assume in this example that the system environment variable MYAPP_ENV exists and has the value 'production'.

\Ejetar\LaravelEnvironment\LaravelEnvironment::fromSystemEnvironmentVariable('MYAPP_ENV');
//Will load the environment file .env.production
Second example

We assume in this example that the system environment variable MYAPP_ENV does not exist.

\Ejetar\LaravelEnvironment\LaravelEnvironment::fromSystemEnvironmentVariable('MYAPP_ENV');
//Will load the .env.local environment file. When the system environment variable does not exist, then it takes $default_value.
//By default $default_value is set to 'local'.
Third example

We assume in this example that the system environment variable MYAPP_ENV does not exist, and $default_value will be 'acme'.

\Ejetar\LaravelEnvironment\LaravelEnvironment::fromSystemEnvironmentVariable('MYAPP_ENV', 'acme');
//Will load the .env.acme environment file. When the system environment variable does not exist, then it takes $default_value.

From file method

First example
\Ejetar\LaravelEnvironment::fromFile('.env.local');
//Load the .env.local file explicitly

From custom method

First example

Loading the server IP-based environment file:

\Ejetar\LaravelEnvironment\LaravelEnvironment::fromCustomMethod(function(){
  switch($_SERVER['SERVER_ADDR']) {
    case '1.2.3.4':
      return '.env.local';
      break;
    case '5.6.7.8':
      return '.env.production';
      break;
    default: 
      return '.env.other';
  }
});

Installation

composer require ejetar/laravel-environment

Changelog

Nothing for now...

Contributing

Contribute to this wonderful project, it will be a pleasure to have you with us. Let's help the free software community. You are invited to incorporate new features, make corrections, report bugs, and any other form of support. Don't forget to star in this repository! 😀

License

This library is a open-source software licensed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-11-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固