1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of RoboSystemPackage. |
4
|
|
|
* |
5
|
|
|
* @author Aitor García Martínez (Falc) <[email protected]> |
6
|
|
|
* @copyright 2015 Aitor García Martínez (Falc) <[email protected]> |
7
|
|
|
* @license MIT |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Falc\Robo\Package\CommandBuilder; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Pacman command builder. |
14
|
|
|
*/ |
15
|
|
|
class PacmanCommandBuilder implements CommandBuilderInterface |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Command action. |
19
|
|
|
* |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $action; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Option list. |
26
|
|
|
* |
27
|
|
|
* @var string[] |
28
|
|
|
*/ |
29
|
|
|
protected $options = []; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Package list. |
33
|
|
|
* |
34
|
|
|
* @var string[] |
35
|
|
|
*/ |
36
|
|
|
protected $packages = []; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Whether quiet mode is enabled or not. |
40
|
|
|
* |
41
|
|
|
* @var boolean |
42
|
|
|
*/ |
43
|
|
|
protected $quiet = false; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
5 |
|
public function install(array $packages) |
49
|
|
|
{ |
50
|
5 |
|
if (empty($packages)) { |
51
|
1 |
|
throw new \Exception('No packages selected to be installed'); |
52
|
|
|
} |
53
|
|
|
|
54
|
4 |
|
$this->packages = $packages; |
55
|
4 |
|
$this->action = 'Sy'; |
56
|
|
|
|
57
|
4 |
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
3 |
|
public function update(array $packages = []) |
64
|
|
|
{ |
65
|
3 |
|
$this->packages = $packages; |
66
|
3 |
|
$this->action = empty($packages) ? 'Syu' : 'Sy'; |
67
|
|
|
|
68
|
3 |
|
return $this; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* {@inheritdoc} |
73
|
|
|
*/ |
74
|
3 |
|
public function uninstall(array $packages) |
75
|
|
|
{ |
76
|
3 |
|
if (empty($packages)) { |
77
|
1 |
|
throw new \Exception('No packages selected to be uninstalled'); |
78
|
|
|
} |
79
|
|
|
|
80
|
2 |
|
$this->packages = $packages; |
81
|
2 |
|
$this->action = 'Rs'; |
82
|
|
|
|
83
|
2 |
|
return $this; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* {@inheritdoc} |
88
|
|
|
*/ |
89
|
1 |
|
public function assumeYes() |
90
|
|
|
{ |
91
|
1 |
|
$this->options[] = '--noconfirm'; |
92
|
|
|
|
93
|
1 |
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* {@inheritdoc} |
98
|
|
|
*/ |
99
|
1 |
|
public function quiet() |
100
|
|
|
{ |
101
|
1 |
|
$this->quiet = true; |
102
|
|
|
|
103
|
1 |
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* {@inheritdoc} |
108
|
|
|
*/ |
109
|
9 |
|
public function getCommand() |
110
|
|
|
{ |
111
|
9 |
|
$packages = implode(' ', array_unique($this->packages)); |
112
|
9 |
|
$options = implode(' ', array_unique($this->options)); |
113
|
|
|
|
114
|
9 |
|
$command = "pacman -{$this->action} {$options} {$packages}"; |
115
|
|
|
|
116
|
9 |
|
if ($this->quiet === true) { |
117
|
1 |
|
$command .= ' 1> /dev/null'; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
// Remove extra whitespaces |
121
|
9 |
|
$command = preg_replace('/\s+/', ' ', trim($command)); |
122
|
|
|
|
123
|
9 |
|
return $command; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|