StoreBuilder.php
3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
declare(strict_types=1);
namespace Dotenv\Store;
use Dotenv\Store\File\Paths;
final class StoreBuilder
{
/**
* The of default name.
*/
private const DEFAULT_NAME = '.env';
/**
* The paths to search within.
*
* @var string[]
*/
private $paths;
/**
* The file names to search for.
*
* @var string[]
*/
private $names;
/**
* Should file loading short circuit?
*
* @var bool
*/
private $shortCircuit;
/**
* The file encoding.
*
* @var string|null
*/
private $fileEncoding;
/**
* Create a new store builder instance.
*
* @param string[] $paths
* @param string[] $names
* @param bool $shortCircuit
* @param string|null $fileEncoding
*
* @return void
*/
private function __construct(array $paths = [], array $names = [], bool $shortCircuit = false, string $fileEncoding = null)
{
$this->paths = $paths;
$this->names = $names;
$this->shortCircuit = $shortCircuit;
$this->fileEncoding = $fileEncoding;
}
/**
* Create a new store builder instance with no names.
*
* @return \Dotenv\Store\StoreBuilder
*/
public static function createWithNoNames()
{
return new self();
}
/**
* Create a new store builder instance with the default name.
*
* @return \Dotenv\Store\StoreBuilder
*/
public static function createWithDefaultName()
{
return new self([], [self::DEFAULT_NAME]);
}
/**
* Creates a store builder with the given path added.
*
* @param string $path
*
* @return \Dotenv\Store\StoreBuilder
*/
public function addPath(string $path)
{
return new self(\array_merge($this->paths, [$path]), $this->names, $this->shortCircuit, $this->fileEncoding);
}
/**
* Creates a store builder with the given name added.
*
* @param string $name
*
* @return \Dotenv\Store\StoreBuilder
*/
public function addName(string $name)
{
return new self($this->paths, \array_merge($this->names, [$name]), $this->shortCircuit, $this->fileEncoding);
}
/**
* Creates a store builder with short circuit mode enabled.
*
* @return \Dotenv\Store\StoreBuilder
*/
public function shortCircuit()
{
return new self($this->paths, $this->names, true, $this->fileEncoding);
}
/**
* Creates a store builder with the specified file encoding.
*
* @param string|null $fileEncoding
*
* @return \Dotenv\Store\StoreBuilder
*/
public function fileEncoding(string $fileEncoding = null)
{
return new self($this->paths, $this->names, $this->shortCircuit, $fileEncoding);
}
/**
* Creates a new store instance.
*
* @return \Dotenv\Store\StoreInterface
*/
public function make()
{
return new FileStore(
Paths::filePaths($this->paths, $this->names),
$this->shortCircuit,
$this->fileEncoding
);
}
}