|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sunnysideup\UpgradeToSilverstripe4\Tasks\Helpers; |
|
4
|
|
|
|
|
5
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Traits\HelperInst; |
|
6
|
|
|
|
|
7
|
|
|
class Composer |
|
8
|
|
|
{ |
|
9
|
|
|
use HelperInst; |
|
10
|
|
|
|
|
11
|
|
|
protected $defaultOptions = ''; |
|
12
|
|
|
|
|
13
|
|
|
public function DumpAutoload(): self |
|
14
|
|
|
{ |
|
15
|
|
|
$this->mu()->execMe( |
|
16
|
|
|
$this->mu()->getWebRootDirLocation(), |
|
|
|
|
|
|
17
|
|
|
'composer dumpautoload --no-interaction', |
|
18
|
|
|
'run composer dumpautoload', |
|
19
|
|
|
false |
|
20
|
|
|
); |
|
21
|
|
|
|
|
22
|
|
|
return $this; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function ClearCache(): self |
|
26
|
|
|
{ |
|
27
|
|
|
$this->mu()->execMe( |
|
28
|
|
|
$this->mu()->getWebRootDirLocation(), |
|
|
|
|
|
|
29
|
|
|
'composer clear-cache --no-interaction', |
|
30
|
|
|
'clear composer cache', |
|
31
|
|
|
false |
|
32
|
|
|
); |
|
33
|
|
|
|
|
34
|
|
|
return $this; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function RequireGlobal(string $package, ?string $version = '', ?bool $devOnly = false, ?string $options = ''): self |
|
38
|
|
|
{ |
|
39
|
|
|
return $this->requireAny($package, $version, $devOnly, $options, true); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function Require(string $package, ?string $version = '', ?string $options = ''): self |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->requireAny($package, $version, false, $options, false); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function RequireDev(string $package, ?string $version = '', ?string $options = ''): self |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->requireAny($package, $version, true, $options, false); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function RemoveDev(string $package): self |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->Remove($package, true); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function Remove(string $package, ?bool $devOnly = false): self |
|
58
|
|
|
{ |
|
59
|
|
|
$devFlag = $devOnly ? '--dev' : ''; |
|
60
|
|
|
$this->mu()->execMe( |
|
61
|
|
|
$this->mu()->getWebRootDirLocation(), |
|
|
|
|
|
|
62
|
|
|
'composer remove ' . $package . ' ' . $devFlag. ' --no-interaction', |
|
63
|
|
|
'running composer remove ' . $package . ' ' . $devFlag, |
|
64
|
|
|
false |
|
65
|
|
|
); |
|
66
|
|
|
|
|
67
|
|
|
return $this; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
protected function requireAny(string $package, ?string $version = '', ?bool $devOnly = false, ?string $options = '', ?bool $isGlobal = false): self |
|
71
|
|
|
{ |
|
72
|
|
|
$devFlag = $devOnly ? '--dev' : ''; |
|
73
|
|
|
if (! $options) { |
|
74
|
|
|
$options = $this->defaultOptions; |
|
75
|
|
|
} |
|
76
|
|
|
if ($version) { |
|
77
|
|
|
$version = ':' . $version; |
|
78
|
|
|
} |
|
79
|
|
|
$globalPhrase = ''; |
|
80
|
|
|
if ($isGlobal) { |
|
81
|
|
|
$globalPhrase = 'global'; |
|
82
|
|
|
} |
|
83
|
|
|
$this->mu()->execMe( |
|
84
|
|
|
$this->mu()->getWebRootDirLocation(), |
|
|
|
|
|
|
85
|
|
|
'composer ' . $globalPhrase . ' require ' . $package . $version . ' ' . $devFlag . ' ' . $options. ' --no-interaction', |
|
86
|
|
|
'running composer require ' . $package . $version . ' ' . $devFlag . ' ' . $options, |
|
87
|
|
|
false |
|
88
|
|
|
); |
|
89
|
|
|
|
|
90
|
|
|
return $this; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|