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