-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRequireCommand.php
More file actions
84 lines (69 loc) · 1.67 KB
/
RequireCommand.php
File metadata and controls
84 lines (69 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
namespace Winter\Packager\Commands;
use Winter\Packager\Composer;
use Winter\Packager\Exceptions\CommandException;
use Winter\Packager\Exceptions\WorkDirException;
class RequireCommand extends BaseCommand
{
/**
* Command constructor.
*/
final public function __construct(
protected Composer $composer,
protected string $package,
protected bool $dryRun = false,
protected bool $dev = false,
protected bool $noUpdate = false,
protected bool $noScripts = false,
) {
parent::__construct($composer);
}
/**
* @inheritDoc
*/
public function arguments(): array
{
$arguments = [];
if ($this->dryRun) {
$arguments['--dry-run'] = true;
}
if ($this->dev) {
$arguments['--dev'] = true;
}
if ($this->noUpdate) {
$arguments['--no-update'] = true;
}
if ($this->noScripts) {
$arguments['--no-scripts'] = true;
}
$arguments['packages'] = [$this->package];
return $arguments;
}
/**
* @throws CommandException
* @throws WorkDirException
*/
public function execute(): string
{
$output = $this->runComposerCommand();
$message = implode(PHP_EOL, $output['output']);
if ($output['code'] !== 0) {
throw new CommandException($message);
}
return $message;
}
/**
* @inheritDoc
*/
protected function requiresWorkDir(): bool
{
return true;
}
/**
* @inheritDoc
*/
public function getCommandName(): string
{
return 'require';
}
}