mradcliffe / laravel-settings-injector
Laravel Settings Injector
Requires (Dev)
- laravel/framework: ~5.3
- phpspec/prophecy: ~1.6
- phpunit/phpunit: ~4.8
This package is auto-updated.
Last update: 2024-10-21 07:55:00 UTC
README
laravel-settings-injector provides a bootstrapper replacement for the default LoadConfiguration bootstrapper from Laravel.
This allows you to create a directory to manage settings from outside of the application directory with symlinks so that various environment-specific variables can be managed at a systems-level for production and other internal enviroments.
This is probably not useful for many installations of Laravel, however due to recommendations of not using dotenv files for production environment variables this is necessary to obfuscate production variables from the application repository. The advantage is that the variables are scoped to LoadConfiguration instead of using global environment variables.
Installation
composer require mradcliffe/laravel-settings-injector
Configuration
- Modify
app/Http/Kernel.php
. - Replace
\Illuminate\Foundation\Bootstrap\LoadConfiguration
with\Radcliffe\LaravelSettingsInjector\Bootstrap\LoadConfiguration
either by modifying an existing::$bootstrappers
protected variable or doing so within the::bootstrappers()
method of that class. - Modify
app/Console/Kernel.php
and add\Illuminate\Foundation\Console\Kernel::$bootstrappers
protected variables to there, and do the same replacement as in #2 above.
Usage
See tests
directory for some example fixtures.
- Create a
settings
directory in app root. - Provision files outside of the webroot, but required somehow by
settings/settings.php
. See image below. - Use those variables as normal in
config/*.php
to configure your application.- Note that any defines or requires could potentially happen more than once due to the way that Laravel works. Specifically
artisan config:cache
will load configuration after configuration has already been loaded so any use ofdefine
orrequire
withinsettings/settings.php
or any file it requires needs to take that into consideratino.
- Note that any defines or requires could potentially happen more than once due to the way that Laravel works. Specifically