Skip to content

Commit

Permalink
Merge pull request #397 from vlucas/store-tweaks
Browse files Browse the repository at this point in the history
[4.1] Made store builder easier to use
  • Loading branch information
GrahamCampbell authored Dec 12, 2019
2 parents 75a7c42 + 1ceb8d3 commit e26c085
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Dotenv.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct(LoaderInterface $loader, RepositoryInterface $reposi
*/
public static function create(RepositoryInterface $repository, $paths, $names = null, $shortCircuit = true)
{
$builder = StoreBuilder::create()->withPaths((array) $paths)->withNames((array) ($names ?: '.env'));
$builder = StoreBuilder::create()->withPaths($paths)->withNames($names);

if ($shortCircuit) {
$builder = $builder->shortCircuit();
Expand Down
24 changes: 12 additions & 12 deletions src/Store/StoreBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class StoreBuilder
/**
* The file names to search for.
*
* @var string[]
* @var string[]|null
*/
private $names;

Expand All @@ -30,13 +30,13 @@ class StoreBuilder
/**
* Create a new store builder instance.
*
* @param string[] $paths
* @param string[] $names
* @param bool $shortCircuit
* @param string[] $paths
* @param string[]|null $names
* @param bool $shortCircuit
*
* @return void
*/
private function __construct(array $paths = [], array $names = [], $shortCircuit = false)
private function __construct(array $paths = [], array $names = null, $shortCircuit = false)
{
$this->paths = $paths;
$this->names = $names;
Expand All @@ -56,25 +56,25 @@ public static function create()
/**
* Creates a store builder with the given paths.
*
* @param string[] $paths
* @param string|string[] $paths
*
* @return \Dotenv\Repository\RepositoryBuilder
*/
public function withPaths(array $paths)
public function withPaths($paths)
{
return new self($paths, $this->names, $this->shortCircuit);
return new self((array) $paths, $this->names, $this->shortCircuit);
}

/**
* Creates a store builder with the given names.
*
* @param string[] $names
* @param string|string[]|null $names
*
* @return \Dotenv\Store\StoreBuilder
*/
public function withNames(array $names)
public function withNames($names = null)
{
return new self($this->paths, $names, $this->shortCircuit);
return new self($this->paths, $names === null ? null : (array) $names, $this->shortCircuit);
}

/**
Expand All @@ -95,7 +95,7 @@ public function shortCircuit()
public function make()
{
return new FileStore(
Paths::filePaths($this->paths, $this->names),
Paths::filePaths($this->paths, $this->names === null ? ['.env'] : $this->names),
$this->shortCircuit
);
}
Expand Down

0 comments on commit e26c085

Please sign in to comment.