|
1
|
|
|
<?php |
|
2
|
|
|
namespace Yoanm\ComposerConfigManager\Application; |
|
3
|
|
|
|
|
4
|
|
|
use Yoanm\ComposerConfigManager\Application\Updater\ConfigurationUpdater; |
|
5
|
|
|
use Yoanm\ComposerConfigManager\Application\Writer\ConfigurationWriterInterface; |
|
6
|
|
|
use Yoanm\ComposerConfigManager\Domain\Model\Configuration; |
|
7
|
|
|
|
|
8
|
|
|
class CreateConfiguration |
|
9
|
|
|
{ |
|
10
|
|
|
/** @var ConfigurationWriterInterface */ |
|
11
|
|
|
private $configurationWriter; |
|
12
|
|
|
/** @var ConfigurationUpdater */ |
|
13
|
|
|
private $configurationUpdater; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @param ConfigurationWriterInterface $configurationWriter |
|
17
|
|
|
* @param ConfigurationUpdater $configurationUpdater |
|
18
|
|
|
*/ |
|
19
|
2 |
|
public function __construct( |
|
20
|
|
|
ConfigurationWriterInterface $configurationWriter, |
|
21
|
|
|
ConfigurationUpdater $configurationUpdater |
|
22
|
|
|
) { |
|
23
|
2 |
|
$this->configurationWriter = $configurationWriter; |
|
24
|
2 |
|
$this->configurationUpdater = $configurationUpdater; |
|
25
|
2 |
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param CreateConfigurationRequest $request |
|
29
|
|
|
*/ |
|
30
|
2 |
|
public function run(CreateConfigurationRequest $request) |
|
31
|
|
|
{ |
|
32
|
2 |
|
$this->configurationWriter->write( |
|
33
|
2 |
|
$this->getConfiguration($request), |
|
34
|
2 |
|
$request->getDestinationFolder() |
|
35
|
2 |
|
); |
|
36
|
2 |
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param CreateConfigurationRequest $request |
|
40
|
|
|
* |
|
41
|
|
|
* @return Configuration |
|
42
|
|
|
*/ |
|
43
|
2 |
|
protected function getConfiguration(CreateConfigurationRequest $request) |
|
44
|
|
|
{ |
|
45
|
2 |
|
$configuration = $request->getConfiguration(); |
|
46
|
|
|
|
|
47
|
2 |
|
if ($request->getTemplateConfiguration() instanceof Configuration) { |
|
48
|
1 |
|
$configuration = $this->configurationUpdater->update( |
|
49
|
1 |
|
$request->getTemplateConfiguration(), |
|
50
|
|
|
$configuration |
|
51
|
1 |
|
); |
|
52
|
1 |
|
} |
|
53
|
|
|
|
|
54
|
2 |
|
return $configuration; |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|