1
|
|
|
<?php namespace Modules\Core\Services; |
2
|
|
|
|
3
|
|
|
use Symfony\Component\Process\Process; |
4
|
|
|
|
5
|
|
|
class Composer extends \Illuminate\Foundation\Composer |
6
|
|
|
{ |
7
|
|
|
protected $outputHandler = null; |
8
|
|
|
private $output; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Enable real time output of all commands. |
12
|
|
|
* |
13
|
|
|
* @param $command |
14
|
|
|
* @return void |
15
|
|
|
*/ |
16
|
|
|
public function enableOutput($command) |
17
|
|
|
{ |
18
|
|
|
$this->output = function ($type, $buffer) use ($command) { |
19
|
|
|
if (Process::ERR === $type) { |
20
|
|
|
$command->info(trim('[ERR] > ' . $buffer)); |
21
|
|
|
} else { |
22
|
|
|
$command->info(trim('> ' . $buffer)); |
23
|
|
|
} |
24
|
|
|
}; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Disable real time output of all commands. |
29
|
|
|
* |
30
|
|
|
* @return void |
31
|
|
|
*/ |
32
|
|
|
public function disableOutput() |
33
|
|
|
{ |
34
|
|
|
$this->output = null; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Update all composer packages. |
39
|
|
|
* |
40
|
|
|
* @param string $package |
41
|
|
|
* @return void |
42
|
|
|
*/ |
43
|
|
View Code Duplication |
public function update($package = null) |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
if (!is_null($package)) { |
46
|
|
|
$package = '"' . $package . '"'; |
47
|
|
|
} |
48
|
|
|
$process = $this->getProcess(); |
49
|
|
|
$process->setCommandLine(trim($this->findComposer() . ' update ' . $package)); |
50
|
|
|
$process->run($this->output); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Require a new composer package. |
55
|
|
|
* |
56
|
|
|
* @param string $package |
57
|
|
|
* @return void |
58
|
|
|
*/ |
59
|
|
View Code Duplication |
public function install($package) |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
if (!is_null($package)) { |
62
|
|
|
$package = '"' . $package . '"'; |
63
|
|
|
} |
64
|
|
|
$process = $this->getProcess(); |
65
|
|
|
$process->setCommandLine(trim($this->findComposer() . ' require ' . $package)); |
66
|
|
|
$process->run($this->output); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return void |
71
|
|
|
*/ |
72
|
|
|
public function dumpAutoload() |
73
|
|
|
{ |
74
|
|
|
$process = $this->getProcess(); |
75
|
|
|
$process->setCommandLine(trim($this->findComposer() . ' dump-autoload -o')); |
76
|
|
|
$process->run($this->output); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
View Code Duplication |
public function remove($package) |
|
|
|
|
80
|
|
|
{ |
81
|
|
|
if (!is_null($package)) { |
82
|
|
|
$package = '"' . $package . '"'; |
83
|
|
|
} |
84
|
|
|
$process = $this->getProcess(); |
85
|
|
|
$process->setCommandLine(trim($this->findComposer() . ' remove ' . $package)); |
86
|
|
|
$process->run($this->output); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
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.