|
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 InvalidaArgumentException; |
|
|
|
|
|
|
26
|
|
|
use Syscodes\Contracts\Dotenv\Adapter; |
|
27
|
|
|
use Syscodes\Dotenv\Repository\Adapters\Readers; |
|
28
|
|
|
use Syscodes\Dotenv\Repository\Adapters\Writers; |
|
29
|
|
|
use Syscodes\Dotenv\Repository\Adapters\EnvAdapter; |
|
30
|
|
|
use Syscodes\Dotenv\Repository\Adapters\ServerAdapter; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Allows you to bring all the adapters. |
|
34
|
|
|
* |
|
35
|
|
|
* @author Alexander Campo <[email protected]> |
|
36
|
|
|
*/ |
|
37
|
|
|
final class RepositoryCreator |
|
38
|
|
|
{ |
|
39
|
|
|
protected const ADAPTERS_DEFAULT = [ |
|
40
|
|
|
EnvAdapter::class, |
|
41
|
|
|
ServerAdapter::class, |
|
42
|
|
|
]; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Gets adapters allow list to use. |
|
46
|
|
|
* |
|
47
|
|
|
* @var string[] $allowlist |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $allowlist; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* The set of readers to use. |
|
53
|
|
|
* |
|
54
|
|
|
* @var \Syscodes\Dotenv\Repository\Adapters\Readers $readers |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $readers; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* The set of writers to use. |
|
60
|
|
|
* |
|
61
|
|
|
* @var \Syscodes\Dotenv\Repository\Adapters\Writers $writers |
|
62
|
|
|
*/ |
|
63
|
|
|
protected $writers; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Constructor. Create a new Repository creator instance. |
|
67
|
|
|
* |
|
68
|
|
|
* @param \Syscodes\Dotenv\Repository\Adapters\Readers $readers |
|
69
|
|
|
* @param \Syscodes\Dotenv\Repository\Adapters\Writers $writers |
|
70
|
|
|
* @param string[]|null $allowList |
|
71
|
|
|
* |
|
72
|
|
|
* @return void |
|
73
|
|
|
*/ |
|
74
|
|
|
public function __construct(array $readers = [], array $writers = [], array $allowList = null) |
|
75
|
|
|
{ |
|
76
|
|
|
$this->readers = $readers; |
|
|
|
|
|
|
77
|
|
|
$this->writers = $writers; |
|
|
|
|
|
|
78
|
|
|
$this->allowList = $allowList; |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Create a new repository creator instance with the default adapters added. |
|
83
|
|
|
* |
|
84
|
|
|
* @return \Syscodes\Dotenv\Repository\RepositoryCreator |
|
85
|
|
|
*/ |
|
86
|
|
|
public static function createDefaultAdapters() |
|
87
|
|
|
{ |
|
88
|
|
|
$adapters = iterator_to_array(self::defaultAdapters()); |
|
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
return new static($adapters, $adapters); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Return the array of default adapters. |
|
95
|
|
|
* |
|
96
|
|
|
* @return \Syscodes\Contracts\Dotenv\Adapter |
|
97
|
|
|
*/ |
|
98
|
|
|
protected static function defaultAdapters() |
|
99
|
|
|
{ |
|
100
|
|
|
foreach (self::ADAPTERS_DEFAULT as $adapter) { |
|
101
|
|
|
return new $adapter; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Determine if the given name if of an adapter class. |
|
107
|
|
|
* |
|
108
|
|
|
* @param string $name |
|
109
|
|
|
* |
|
110
|
|
|
* @return bool |
|
111
|
|
|
*/ |
|
112
|
|
|
protected static function inAdapterClass(string $name) |
|
113
|
|
|
{ |
|
114
|
|
|
if ( ! class_exists($name)) |
|
115
|
|
|
{ |
|
116
|
|
|
return false; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
return (new ReflectionClass($name))->implementsInterface(Adapter::class); |
|
|
|
|
|
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Creates a repository builder with the given reader added. |
|
124
|
|
|
* |
|
125
|
|
|
* @param string $adapter |
|
126
|
|
|
* |
|
127
|
|
|
* @return new static |
|
|
|
|
|
|
128
|
|
|
* |
|
129
|
|
|
* @return \InvalidArgumentException |
|
130
|
|
|
*/ |
|
131
|
|
|
public function addAdapter(string $adapter) |
|
132
|
|
|
{ |
|
133
|
|
|
if ( ! is_string($adapter) && ! ($adapter instanceof Adapter)) { |
|
|
|
|
|
|
134
|
|
|
throw new InvalidaArgumentException("Expected either an instance of [{$this->allowList}]"); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
$readers = array_merge($this->readers, [$adapter]); |
|
|
|
|
|
|
138
|
|
|
$writers = array_merge($this->writers, [$adapter]); |
|
|
|
|
|
|
139
|
|
|
|
|
140
|
|
|
return new static($readers, $writers, $this->allowList); |
|
|
|
|
|
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Creates a new repository instance. |
|
145
|
|
|
* |
|
146
|
|
|
* @return \Syscodes\Dotenv\Repository\AdapterRepository |
|
147
|
|
|
*/ |
|
148
|
|
|
public function make() |
|
149
|
|
|
{ |
|
150
|
|
|
$readers = new Readers($this->readers); |
|
|
|
|
|
|
151
|
|
|
$writers = new Writers($this->writers); |
|
|
|
|
|
|
152
|
|
|
|
|
153
|
|
|
return new AdapterRepository($readers, $writers); |
|
154
|
|
|
} |
|
155
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths