koriym / env-json
Installs: 81 770
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 3
Open Issues: 0
Requires
- php: ^7.4 || ^8.0
- ext-json: *
- evaisse/php-json-schema-generator: ^2.1
- justinrainbow/json-schema: ^5.2
Requires (Dev)
- doctrine/coding-standard: ^10.0
- phpmd/phpmd: ^2.9
- phpmetrics/phpmetrics: ^2.7
- phpstan/phpstan: ^1.1
- phpunit/phpunit: ^8.5.27 || ^9.5
- squizlabs/php_codesniffer: ^3.5
- vimeo/psalm: ^4.2
This package is auto-updated.
Last update: 2024-11-02 13:07:57 UTC
README
Use JSON instead of .env
file to set environment variables.
Validation by JSON schema is performed on environment variables as well as JSON.
Installation
composer require koriym/env-json
Usage
Specify the directory of the env.schema.json
schema file to load()
.
(new EnvJson())->load($dir);
- If environment variables are already set, they are validated by
env.schema.json
to see if they are correct. - If not,
env.json
orenv.dist.json
is read, validated byenv.schema.json
, and exported as the environment variables.
$dir/env.json
or $dir/env.dist.json
{ "$schema": "./env.schema.json", "FOO": "foo1", "BAR": "bar1" }
$dir/env.schema.json
{ "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "required": [ "FOO", "BAR" ], "properties": { "FOO": { "description": "Foo's value", "minLength": 3 }, "BAR": { "description": "Bar's value", "enum": ["bar1", "bar2"] } } }
It can provide more appropriate documentation and constraints compared to .env
files.
Convert ini file
JSON and its schema file are generated from the .env
file with ini2json
.
. /vendor/bin/ini2json .env