Skip to content

Commit fbb6a5f

Browse files
Replaced whitelists by allow lists
1 parent ca258dc commit fbb6a5f

File tree

5 files changed

+35
-35
lines changed

5 files changed

+35
-35
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,11 @@ interpolating environment variables, we'll only read from `$_ENV`. Moreover, it
178178
will never replace any variables already set before loading the file.
179179

180180
By means of another example, one can also specify a set of variables to be
181-
whitelisted. That is, only the variables in the whitelist will be loaded:
181+
allow listed. That is, only the variables in the allow list will be loaded:
182182

183183
```php
184184
$repository = Dotenv\Repository\RepositoryBuilder::createWithDefaultAdapters()
185-
->whitelist(['FOO', 'BAR'])
185+
->allowList(['FOO', 'BAR'])
186186
->make();
187187

188188
$dotenv = Dotenv\Dotenv::create($repository, __DIR__);

UPGRADING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Release notes for 5.0.0 are available [here](https://github.com/vlucas/phpdotenv
1515
3. Scalar typehints have been added to the public interface.
1616
4. The parser now returns a result type instead of raising an exception. This change is strictly internal, and most users won't notice a differnce. The responsibility for rasising an exception has simply been shifted up to the caller.
1717
5. Adapters have been refactored again, with changes to the repositories. In particular, the repository builder has been tweaked. It now expects to be explicitly told if you want to use the default adapters or not, and expects individual readers and writers to be added, one by one. Similar changes have been applied to the store factory. Moreover, the `ApacheAdapter` has been changed so that it behaves much like the other adapters. The old behaviour can be simulated by composing it with the new `ReplacingWriter` (see below). We will no longer include this adapter in our default setup, so that people can enable exactly what they need. Finally, by default, we will no longer be using the `PutenvAdapter`. It can be added, as required.
18-
6. Variable whitelisting has moved from the loader to be a responsibility of the repository, implemented via a special adapter.
18+
6. Variable whitelisting has been replaced with allow listing, and the responsibility has moved from the loader to a new adapter `GuardedWriter`.
1919
7. The parser has been moved to its own namespace and parses entire files now. This change is expected to have little impact when upgrading. The `Lines` class has also moved to the parser namespace.
2020
8. The loader now only returns the variables that were actually loaded into the repository, and not all the variables from the file. Moreover, it now expects as input the result of running the new parser (an array of entries), rather than raw file content.
2121

src/Repository/Adapter/WhitelistWriter.php renamed to src/Repository/Adapter/GuardedWriter.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Dotenv\Repository\Adapter;
66

7-
final class WhitelistWriter implements WriterInterface
7+
final class GuardedWriter implements WriterInterface
88
{
99
/**
1010
* The inner writer to use.
@@ -14,24 +14,24 @@ final class WhitelistWriter implements WriterInterface
1414
private $writer;
1515

1616
/**
17-
* The variable name whitelist.
17+
* The variable name allow list.
1818
*
1919
* @var string[]
2020
*/
21-
private $whitelist;
21+
private $allowList;
2222

2323
/**
24-
* Create a new whitelist writer instance.
24+
* Create a new guarded writer instance.
2525
*
2626
* @param \Dotenv\Repository\Adapter\WriterInterface $writer
27-
* @param string[] $whitelist
27+
* @param string[] $allowList
2828
*
2929
* @return void
3030
*/
31-
public function __construct(WriterInterface $writer, array $whitelist)
31+
public function __construct(WriterInterface $writer, array $allowList)
3232
{
3333
$this->writer = $writer;
34-
$this->whitelist = $whitelist;
34+
$this->allowList = $allowList;
3535
}
3636

3737
/**
@@ -44,8 +44,8 @@ public function __construct(WriterInterface $writer, array $whitelist)
4444
*/
4545
public function write(string $name, string $value)
4646
{
47-
// Don't set non-whitelisted variables
48-
if (!$this->isWhitelisted($name)) {
47+
// Don't set non-allowed variables
48+
if (!$this->isAllowed($name)) {
4949
return false;
5050
}
5151

@@ -62,8 +62,8 @@ public function write(string $name, string $value)
6262
*/
6363
public function delete(string $name)
6464
{
65-
// Don't clear non-whitelisted variables
66-
if (!$this->isWhitelisted($name)) {
65+
// Don't clear non-allowed variables
66+
if (!$this->isAllowed($name)) {
6767
return false;
6868
}
6969

@@ -72,14 +72,14 @@ public function delete(string $name)
7272
}
7373

7474
/**
75-
* Determine if the given variable is whitelisted.
75+
* Determine if the given variable is allowed.
7676
*
7777
* @param string $name
7878
*
7979
* @return bool
8080
*/
81-
private function isWhitelisted(string $name)
81+
private function isAllowed(string $name)
8282
{
83-
return \in_array($name, $this->whitelist, true);
83+
return \in_array($name, $this->allowList, true);
8484
}
8585
}

src/Repository/RepositoryBuilder.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Dotenv\Repository\Adapter\MultiWriter;
1212
use Dotenv\Repository\Adapter\ReaderInterface;
1313
use Dotenv\Repository\Adapter\ServerConstAdapter;
14-
use Dotenv\Repository\Adapter\WhitelistWriter;
14+
use Dotenv\Repository\Adapter\GuardedWriter;
1515
use Dotenv\Repository\Adapter\WriterInterface;
1616
use InvalidArgumentException;
1717
use PhpOption\Some;
@@ -51,28 +51,28 @@ final class RepositoryBuilder
5151
private $immutable;
5252

5353
/**
54-
* The variable name whitelist.
54+
* The variable name allow list.
5555
*
5656
* @var string[]|null
5757
*/
58-
private $whitelist;
58+
private $allowList;
5959

6060
/**
6161
* Create a new repository builder instance.
6262
*
6363
* @param \Dotenv\Repository\Adapter\ReaderInterface[] $readers
6464
* @param \Dotenv\Repository\Adapter\WriterInterface[] $writers
6565
* @param bool $immutable
66-
* @param string[]|null $whitelist
66+
* @param string[]|null $allowList
6767
*
6868
* @return void
6969
*/
70-
private function __construct(array $readers = [], array $writers = [], bool $immutable = false, array $whitelist = null)
70+
private function __construct(array $readers = [], array $writers = [], bool $immutable = false, array $allowList = null)
7171
{
7272
$this->readers = $readers;
7373
$this->writers = $writers;
7474
$this->immutable = $immutable;
75-
$this->whitelist = $whitelist;
75+
$this->allowList = $allowList;
7676
}
7777

7878
/**
@@ -158,7 +158,7 @@ public function addReader($reader)
158158

159159
$readers = \array_merge($this->readers, \iterator_to_array($optional));
160160

161-
return new self($readers, $this->writers, $this->immutable, $this->whitelist);
161+
return new self($readers, $this->writers, $this->immutable, $this->allowList);
162162
}
163163

164164
/**
@@ -191,7 +191,7 @@ public function addWriter($writer)
191191

192192
$writers = \array_merge($this->writers, \iterator_to_array($optional));
193193

194-
return new self($this->readers, $writers, $this->immutable, $this->whitelist);
194+
return new self($this->readers, $writers, $this->immutable, $this->allowList);
195195
}
196196

197197
/**
@@ -226,7 +226,7 @@ public function addAdapter($adapter)
226226
$readers = \array_merge($this->readers, \iterator_to_array($optional));
227227
$writers = \array_merge($this->writers, \iterator_to_array($optional));
228228

229-
return new self($readers, $writers, $this->immutable, $this->whitelist);
229+
return new self($readers, $writers, $this->immutable, $this->allowList);
230230
}
231231

232232
/**
@@ -236,19 +236,19 @@ public function addAdapter($adapter)
236236
*/
237237
public function immutable()
238238
{
239-
return new self($this->readers, $this->writers, true, $this->whitelist);
239+
return new self($this->readers, $this->writers, true, $this->allowList);
240240
}
241241

242242
/**
243-
* Creates a repository builder with the given whitelist.
243+
* Creates a repository builder with the given allow list.
244244
*
245-
* @param string[]|null $whitelist
245+
* @param string[]|null $allowList
246246
*
247247
* @return \Dotenv\Repository\RepositoryBuilder
248248
*/
249-
public function whitelist(array $whitelist = null)
249+
public function allowList(array $allowList = null)
250250
{
251-
return new self($this->readers, $this->writers, $this->immutable, $whitelist);
251+
return new self($this->readers, $this->writers, $this->immutable, $allowList);
252252
}
253253

254254
/**
@@ -265,8 +265,8 @@ public function make()
265265
$writer = new ImmutableWriter($writer, $reader);
266266
}
267267

268-
if ($this->whitelist !== null) {
269-
$writer = new WhitelistWriter($writer, $this->whitelist);
268+
if ($this->allowList !== null) {
269+
$writer = new GuardedWriter($writer, $this->allowList);
270270
}
271271

272272
return new AdapterRepository($reader, $writer);

tests/Dotenv/Loader/LoaderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ public function testLoaderWithNoReaders()
3232
self::assertSame($expected, $loader->load($repository, (new Parser())->parse($content)));
3333
}
3434

35-
public function testLoaderWithWhitelist()
35+
public function testLoaderWithAllowList()
3636
{
3737
$adapter = ArrayAdapter::create()->get();
38-
$repository = RepositoryBuilder::createWithNoAdapters()->addReader($adapter)->addWriter($adapter)->whitelist(['FOO'])->make();
38+
$repository = RepositoryBuilder::createWithNoAdapters()->addReader($adapter)->addWriter($adapter)->allowList(['FOO'])->make();
3939
$loader = new Loader();
4040

4141
self::assertSame(['FOO' => 'Hello'], $loader->load($repository, (new Parser())->parse("FOO=\"Hello\"\nBAR=\"World!\"\n")));

0 commit comments

Comments
 (0)