1
|
|
|
<?php |
2
|
|
|
namespace Samurai\Project\Task; |
3
|
|
|
|
4
|
|
|
use Samurai\Project\Composer\ComposerConfigMerger; |
5
|
|
|
use Samurai\Task\ITask; |
6
|
|
|
use Samurai\Task\Task; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class ComposerConfigSetting |
12
|
|
|
* @package Samurai\Project\Task |
13
|
|
|
* @author Raphaël Lefebvre <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class ComposerConfigSetting extends Task |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @param InputInterface $input |
19
|
|
|
* @param OutputInterface $output |
20
|
|
|
* @return bool |
21
|
|
|
*/ |
22
|
4 |
|
public function execute(InputInterface $input, OutputInterface $output) |
23
|
|
|
{ |
24
|
4 |
|
$output->writeln('<info>Initializing composer config</info>'); |
25
|
|
|
|
26
|
4 |
|
$this->resetConfig(); |
27
|
|
|
|
28
|
4 |
|
$hasError = false; |
29
|
4 |
View Code Duplication |
if($this->getService('composer')->validateConfig($this->getService('project')->getDirectoryPath())) { |
30
|
1 |
|
$output->writeln('<error>Error: Composer config is not valid</error>'); |
31
|
1 |
|
$hasError = true; |
32
|
1 |
|
} |
33
|
4 |
View Code Duplication |
if($this->getService('composer')->dumpAutoload($this->getService('project')->getDirectoryPath())) { |
34
|
1 |
|
$output->writeln('<error>Error: autoload is not up-to-date. Process to "composer dump-autoload".</error>'); |
35
|
1 |
|
$hasError = true; |
36
|
4 |
|
} |
37
|
|
|
|
38
|
4 |
|
return $hasError ? ITask::NO_ERROR_CODE : ITask::NON_BLOCKING_ERROR_CODE; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* |
43
|
|
|
*/ |
44
|
4 |
|
public function resetConfig() |
45
|
|
|
{ |
46
|
4 |
|
$merger = new ComposerConfigMerger(); |
47
|
4 |
|
$this->getService('composer')->setConfig( |
48
|
4 |
|
$merger->merge($this->retrieveCurrentConfig(), $this->getService('project')->toConfig()), |
49
|
4 |
|
$this->getService('project')->getDirectoryPath() |
50
|
4 |
|
); |
51
|
4 |
|
$this->getService('composer')->flushConfig($this->getService('project')->getDirectoryPath()); |
52
|
4 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
4 |
|
public function retrieveCurrentConfig() |
58
|
|
|
{ |
59
|
4 |
|
return $this->getService('composer')->getConfig($this->getService('project')->getDirectoryPath()); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|