0.0.0 / laravel-env-shim
Use Laravel's pre-5.8 env() function in your non-Laravel projects.
Requires
- php: >=7.0
- 0.0.0/composer-include-files: *
- vlucas/phpdotenv: *
Requires (Dev)
README
Benefits
- Works with any package, even non-Laravel ones (it was my secondary reason)
- You no longer have to fear Laravel just going one day "Oops! We're not going to read from the environment anymore! Too bad!" on a non-major release.
Backstory
With the introduction of Laravel 5.8, they broke the essential env()
function
by changing it from reading from/writing to environment variables to only using
the global $_SERVER
array, which is totally useless in console-based apps.
See
Therefore, I took it upon myself to create this polyfill to ensure that the pre-5.8 behaviors remain intact.
Additionally, this is a great little utility function to use outside of Laravel-specic
projects that also want to use the env()
function.
It is specially configured with a 0.0.1
composer vendor and a AAutoloadFirst
namespace, so that composer will always load it before it gets to Laravel.
See composer/composer#6768
The source code is lifted directly from the last version of Laravel 5.7.
As you can imagine, most of the copyright in this project belongs to Taylor Otwell, 2018.
It also includes 100% unit test code .
Installation
Via Composer
composer require phpexperts/laravel-env-polyfill
Usage
putenv('foo=bar'); $foo = \env('foo'); // 'bar'
and
if (in_array(SomeTrait::class, class_uses_recursive($this)) { // The class or its child it's being called from uses SomeTrait. }
Use cases
PHPExperts\Laravel57EnvPolyfill\Tests\Env
✔ Env
✔ Env with quotes
✔ Env true
✔ Env false
✔ Env empty
✔ Env null
✔ Value
✔ Env will use default value if needed
✔ Will load vlucas/phpdot if a .env is present.
✔ Will not load vlucas/phpdotenv if a .env is not present.
Testing
phpunit
Contributors
Theodore R. Smith theodore@phpexperts.pro
GPG Fingerprint: 4BF8 2613 1C34 87AC D28F 2AD8 EB24 A91D D612 5690
CEO: PHP Experts, Inc.
License
MIT license. Please see the license file for more information.