|
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 InvalidArgumentException; |
|
26
|
|
|
use Syscodes\Dotenv\Store\Contributors\Reader; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Reads the content of the environments files. |
|
30
|
|
|
* |
|
31
|
|
|
* @author Alexander Campo <[email protected]> |
|
32
|
|
|
*/ |
|
33
|
|
|
final class FileStore |
|
34
|
|
|
{ |
|
35
|
|
|
/** |
|
36
|
|
|
* The file paths. |
|
37
|
|
|
* |
|
38
|
|
|
* @var string[] $filePaths |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $filePaths; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Should file loading in enabled mode? |
|
44
|
|
|
* |
|
45
|
|
|
* @var bool $modeEnabled |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $modeEnabled; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Constructor. Create a new FileStore instance. |
|
51
|
|
|
* |
|
52
|
|
|
* @param string[] $filePaths |
|
53
|
|
|
* @param bool $modeEnabled |
|
54
|
|
|
* |
|
55
|
|
|
* @return void |
|
56
|
|
|
*/ |
|
57
|
|
|
public function __construct(array $filePaths, bool $modeEnabled) |
|
58
|
|
|
{ |
|
59
|
|
|
$this->filePaths = $filePaths; |
|
60
|
|
|
$this->modeEnabled = $modeEnabled; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Read the content of the environment file(s). |
|
65
|
|
|
* |
|
66
|
|
|
* @return array |
|
67
|
|
|
*/ |
|
68
|
|
|
public function read() |
|
69
|
|
|
{ |
|
70
|
|
|
if ($this->filePaths === []) { |
|
71
|
|
|
throw new InvalidArgumentException('At least one environment file path must be provided'); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$contents = Reader::read($this->filePaths, $this->modeEnabled); |
|
75
|
|
|
|
|
76
|
|
|
return $contents; |
|
77
|
|
|
} |
|
78
|
|
|
} |