Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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