|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Geekish\Crap; |
|
4
|
|
|
|
|
5
|
|
|
use Composer\Package\Version\VersionParser; |
|
6
|
|
|
use mindplay\unbox\ContainerFactory; |
|
7
|
|
|
use mindplay\unbox\ProviderInterface; |
|
8
|
|
|
use Symfony\Component\Console\Formatter\OutputFormatterStyle; |
|
9
|
|
|
use Symfony\Component\Console\Helper; |
|
10
|
|
|
use Symfony\Component\Console\Input\ArgvInput; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
12
|
|
|
use Symfony\Component\Console\Output\ConsoleOutput; |
|
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
14
|
|
|
use Webmozart\KeyValueStore\JsonFileStore; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @codeCoverageIgnore |
|
18
|
|
|
*/ |
|
19
|
|
|
class CrapProvider implements ProviderInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var string */ |
|
22
|
|
|
private $composerHome; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param string $composerHome |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct($composerHome) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->composerHome = $composerHome; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @inheritDoc |
|
34
|
|
|
*/ |
|
35
|
|
|
public function register(ContainerFactory $factory) |
|
36
|
|
|
{ |
|
37
|
|
|
$composerHome = $this->composerHome; |
|
38
|
|
|
|
|
39
|
|
|
$factory->register(ArgvInput::class); |
|
40
|
|
|
$factory->register(ConsoleOutput::class); |
|
41
|
|
|
|
|
42
|
|
|
$factory->alias(InputInterface::class, ArgvInput::class); |
|
43
|
|
|
$factory->alias(OutputInterface::class, ConsoleOutput::class); |
|
44
|
|
|
|
|
45
|
|
|
$factory->configure( |
|
46
|
|
|
ConsoleOutput::class, |
|
47
|
|
|
function (ConsoleOutput $output) { |
|
48
|
|
|
$output->getFormatter()->setStyle('error', new OutputFormatterStyle('red', null, [])); |
|
49
|
|
|
$output->getFormatter()->setStyle('success', new OutputFormatterStyle('green', null, [])); |
|
50
|
|
|
return $output; |
|
51
|
|
|
} |
|
52
|
|
|
); |
|
53
|
|
|
|
|
54
|
|
|
$factory->set( |
|
55
|
|
|
Helper\HelperSet::class, |
|
56
|
|
|
new Helper\HelperSet([ |
|
57
|
|
|
new Helper\FormatterHelper(), |
|
58
|
|
|
new Helper\DebugFormatterHelper(), |
|
59
|
|
|
new Helper\ProcessHelper(), |
|
60
|
|
|
new Helper\QuestionHelper(), |
|
61
|
|
|
]) |
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
|
|
$factory->register(VersionParser::class); |
|
65
|
|
|
$factory->register(CrapHelper::class); |
|
66
|
|
|
$factory->register(Crap::class); |
|
67
|
|
|
|
|
68
|
|
|
$factory->register( |
|
69
|
|
|
JsonFileStore::class, |
|
70
|
|
|
function () use ($composerHome) { |
|
71
|
|
|
$file = sprintf('%s/%s', $composerHome, Crap::FILENAME); |
|
72
|
|
|
$flags = JsonFileStore::NO_SERIALIZE_STRINGS |
|
73
|
|
|
| JsonFileStore::PRETTY_PRINT |
|
74
|
|
|
| JsonFileStore::NO_ESCAPE_SLASH; |
|
75
|
|
|
return new JsonFileStore($file, $flags); |
|
76
|
|
|
} |
|
77
|
|
|
); |
|
78
|
|
|
|
|
79
|
|
|
$factory->configure( |
|
80
|
|
|
Crap::class, |
|
81
|
|
|
function (Crap $crap, CrapHelper $helper) { |
|
82
|
|
|
$crap->addCommands([ |
|
83
|
|
|
new Command\ListAliasesCommand($helper), |
|
84
|
|
|
new Command\AliasCommand($helper), |
|
85
|
|
|
new Command\InfoCommand($helper), |
|
86
|
|
|
new Command\UnaliasCommand($helper), |
|
87
|
|
|
new Command\RequireCommand($helper), |
|
88
|
|
|
new Command\UpdateCommand($helper), |
|
89
|
|
|
new Command\RemoveCommand($helper), |
|
90
|
|
|
new Command\ProjectCommand($helper), |
|
91
|
|
|
]); |
|
92
|
|
|
return $crap; |
|
93
|
|
|
} |
|
94
|
|
|
); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|