1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
namespace PhpTaskman\Core\Robo\Plugin\Commands; |
6
|
|
|
|
7
|
|
|
use Consolidation\Config\Loader\ConfigProcessor; |
8
|
|
|
use PhpTaskman\Core\Contract\ComposerAwareInterface; |
9
|
|
|
use PhpTaskman\Core\Taskman; |
10
|
|
|
use PhpTaskman\Core\Traits\ComposerAwareTrait; |
11
|
|
|
use Robo\Common\ConfigAwareTrait; |
12
|
|
|
use Robo\Common\IO; |
13
|
|
|
use Robo\Contract\ConfigAwareInterface; |
14
|
|
|
use Robo\Contract\IOAwareInterface; |
15
|
|
|
use Robo\Contract\BuilderAwareInterface; |
16
|
|
|
use Robo\LoadAllTasks; |
17
|
|
|
use Robo\Robo; |
18
|
|
|
use Symfony\Component\Console\Event\ConsoleCommandEvent; |
19
|
|
|
use Symfony\Component\EventDispatcher\Event; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class AbstractCommands. |
23
|
|
|
*/ |
24
|
|
|
abstract class AbstractCommands implements |
25
|
|
|
BuilderAwareInterface, |
26
|
|
|
IOAwareInterface, |
27
|
|
|
ConfigAwareInterface, |
28
|
|
|
ComposerAwareInterface |
29
|
|
|
{ |
30
|
|
|
use ComposerAwareTrait; |
31
|
|
|
use ConfigAwareTrait; |
32
|
|
|
use IO; |
33
|
|
|
use LoadAllTasks; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Path to YAML configuration file containing command defaults. |
37
|
|
|
* |
38
|
|
|
* Command classes should implement this method. |
39
|
|
|
* |
40
|
|
|
* @return string |
41
|
|
|
*/ |
42
|
|
|
abstract public function getConfigurationFile(): string; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Path to YAML configuration file containing command defaults. |
46
|
|
|
* |
47
|
|
|
* Command classes should implement this method. |
48
|
|
|
* |
49
|
|
|
* @return string |
50
|
|
|
* The path of the default configuration file. |
51
|
|
|
*/ |
52
|
|
|
abstract public function getDefaultConfigurationFile(): string; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Load default configuration. |
56
|
|
|
* |
57
|
|
|
* PHP Tasks does not allow to provide default configuration for |
58
|
|
|
* commands. In this hook we load Toolkit default configuration and re-apply |
59
|
|
|
* it back. |
60
|
|
|
* |
61
|
|
|
* @hook pre-command-event * |
62
|
|
|
*/ |
63
|
|
|
public function loadDefaultConfig(ConsoleCommandEvent $event) |
|
|
|
|
64
|
|
|
{ |
65
|
|
|
// Get Tasks configuration. |
66
|
|
|
$config = $this->getConfig(); |
67
|
|
|
|
68
|
|
|
if (null === $config->get('taskman.bin_dir')) { |
69
|
|
|
if (null !== $composer = $this->getComposer()) { |
70
|
|
|
// The COMPOSER_BIN_DIR environment takes precedence over the value |
71
|
|
|
// defined in composer.json config, if any. Default to ./vendor/bin. |
72
|
|
|
if (!$composerBinDir = \getenv('COMPOSER_BIN_DIR')) { |
73
|
|
|
if (!$composerBinDir = $composer->getConfig('bin-dir')) { |
74
|
|
|
$composerBinDir = './vendor/bin'; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
if (false === \strpos($composerBinDir, './')) { |
79
|
|
|
$composerBinDir = './' . $composerBinDir; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$composerBinDir = \rtrim($composerBinDir, \DIRECTORY_SEPARATOR); |
83
|
|
|
$config->set('taskman.bin_dir', $composerBinDir); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
// Refactor this. |
88
|
|
|
$configurationFilePath = \realpath($this->getConfigurationFile()); |
89
|
|
|
|
90
|
|
|
Robo::loadConfiguration([$configurationFilePath], $config); |
91
|
|
|
|
92
|
|
|
$default_config = Taskman::createConfiguration( |
93
|
|
|
[$this->getDefaultConfigurationFile()] |
94
|
|
|
); |
95
|
|
|
|
96
|
|
|
// Re-build configuration. |
97
|
|
|
$processor = new ConfigProcessor(); |
98
|
|
|
$processor->add($default_config->export()); |
99
|
|
|
$processor->add($config->export()); |
100
|
|
|
|
101
|
|
|
// Import newly built configuration. |
102
|
|
|
$config->import($processor->export()); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.