|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Gacela\Framework\Config\GacelaFileConfig; |
|
6
|
|
|
|
|
7
|
|
|
use Gacela\Framework\Config\ConfigReader\PhpConfigReader; |
|
8
|
|
|
use Gacela\Framework\Config\ConfigReaderInterface; |
|
9
|
|
|
use function get_class; |
|
10
|
|
|
|
|
11
|
|
|
final class GacelaConfigItem |
|
12
|
|
|
{ |
|
13
|
|
|
private const DEFAULT_PATH = 'config/*.php'; |
|
14
|
|
|
private const DEFAULT_PATH_LOCAL = 'config/local.php'; |
|
15
|
|
|
|
|
16
|
|
|
private string $path; |
|
17
|
|
|
private string $pathLocal; |
|
18
|
|
|
private ConfigReaderInterface $reader; |
|
19
|
|
|
|
|
20
|
29 |
|
public function __construct( |
|
21
|
|
|
string $path = self::DEFAULT_PATH, |
|
22
|
|
|
string $pathLocal = self::DEFAULT_PATH_LOCAL, |
|
23
|
|
|
?ConfigReaderInterface $reader = null |
|
24
|
|
|
) { |
|
25
|
29 |
|
$this->path = $path; |
|
26
|
29 |
|
$this->pathLocal = $pathLocal; |
|
27
|
29 |
|
$this->reader = $reader ?? new PhpConfigReader(); |
|
28
|
29 |
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param array{path?:string, path_local?:string, reader?:ConfigReaderInterface} $item |
|
32
|
|
|
*/ |
|
33
|
27 |
|
public static function fromArray(array $item): self |
|
34
|
|
|
{ |
|
35
|
27 |
|
return new self( |
|
36
|
27 |
|
$item['path'] ?? self::DEFAULT_PATH, |
|
37
|
27 |
|
$item['path_local'] ?? self::DEFAULT_PATH_LOCAL, |
|
38
|
27 |
|
$item['reader'] ?? new PhpConfigReader(), |
|
39
|
|
|
); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
27 |
|
public static function withDefaults(): self |
|
43
|
|
|
{ |
|
44
|
27 |
|
return self::fromArray([]); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
24 |
|
public function path(): string |
|
48
|
|
|
{ |
|
49
|
24 |
|
return $this->path; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
24 |
|
public function pathLocal(): string |
|
53
|
|
|
{ |
|
54
|
24 |
|
return $this->pathLocal; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
29 |
|
public function reader(): ConfigReaderInterface |
|
58
|
|
|
{ |
|
59
|
29 |
|
return $this->reader; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function __toString(): string |
|
63
|
|
|
{ |
|
64
|
|
|
return sprintf( |
|
65
|
|
|
'GacelaConfigItem{path:%s, pathLocal:%s, reader:%s}', |
|
66
|
|
|
$this->path, |
|
67
|
|
|
$this->pathLocal, |
|
68
|
|
|
get_class($this->reader) |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|