|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace NamespaceProtector\Config; |
|
4
|
|
|
|
|
5
|
|
|
use NamespaceProtector\Common\PathInterface; |
|
6
|
|
|
use NamespaceProtector\Common\FileSystemPath; |
|
7
|
|
|
|
|
8
|
|
|
final class ConfigMaker extends AbstractConfigMaker |
|
9
|
|
|
{ |
|
10
|
|
|
public function createFromFile(PathInterface $path): Config |
|
11
|
|
|
{ |
|
12
|
|
|
$content = \safe\file_get_contents($path->get()); |
|
13
|
|
|
$arrayConfig = \safe\json_decode($content, true); |
|
14
|
|
|
|
|
15
|
|
|
$self = new Config( |
|
16
|
|
|
$arrayConfig['version'], |
|
17
|
|
|
new FileSystemPath($arrayConfig['start-path'] ?? '.'), |
|
18
|
|
|
new FileSystemPath($arrayConfig['composer-json-path'] ?? '.'), |
|
19
|
|
|
$arrayConfig['private-entries'] ?? [], |
|
20
|
|
|
$arrayConfig['public-entries'] ?? [], |
|
21
|
|
|
$arrayConfig['mode'] ?? Config::MODE_PUBLIC, |
|
22
|
|
|
$arrayConfig['cache'] ?? false, |
|
23
|
|
|
$arrayConfig['plotter'] ?? Config::PLOTTER_TERMINAL, |
|
24
|
|
|
); |
|
25
|
|
|
|
|
26
|
|
|
$self->validateLoadedConfig(); |
|
27
|
|
|
return $self; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** @param array<string,string> $parameters */ |
|
31
|
|
|
public function createFromItSelf(Config $config, array $parameters): Config |
|
32
|
|
|
{ |
|
33
|
|
|
$self = new Config( |
|
34
|
|
|
$config->getVersion(), |
|
35
|
|
|
$config->getStartPath(), |
|
36
|
|
|
$config->getPathComposerJson(), |
|
37
|
|
|
$config->getPrivateEntries(), |
|
38
|
|
|
$config->getPublicEntries(), |
|
39
|
|
|
$config->getMode(), |
|
40
|
|
|
$config->enabledCache(), |
|
41
|
|
|
$parameters['plotter'] ?? $config->getPlotter(), |
|
42
|
|
|
); |
|
43
|
|
|
|
|
44
|
|
|
$self->validateLoadedConfig(); |
|
45
|
|
|
|
|
46
|
|
|
return $self; |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|