Validate your .env file and save yourself some headaches.
- Validates your .env file
- CLI and programmatic usage
Missing environment variables or incorrect value can cause some nasty bugs. Principles helps you to avoid those bugs by validating your .env file, saving you time and headaches.
Hi my name is Nils, I like to create things that make life easier. Creating a package that validates .env files is one of those things.
There are two ways to use this package: CLI and programmatic.
In the root of your project create a principles.json
file.
This file contains all the env variables you want to validate.
{
"MY_ENV_VAR": "required|string"
}
There are many rules you can use to validate your env variables. This list contains all of them.
Then run the following command:
./vendor/bin/principles
// Either define the rules here or load them from a file
$rules = [
'MY_ENV_VAR' => 'required|string',
];
$validation = new \Principles\EnvValidator($rules);
$validation->validate();
if ($validation->fails()) {
// TODO: handle errors
}
Use composer to add this package to the development dependencies of your project.
composer require principles/principles --require-dev
Requirements: PHP 7.4 or higher
If you have any suggestions or improvements, please open an issue or a pull request. I welcome any feedback.