1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the phpspec-console package. |
4
|
|
|
* (c) 2017 Timo Michna <timomichna/yahoo.de> |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Tidal\PhpSpec\ConsoleExtension\Command; |
11
|
|
|
|
12
|
|
|
use Symfony\Component\Console\Command\Command; |
13
|
|
|
|
14
|
|
|
use Tidal\PhpSpec\ConsoleExtension\Contract\Command\{ |
15
|
|
|
ConfiguratorInterface |
16
|
|
|
}; |
17
|
|
|
use Tidal\PhpSpec\ConsoleExtension\Contract\WriterInterface; |
18
|
|
|
use Tidal\PhpSpec\ConsoleExtension\Behavior\{ |
19
|
|
|
HasWriterTrait, |
20
|
|
|
HasContainerTrait |
21
|
|
|
}; |
22
|
|
|
use Tidal\PhpSpec\ConsoleExtension\Behavior\Command\{ |
23
|
|
|
ConfigurableTrait, |
24
|
|
|
HasInputTrait, |
25
|
|
|
HasOutputTrait |
26
|
|
|
}; |
27
|
|
|
use Tidal\PhpSpec\ConsoleExtension\Contract\Command\ConfigInterface as Config; |
28
|
|
|
use Tidal\PhpSpec\ConsoleExtension\Contract\Command\InlineConfigCommandInterface; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* class Tidal\PhpSpec\ConsoleExtension\Command\GenericInlineConfigCommand |
32
|
|
|
*/ |
33
|
|
|
class GenericInlineConfigCommand extends Command implements InlineConfigCommandInterface |
34
|
|
|
{ |
35
|
|
|
use ConfigurableTrait, |
36
|
|
|
HasInputTrait, |
37
|
|
|
HasOutputTrait, |
38
|
|
|
HasWriterTrait, |
39
|
|
|
HasContainerTrait; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* CONFIG |
43
|
|
|
*/ |
44
|
|
|
public const NAME = 'inline-config-command'; |
45
|
|
|
public const DESCRIPTION = 'generic inline config command'; |
46
|
|
|
public const HIDDEN = false; |
47
|
|
|
public const USAGES = []; |
48
|
|
|
public const HELP = ''; |
49
|
|
|
public const ARGUMENTS = []; |
50
|
|
|
public const OPTIONS = []; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* GenericInlineConfigCommand constructor. |
54
|
|
|
* @param WriterInterface $writer |
55
|
|
|
* @param ConfiguratorInterface $configurator |
56
|
|
|
* @param array|null $config |
57
|
|
|
*/ |
58
|
|
|
public function __construct(WriterInterface $writer, ConfiguratorInterface $configurator, ?array $config = []) |
59
|
|
|
{ |
60
|
|
|
if ($config !== null) { |
61
|
|
|
$configurator->setConfig($config); |
62
|
|
|
if (isset($config[Config::NAME_KEY])) { |
63
|
|
|
$this->setName($config[Config::NAME_KEY]); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
$this->setWriter($writer); |
67
|
|
|
$this->setConfigurator($configurator); |
68
|
|
|
parent::__construct(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
protected function configure() |
72
|
|
|
{ |
73
|
|
|
$this |
74
|
|
|
->getConfigurator() |
75
|
|
|
->configure($this); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param string[] $usages |
80
|
|
|
*/ |
81
|
|
|
public function setUsages(array $usages = []) |
82
|
|
|
{ |
83
|
|
|
foreach ($usages as $usage) { |
84
|
|
|
$this->addUsage($usage); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
|
|
public function getConfig(): array |
92
|
|
|
{ |
93
|
|
|
return [ |
94
|
|
|
Config::NAME_KEY => static::NAME, |
95
|
|
|
Config::DESCRIPTION_KEY => static::DESCRIPTION, |
96
|
|
|
Config::HELP_KEY => static::HELP, |
97
|
|
|
Config::HIDDEN_KEY => static::HIDDEN, |
98
|
|
|
Config::ARGUMENTS_KEY => static::ARGUMENTS, |
99
|
|
|
Config::OPTIONS_KEY => static::OPTIONS, |
100
|
|
|
]; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|