Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.1] Implement variable name whitelist #398

Merged
merged 1 commit into from
Dec 13, 2019
Merged

[4.1] Implement variable name whitelist #398

merged 1 commit into from
Dec 13, 2019

Conversation

GrahamCampbell
Copy link
Collaborator

It is now possible to tell the loader to only allow a predefined set of variables to be loaded. Since whitelisting is a kinda edge case requirement, I'll not be adding special create methods, like I did for choosing between mutable and immutable. Directly newing up Dotenv will be required. This is to keep the interface nice and simple for the majority of users.

A full example is below, assuming the directory where the .env file is stored in $directory and the array of allowed environment variable names (case sensitive) is in $whitelist:

<php

use Dotenv\Dotenv;
use Dotenv\Loader\Loader;
use Dotenv\Repository\RepositoryBuilder;
use Dotenv\Store\StoreBuilder;

$loader = new Loader($whitelist);
$repository = RepositoryBuilder::create()->immutable()->make();
$store = StoreBuilder::create()->withPaths($directory)->make();

$dotenv = new Dotenv($loader, $repository, $store);

$dotenv->load();

// cc @ilimic1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant