|
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\Repository; |
|
24
|
|
|
|
|
25
|
|
|
use Syscodes\Contracts\Dotenv\Adapter; |
|
26
|
|
|
use Syscodes\Dotenv\Repository\Adapters\ArrayAdapter; |
|
27
|
|
|
use Syscodes\Dotenv\Repository\Adapters\ApacheAdapter; |
|
28
|
|
|
use Syscodes\Dotenv\Repository\Adapters\PutenvAdapter; |
|
29
|
|
|
use Syscodes\Dotenv\Repository\Adapters\ServerAdapter; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Allows you to bring all the adapters. |
|
33
|
|
|
* |
|
34
|
|
|
* @author Alexander Campo <[email protected]> |
|
35
|
|
|
*/ |
|
36
|
|
|
final class RepositoryCreator |
|
37
|
|
|
{ |
|
38
|
|
|
protected const ADAPTERS_DEFAULT = [ |
|
39
|
|
|
ApacheAdapter::class, |
|
40
|
|
|
ArrayAdapter::class, |
|
41
|
|
|
PutenvAdapter::class, |
|
42
|
|
|
ServerAdapter::class, |
|
43
|
|
|
]; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Gets adapters allow list to use. |
|
47
|
|
|
* |
|
48
|
|
|
* @var string[] $allowlist |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $allowlist; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Constructor. Create a new Repository creator instance. |
|
54
|
|
|
* |
|
55
|
|
|
* @param \Syscodes\Contracts\Dotenv\Adapter[] $adapter |
|
56
|
|
|
* |
|
57
|
|
|
* @return void |
|
58
|
|
|
*/ |
|
59
|
|
|
public function __construct(array $adapter = []) |
|
60
|
|
|
{ |
|
61
|
|
|
$this->allowList = $adapter; |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Create a new repository creator instance with the default adapters added. |
|
66
|
|
|
* |
|
67
|
|
|
* @return \Syscodes\Dotenv\Repository\RepositoryCreator |
|
68
|
|
|
*/ |
|
69
|
|
|
public function createDefaultAdapters() |
|
70
|
|
|
{ |
|
71
|
|
|
$adapters = iterator_to_array(self::defaultAdapters()); |
|
72
|
|
|
|
|
73
|
|
|
return new static($adapters); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Return the array of default adapters. |
|
78
|
|
|
* |
|
79
|
|
|
* @return \Syscodes\Contracts\Dotenv\Adapter |
|
80
|
|
|
*/ |
|
81
|
|
|
protected static function defaultAdapters() |
|
82
|
|
|
{ |
|
83
|
|
|
foreach (self::ADAPTERS_DEFAULT as $adapter) { |
|
84
|
|
|
yield new $adapter; |
|
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Creates a new repository instance. |
|
90
|
|
|
* |
|
91
|
|
|
* @return \Syscodes\Contracts\Dotenv\Repository |
|
92
|
|
|
*/ |
|
93
|
|
|
public function make() |
|
94
|
|
|
{ |
|
95
|
|
|
return new AdapterRepository($this->allowlist); |
|
|
|
|
|
|
96
|
|
|
} |
|
97
|
|
|
} |