Skip to content

Commit 1ceb8d3

Browse files
Made store builder easier to use
1 parent a909e48 commit 1ceb8d3

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/Dotenv.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function __construct(LoaderInterface $loader, RepositoryInterface $reposi
6060
*/
6161
public static function create(RepositoryInterface $repository, $paths, $names = null, $shortCircuit = true)
6262
{
63-
$builder = StoreBuilder::create()->withPaths((array) $paths)->withNames((array) ($names ?: '.env'));
63+
$builder = StoreBuilder::create()->withPaths($paths)->withNames($names);
6464

6565
if ($shortCircuit) {
6666
$builder = $builder->shortCircuit();

src/Store/StoreBuilder.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class StoreBuilder
1616
/**
1717
* The file names to search for.
1818
*
19-
* @var string[]
19+
* @var string[]|null
2020
*/
2121
private $names;
2222

@@ -30,13 +30,13 @@ class StoreBuilder
3030
/**
3131
* Create a new store builder instance.
3232
*
33-
* @param string[] $paths
34-
* @param string[] $names
35-
* @param bool $shortCircuit
33+
* @param string[] $paths
34+
* @param string[]|null $names
35+
* @param bool $shortCircuit
3636
*
3737
* @return void
3838
*/
39-
private function __construct(array $paths = [], array $names = [], $shortCircuit = false)
39+
private function __construct(array $paths = [], array $names = null, $shortCircuit = false)
4040
{
4141
$this->paths = $paths;
4242
$this->names = $names;
@@ -56,25 +56,25 @@ public static function create()
5656
/**
5757
* Creates a store builder with the given paths.
5858
*
59-
* @param string[] $paths
59+
* @param string|string[] $paths
6060
*
6161
* @return \Dotenv\Repository\RepositoryBuilder
6262
*/
63-
public function withPaths(array $paths)
63+
public function withPaths($paths)
6464
{
65-
return new self($paths, $this->names, $this->shortCircuit);
65+
return new self((array) $paths, $this->names, $this->shortCircuit);
6666
}
6767

6868
/**
6969
* Creates a store builder with the given names.
7070
*
71-
* @param string[] $names
71+
* @param string|string[]|null $names
7272
*
7373
* @return \Dotenv\Store\StoreBuilder
7474
*/
75-
public function withNames(array $names)
75+
public function withNames($names = null)
7676
{
77-
return new self($this->paths, $names, $this->shortCircuit);
77+
return new self($this->paths, $names === null ? null : (array) $names, $this->shortCircuit);
7878
}
7979

8080
/**
@@ -95,7 +95,7 @@ public function shortCircuit()
9595
public function make()
9696
{
9797
return new FileStore(
98-
Paths::filePaths($this->paths, $this->names),
98+
Paths::filePaths($this->paths, $this->names === null ? ['.env'] : $this->names),
9999
$this->shortCircuit
100100
);
101101
}

0 commit comments

Comments
 (0)