Passed
Push — 0.7.0 ( 7cf8ff...8cbd21 )
by Alexander
04:15 queued 11s
created

StoreBuilder::make()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php 
2
3
/**
4
 * Lenevor Framework
5
 *
6
 * LICENSE
7
 *
8
 * This source file is subject to the new BSD license that is bundled
9
 * with this package in the file license.md.
10
 * It is also available through the world-wide-web at this URL:
11
 * https://lenevor.com/license
12
 * If you did not receive a copy of the license and are unable to
13
 * obtain it through the world-wide-web, please send an email
14
 * to [email protected] so we can send you a copy immediately.
15
 *
16
 * @package     Lenevor
17
 * @subpackage  Base
18
 * @link        https://lenevor.com
19
 * @copyright   Copyright (c) 2019 - 2021 Alexander Campo <[email protected]>
20
 * @license     https://opensource.org/licenses/BSD-3-Clause New BSD license or see https://lenevor.com/license or see /license.md
21
 */
22
23
namespace Syscodes\Dotenv\Store;
24
25
use Syscodes\Dotenv\Store\Contributors\Paths;
26
27
/**
28
 * Create a store builder for environment files.
29
 * 
30
 * @author Alexander Campo <[email protected]>
31
 */
32
final class StoreBuilder
33
{
34
    /**
35
     * The of default name.
36
     * 
37
     * @var string[] DEFAULT_NAME
38
     */
39
    protected const DEFAULT_NAME = '.env';
40
41
    /**
42
     * Should file loading in enabled mode? 
43
     * 
44
     * @var bool $modeEnabled
45
     */
46
    protected $modeEnabled;
47
48
    /**
49
     * Get the file name .env.
50
     * 
51
     * @var string[] $names
52
     */
53
    protected $names;
54
55
    /**
56
     * The directory where the .env file is located.
57
     * 
58
     * @var string[] $paths
59
     */
60
    protected $paths;
61
62
    /**
63
     * Constructor. Create a new FileStore instance.
64
     * 
65
     * @param  string|string[]  $paths
66
     * @param  string|string[]  $names
67
     * @param  bool  $modeEnabled  (false by default)
68
     * 
69
     * @return void
70
     */
71
    public function __construct(array $paths = [], array $names = [], bool $modeEnabled = false)
72
    {
73
        $this->paths       = $paths;
74
        $this->names       = $names;
75
        $this->modeEnabled = $modeEnabled;
76
    }
77
    
78
    /**
79
     * Create a new file store instance with no names.
80
     * 
81
     * @return \Syscodes\Dotenv\Store\StoreBuilder
82
     */
83
    public static function createWithNoNames()
84
    {
85
        return new self();
86
    }
87
    
88
    /**
89
     * Create a new file store instance with the default name.
90
     * 
91
     * @return \Syscodes\Dotenv\Store\StoreBuilder
92
     */
93
    public static function createWithDefaultName()
94
    {
95
        return new self([], [self::DEFAULT_NAME]);
96
    }
97
    
98
    /**
99
     * Creates a file store with the given path added.
100
     * 
101
     * @param  string  $path
102
     * 
103
     * @return \Syscodes\Dotenv\Store\StoreBuilder
104
     */
105
    public function addPath(string $path)
106
    {
107
        return new self(array_merge($this->paths, [$path]), $this->names);
108
    }
109
    
110
    /**
111
     * Creates a file store with the given name added.
112
     * 
113
     * @param  string  $name
114
     * 
115
     * @return \Syscodes\Dotenv\Store\StoreBuilder
116
     */
117
    public function addName(string $name)
118
    {
119
        return new self($this->paths, array_merge($this->names, [$name]));
120
    }
121
122
    /**
123
     * Creates a store builder with mode enabled break.
124
     * 
125
     * @return \Syscodes\Dotenv\Store\StoreBuilder
126
     */
127
    public function modeEnabled()
128
    {
129
        return new self($this->paths, $this->names, true);
130
    }
131
    
132
    /**
133
     * Creates a new store instance.
134
     * 
135
     * @return \Syscodes\Dotenv\Store\FileStore
136
     */
137
    public function make()
138
    {
139
        return new FileStore(
140
            Paths::getFilePath($this->paths, $this->names),
141
            $this->modeEnabled
142
        );
143
    }
144
}