|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PhpUnitGen\Configuration; |
|
4
|
|
|
|
|
5
|
|
|
use PhpUnitGen\Configuration\ConfigurationInterface\ConsoleConfigInterface; |
|
6
|
|
|
use PhpUnitGen\Exception\InvalidConfigException; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class AbstractConsoleConfigFactory. |
|
10
|
|
|
* |
|
11
|
|
|
* @author Paul Thébaud <[email protected]>. |
|
12
|
|
|
* @copyright 2017-2018 Paul Thébaud <[email protected]>. |
|
13
|
|
|
* @license https://opensource.org/licenses/MIT The MIT license. |
|
14
|
|
|
* @link https://github.com/paul-thebaud/phpunit-generator |
|
15
|
|
|
* @since Class available since Release 2.0.0. |
|
16
|
|
|
*/ |
|
17
|
|
|
abstract class AbstractConsoleConfigFactory |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* {@inheritdoc} |
|
21
|
|
|
*/ |
|
22
|
|
|
public function invoke(string $configPath): ConsoleConfigInterface |
|
23
|
|
|
{ |
|
24
|
|
|
return new ConsoleConfig($this->decode($configPath)); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* {@inheritdoc} |
|
29
|
|
|
*/ |
|
30
|
|
|
public function invokeDir(string $configPath, string $sourceDir, string $targetDir): ConsoleConfigInterface |
|
31
|
|
|
{ |
|
32
|
|
|
$configArray = $this->decode($configPath); |
|
33
|
|
|
$configArray['dirs'] = [ |
|
34
|
|
|
$sourceDir => $targetDir |
|
35
|
|
|
]; |
|
36
|
|
|
$configArray['files'] = []; |
|
37
|
|
|
|
|
38
|
|
|
return new ConsoleConfig($configArray); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* {@inheritdoc} |
|
43
|
|
|
*/ |
|
44
|
|
|
public function invokeFile(string $configPath, string $sourceFile, string $targetFile): ConsoleConfigInterface |
|
45
|
|
|
{ |
|
46
|
|
|
$configArray = $this->decode($configPath); |
|
47
|
|
|
$configArray['dirs'] = []; |
|
48
|
|
|
$configArray['files'] = [ |
|
49
|
|
|
$sourceFile => $targetFile |
|
50
|
|
|
]; |
|
51
|
|
|
|
|
52
|
|
|
return new ConsoleConfig($configArray); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Decode a configuration file to get a configuration array. |
|
57
|
|
|
* |
|
58
|
|
|
* @param string $configPath The configuration file path. |
|
59
|
|
|
* |
|
60
|
|
|
* @return array The decoded configuration array. |
|
61
|
|
|
* |
|
62
|
|
|
* @throws InvalidConfigException If the configuration is invalid. |
|
63
|
|
|
*/ |
|
64
|
|
|
abstract protected function decode(string $configPath): array; |
|
65
|
|
|
} |
|
66
|
|
|
|