|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
|
4
|
|
|
|
|
5
|
|
|
namespace PhpTaskman\Core; |
|
6
|
|
|
|
|
7
|
|
|
use Composer\Autoload\ClassLoader; |
|
8
|
|
|
use Consolidation\Config\Loader\ConfigProcessor; |
|
9
|
|
|
use League\Container\Container; |
|
10
|
|
|
use League\Container\ContainerInterface; |
|
11
|
|
|
use PhpTaskman\Core\Config\Loader\JsonConfigLoader; |
|
12
|
|
|
use PhpTaskman\Core\Services\Composer; |
|
|
|
|
|
|
13
|
|
|
use Robo\Application; |
|
14
|
|
|
use Robo\Config\Config; |
|
15
|
|
|
use Robo\Robo; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
17
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class Taskman. |
|
22
|
|
|
*/ |
|
23
|
|
|
final class Taskman |
|
24
|
|
|
{ |
|
25
|
|
|
public const APPLICATION_NAME = 'Taskman'; |
|
26
|
|
|
public const VERSION = 'dev-master'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Create default configuration. |
|
30
|
|
|
* |
|
31
|
|
|
* @param null|mixed $workingDir |
|
32
|
|
|
* @param mixed $paths |
|
33
|
|
|
* |
|
34
|
|
|
* @return Config |
|
35
|
|
|
*/ |
|
36
|
3 |
|
public static function createConfiguration($paths, $workingDir = null) |
|
37
|
|
|
{ |
|
38
|
3 |
|
$workingDir = $workingDir ?? \getcwd(); |
|
39
|
|
|
|
|
40
|
|
|
// Create a default configuration. |
|
41
|
3 |
|
$config = Robo::createConfiguration($paths); |
|
42
|
|
|
|
|
43
|
|
|
// Set the variable working_dir. |
|
44
|
3 |
|
if (false === $workingDir = \realpath($workingDir)) { |
|
45
|
1 |
|
return $config; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
3 |
|
$config->set('taskman.working_dir', \realpath($workingDir)); |
|
49
|
|
|
|
|
50
|
|
|
// Load the configuration. |
|
51
|
3 |
|
Robo::loadConfiguration( |
|
52
|
3 |
|
\PhpTaskman\Core\Config\Config::findFilesToIncludeInConfiguration($workingDir), |
|
53
|
3 |
|
$config |
|
54
|
|
|
); |
|
55
|
|
|
|
|
56
|
3 |
|
return $config; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Create and configure container. |
|
61
|
|
|
* |
|
62
|
|
|
* @param InputInterface $input |
|
63
|
|
|
* @param OutputInterface $output |
|
64
|
|
|
* @param Application $application |
|
65
|
|
|
* @param Config $config |
|
66
|
|
|
* @param ClassLoader $classLoader |
|
67
|
|
|
* |
|
68
|
|
|
* @return Container|\League\Container\ContainerInterface |
|
69
|
|
|
*/ |
|
70
|
2 |
|
public static function createContainer( |
|
71
|
|
|
InputInterface $input, |
|
72
|
|
|
OutputInterface $output, |
|
73
|
|
|
Application $application, |
|
74
|
|
|
Config $config, |
|
75
|
|
|
ClassLoader $classLoader |
|
76
|
|
|
) { |
|
77
|
2 |
|
$container = Robo::createDefaultContainer($input, $output, $application, $config, $classLoader); |
|
78
|
2 |
|
$container->get('commandFactory')->setIncludeAllPublicMethods(false); |
|
79
|
|
|
|
|
80
|
2 |
|
return $container; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @param null|string $appName |
|
85
|
|
|
* @param null|string $appVersion |
|
86
|
|
|
* @param null|string $workingDir |
|
87
|
|
|
* |
|
88
|
|
|
* @return Application |
|
89
|
|
|
*/ |
|
90
|
2 |
|
public static function createDefaultApplication($appName = null, $appVersion = null, $workingDir = null) |
|
91
|
|
|
{ |
|
92
|
2 |
|
$workingDir = $workingDir ?? \getcwd(); |
|
93
|
2 |
|
$appName = $appName ?? self::APPLICATION_NAME; |
|
94
|
2 |
|
$appVersion = $appVersion ?? self::VERSION; |
|
95
|
|
|
|
|
96
|
2 |
|
$app = Robo::createDefaultApplication($appName, $appVersion); |
|
97
|
|
|
|
|
98
|
|
|
$app |
|
99
|
2 |
|
->getDefinition() |
|
100
|
2 |
|
->addOption( |
|
101
|
2 |
|
new InputOption( |
|
102
|
2 |
|
'--working-dir', |
|
103
|
2 |
|
null, |
|
104
|
2 |
|
InputOption::VALUE_REQUIRED, |
|
105
|
2 |
|
'Working directory, defaults to current working directory.', |
|
106
|
2 |
|
\realpath($workingDir) |
|
107
|
|
|
) |
|
108
|
|
|
); |
|
109
|
|
|
|
|
110
|
2 |
|
$app->setAutoExit(false); |
|
111
|
|
|
|
|
112
|
2 |
|
return $app; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @param ContainerInterface $container |
|
117
|
|
|
* |
|
118
|
|
|
* @return \Robo\Runner |
|
119
|
|
|
*/ |
|
120
|
1 |
|
public static function createDefaultRunner(ContainerInterface $container) |
|
121
|
|
|
{ |
|
122
|
1 |
|
return (new \Robo\Runner()) |
|
123
|
1 |
|
->setRelativePluginNamespace('Robo\Plugin') |
|
124
|
1 |
|
->setContainer($container); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @param $paths |
|
129
|
|
|
* |
|
130
|
|
|
* @return \Robo\Config\Config |
|
131
|
|
|
*/ |
|
132
|
3 |
|
public static function createJsonConfiguration($paths) |
|
133
|
|
|
{ |
|
134
|
3 |
|
$config = new Config(); |
|
135
|
3 |
|
self::loadJsonConfiguration($paths, $config); |
|
136
|
|
|
|
|
137
|
3 |
|
return $config; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @param string $path |
|
142
|
|
|
* The directory |
|
143
|
|
|
* |
|
144
|
|
|
* @return \Robo\Config\Config |
|
145
|
|
|
* The composer object. |
|
146
|
|
|
*/ |
|
147
|
3 |
|
public static function getComposerFromDirectory($path): ?Config |
|
148
|
|
|
{ |
|
149
|
3 |
|
$composerFile = \realpath($path . '/composer.json'); |
|
150
|
|
|
|
|
151
|
3 |
|
if (false === $composerFile) { |
|
152
|
|
|
return null; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
3 |
|
return self::getConfigFromArray( |
|
156
|
3 |
|
\json_decode( |
|
157
|
3 |
|
\file_get_contents($composerFile), |
|
158
|
3 |
|
true |
|
159
|
|
|
) |
|
160
|
|
|
); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @param array $data |
|
165
|
|
|
* |
|
166
|
|
|
* @return \Robo\Config\Config |
|
167
|
|
|
* The composer object. |
|
168
|
|
|
*/ |
|
169
|
3 |
|
public static function getConfigFromArray(array $data): Config |
|
170
|
|
|
{ |
|
171
|
3 |
|
return new Config($data); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* @param $paths |
|
176
|
|
|
* @param null $config |
|
|
|
|
|
|
177
|
|
|
*/ |
|
178
|
3 |
|
public static function loadJsonConfiguration($paths, $config = null) |
|
179
|
|
|
{ |
|
180
|
3 |
|
if (null === $config) { |
|
|
|
|
|
|
181
|
|
|
$config = Robo::config(); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
3 |
|
$loader = new JsonConfigLoader(); |
|
185
|
3 |
|
$processor = new ConfigProcessor(); |
|
186
|
3 |
|
$processor->add($config->export()); |
|
187
|
|
|
|
|
188
|
3 |
|
foreach ($paths as $path) { |
|
189
|
3 |
|
$processor->extend($loader->load($path)); |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
3 |
|
$config->import($processor->export()); |
|
|
|
|
|
|
193
|
3 |
|
} |
|
194
|
|
|
} |
|
195
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths