bnomei / kirby3-dotenv
Kirby 3 Plugin for environment variables from .env
Fund package maintenance!
bnomei
Patreon
buymeacoff.ee/bnomei
paypal.me/bnomei
Installs: 21 900
Dependents: 1
Suggesters: 4
Security: 0
Stars: 31
Watchers: 2
Forks: 2
Open Issues: 1
Type:kirby-plugin
Requires
- php: >=8.0
- getkirby/composer-installer: ^1.1
- vlucas/phpdotenv: ^5.3
Requires (Dev)
- getkirby/cms: ^3.5
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ^9.5
Suggests
- bnomei/kirby3-janitor: Use a Panel Button or PHP code to clear the cache
- bnomei/kirby3-lapse: For faster and automatic caching based on modification of Kirby Objects
- bnomei/kirby3-security-headers: CPS headers to make the the web a saver place. Sensible defaults with zero configuration.
- robinscholz/better-rest: Allows you to send authenticated GET requests querying the Kirby API
README
Kirby 3 Plugin for environment variables from .env
Commercial Usage
Support open source!
This plugin is free but if you use it in a commercial project please consider to sponsor me or make a donation.
If my work helped you to make some cash it seems fair to me that I might get a little reward as well, right?
Be kind. Share a little. Thanks.
‐ Bruno
Similar Plugins
Installation
- unzip master.zip as folder
site/plugins/kirby3-dotenv
or git submodule add https://github.com/bnomei/kirby3-dotenv.git site/plugins/kirby3-dotenv
orcomposer require bnomei/kirby3-dotenv
Setup
.env file Examples
/.env
APP_MODE=production APP_DEBUG=false ALGOLIA_APIKEY=12d7331a21d8a28b3069c49830f463e833e30f6d KIRBY_API_USER=bnomei KIRBY_API_PW=52d3a0edcc78be6c5645fdb7568f94d3d83d1c2a
/.env.staging
APP_MODE=staging APP_DEBUG=true ALGOLIA_APIKEY=950306d052ec893b467f2ca088daf2964b9f9530 KIRBY_API_USER=notBnomei KIRBY_API_PW=37e30ad867ff3a427317dcd1852abbd692b39ffc
Usage everywhere but in Config files
⚠️ ATTENTION: The global PHP functions
getenv()
orputenv()
are NOT supported by this plugin since v2. What will work...
- use super globals
$_ENV[]
,$_SERVER[]
or- the plugins global helper function
env()
or->getenv()
,->env()
page and site methods
on server
echo $_ENV['APP_MODE']; // production echo env('APP_DEBUG'); // false // or echo $page->getenv('ALGOLIA_APIKEY'); // 12d7331a21d8a28b3069c49830f463e833e30f6d echo $page->env('ALGOLIA_APIKEY'); // 12d7331a21d8a28b3069c49830f463e833e30f6d echo site()->getenv('ALGOLIA_APIKEY'); // 12d7331a21d8a28b3069c49830f463e833e30f6d echo site()->env('ALGOLIA_APIKEY'); // 12d7331a21d8a28b3069c49830f463e833e30f6d
on staging server
echo $_ENV['APP_MODE']; // staging echo env('APP_DEBUG'); // true // or echo $page->getenv('ALGOLIA_APIKEY'); // 37e30ad867ff3a427317dcd1852abbd692b39ffc echo $page->env('ALGOLIA_APIKEY'); // 37e30ad867ff3a427317dcd1852abbd692b39ffc echo site()->getenv('ALGOLIA_APIKEY'); // 37e30ad867ff3a427317dcd1852abbd692b39ffc echo site()->env('ALGOLIA_APIKEY'); // 37e30ad867ff3a427317dcd1852abbd692b39ffc
Usage in Config files
See config examples on how to use this plugin in combination with kirbys config files. Since v2 this plugin support Kirbys Multi-environment setup used to merging multiple config files.
Default values
In case you want to provide a default value as fallback in case the environment variable is not set you can do that with the 2nd parameter in each helper function.
// `true` as default value echo env('ALGOLIA_ENABLED', true);
Thanks for your PR @teichsta
Settings
Dependencies
Disclaimer
This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please create a new issue.
License
It is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.
Credits
based on K2 version of