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; |
11
|
|
|
|
12
|
|
|
use Robo\Contract\CommandInterface; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Package Install |
16
|
|
|
* |
17
|
|
|
* ``` php |
18
|
|
|
* // Installing a single package: |
19
|
|
|
* $this->taskPackageInstall() |
20
|
|
|
* ->packageManager('yum') |
21
|
|
|
* ->package('package1') |
22
|
|
|
* ->run(); |
23
|
|
|
* |
24
|
|
|
* // Installing many packages: |
25
|
|
|
* $this->taskPackageInstall() |
26
|
|
|
* ->packageManager('yum') |
27
|
|
|
* ->packages(['package1', 'package2']) |
28
|
|
|
* ->run(); |
29
|
|
|
* |
30
|
|
|
* // Compact form: |
31
|
|
|
* $this->taskPackageInstall('yum', ['package1', 'package2'])->run(); |
32
|
|
|
* |
33
|
|
|
* // It allows to specify packages conditionally: |
34
|
|
|
* $install = $this->taskPackageInstall('yum', ['package1']); |
35
|
|
|
* |
36
|
|
|
* if ($requiresPackage2) { |
37
|
|
|
* $install->package('package2'); |
38
|
|
|
* } |
39
|
|
|
* |
40
|
|
|
* $install->run(); |
41
|
|
|
* |
42
|
|
|
* // It is possible to specify a pattern: |
43
|
|
|
* $this->taskPackageInstall() |
44
|
|
|
* ->packageManager('yum') |
45
|
|
|
* ->package('package1-*') // Installs all packages starting with "package1-" |
46
|
|
|
* ->run(); |
47
|
|
|
* ``` |
48
|
|
|
*/ |
49
|
|
View Code Duplication |
class Install extends BaseTask implements CommandInterface |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
8 |
|
public function getCommand() |
55
|
|
|
{ |
56
|
8 |
|
if ($this->builder === null) { |
57
|
1 |
|
throw new \Exception('Package manager not defined'); |
58
|
|
|
} |
59
|
|
|
|
60
|
7 |
|
$this->builder->install($this->packages)->assumeYes(); |
61
|
|
|
|
62
|
7 |
|
if (!$this->verbose) { |
63
|
6 |
|
$this->builder->quiet(); |
64
|
|
|
} |
65
|
|
|
|
66
|
7 |
|
return $this->builder->getCommand(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritdoc} |
71
|
|
|
*/ |
72
|
1 |
|
public function run() |
73
|
|
|
{ |
74
|
1 |
|
$command = $this->getCommand(); |
75
|
|
|
|
76
|
1 |
|
$this->printTaskInfo('Installing packages...'); |
77
|
1 |
|
return $this->executeCommand($command); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.