1
|
|
|
<?php declare(strict_types = 1); |
2
|
|
|
|
3
|
|
|
namespace ApiClients\Tools\Installer\Operation; |
4
|
|
|
|
5
|
|
|
use ApiClients\Tools\Installer\Filesystem; |
6
|
|
|
use ApiClients\Tools\Installer\OperationInterface; |
7
|
|
|
use Composer\Factory; |
8
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
9
|
|
|
use Symfony\Component\Yaml\Yaml; |
10
|
|
|
|
11
|
|
|
final class ResourcesYml implements OperationInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var Filesystem |
15
|
|
|
*/ |
16
|
|
|
private $filesystem; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @internal |
20
|
|
|
* @param Filesystem $filesystem |
21
|
|
|
*/ |
22
|
|
|
public function __construct(Filesystem $filesystem) |
23
|
|
|
{ |
24
|
|
|
$this->filesystem = $filesystem; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @return OperationInterface |
29
|
|
|
*/ |
30
|
|
|
public static function create(): OperationInterface |
31
|
|
|
{ |
32
|
|
|
return new self(new Filesystem()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param array $replacements |
37
|
|
|
* @param array $environment |
38
|
|
|
* @param SymfonyStyle $style |
39
|
|
|
*/ |
40
|
|
|
public function operate(array $replacements, array $environment, SymfonyStyle $style) |
41
|
|
|
{ |
42
|
|
|
$path = str_replace( |
43
|
|
|
'composer.json', |
44
|
|
|
'resources.yml', |
45
|
|
|
Factory::getComposerFile() |
46
|
|
|
); |
47
|
|
|
$style->section('Updating resources.yml'); |
48
|
|
|
$style->text('Reading resources.yml'); |
49
|
|
|
$resourcesYml = Yaml::parse($this->filesystem->read($path)); |
50
|
|
|
|
51
|
|
|
$style->text('Replacing api_settings'); |
52
|
|
|
$resourcesYml['api_settings'] = $replacements['ns_vendor'] . '\\' . $replacements['ns_project'] . '\\ApiSettings'; |
53
|
|
|
|
54
|
|
|
$style->text('Replacing src.namespace'); |
55
|
|
|
$resourcesYml['src']['namespace'] = $replacements['ns_vendor'] . '\\' . $replacements['ns_project'] . '\\Resource'; |
56
|
|
|
|
57
|
|
|
$style->text('Replacing tests.namespace'); |
58
|
|
|
$resourcesYml['tests']['namespace'] = $replacements['ns_tests_vendor'] . '\\' . $replacements['ns_project'] . '\\Resource'; |
59
|
|
|
|
60
|
|
|
$style->text('Writing updated resources.yml'); |
61
|
|
|
$this->filesystem->write($path, Yaml::dump($resourcesYml)); |
62
|
|
|
$style->success('Updated resources.yml'); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|