ejetar / laravel-environment
📂 根据您的环境加载自定义的 .env 文件。
0.1.0
2019-11-07 02:05 UTC
Requires
- php: >=5.4.0
This package is auto-updated.
Last update: 2024-09-05 05:10:51 UTC
README
目录
关于
Laravel Environment 是一个库,旨在与 Laravel 一起使用。它允许用户从原始文件中加载不同的 .env 文件。这个库最酷的地方在于它提供了不同的方法来实现这一点。
目前有 3 种方法
\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
工作原理
要使用此库非常简单,只需在 bootstrap/app.php 文件中的 return $app; 之前调用 Laravel Environment 即可
... \Ejetar\LaravelEnvironment\LaravelEnvironment::fromSystemEnvironmentVariable('MYAPP_ENV'); return $app;
开始使用
示例
从系统环境变量方法
第一个示例
在这个示例中,我们假设系统环境变量 MYAPP_ENV 存在并且值为 'production'。
\Ejetar\LaravelEnvironment\LaravelEnvironment::fromSystemEnvironmentVariable('MYAPP_ENV'); //Will load the environment file .env.production
第二个示例
在这个示例中,我们假设系统环境变量 MYAPP_ENV 不存在。
\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'.
第三个示例
在这个示例中,我们假设系统环境变量 MYAPP_ENV 不存在,并且 $default_value 将为 '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.
从文件方法
第一个示例
\Ejetar\LaravelEnvironment::fromFile('.env.local'); //Load the .env.local file explicitly
从自定义方法
第一个示例
加载基于服务器 IP 的环境文件
\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'; } });
安装
composer require ejetar/laravel-environment
变更日志
暂时没有...
贡献
为这个精彩的项目做出贡献,与您一起工作将是一种乐趣。让我们帮助免费软件社区。我们邀请您加入新特性、进行修正、报告错误以及提供其他形式的帮助。别忘了在这个存储库中 star!😀
许可协议
此库是一个开源软件,许可协议为 MIT。