|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Support\XDebug; |
|
4
|
|
|
|
|
5
|
|
|
use App\Models\PhpVersion; |
|
6
|
|
|
use App\Models\Setting; |
|
7
|
|
|
use App\Porter; |
|
8
|
|
|
use App\Support\Console\DockerCompose\CliCommandFactory; |
|
9
|
|
|
|
|
10
|
|
|
class XDebug |
|
11
|
|
|
{ |
|
12
|
|
|
/** @var Porter */ |
|
13
|
|
|
protected $porter; |
|
14
|
|
|
|
|
15
|
|
|
/** @var CliCommandFactory */ |
|
16
|
|
|
protected $dockerCompose; |
|
17
|
|
|
|
|
18
|
193 |
|
public function __construct(Porter $porter, CliCommandFactory $dockerCompose) |
|
19
|
|
|
{ |
|
20
|
193 |
|
$this->porter = $porter; |
|
21
|
193 |
|
$this->dockerCompose = $dockerCompose; |
|
22
|
193 |
|
} |
|
23
|
|
|
|
|
24
|
4 |
|
public function turnOn() |
|
25
|
|
|
{ |
|
26
|
4 |
|
Setting::updateOrCreate('use_xdebug', 'on'); |
|
27
|
|
|
|
|
28
|
4 |
|
$results = []; |
|
29
|
4 |
|
foreach (PhpVersion::active()->get() as $version) { |
|
30
|
1 |
|
$move = "mv /etc/php/{$version->version_number}/mods-available/xdebug.bak /etc/php/{$version->version_number}/mods-available/xdebug.ini"; |
|
31
|
|
|
|
|
32
|
1 |
|
ob_start(); |
|
33
|
1 |
|
$this->dockerCompose->execContainer($version->getFpmNameAttribute())->append($move)->interactive()->perform(); |
|
34
|
1 |
|
$results[$version->id] = ob_get_clean(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
4 |
|
foreach (PhpVersion::active()->get() as $version) { |
|
38
|
1 |
|
if ($results[$version->id]) { |
|
39
|
|
|
// If there was any output captured it's because it failed - the file wasn't able to be moved |
|
40
|
|
|
// Most likely because it was moved before |
|
41
|
1 |
|
continue; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$this->porter->softRestart($version->getFpmNameAttribute()); |
|
45
|
|
|
} |
|
46
|
4 |
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function turnOff() |
|
49
|
|
|
{ |
|
50
|
|
|
Setting::updateOrCreate('use_xdebug', 'off'); |
|
51
|
|
|
|
|
52
|
|
|
$results = []; |
|
53
|
|
|
foreach (PhpVersion::active()->get() as $version) { |
|
54
|
|
|
$move = "mv /etc/php/{$version->version_number}/mods-available/xdebug.ini /etc/php/{$version->version_number}/mods-available/xdebug.bak"; |
|
55
|
|
|
|
|
56
|
|
|
ob_start(); |
|
57
|
|
|
$this->dockerCompose->execContainer($version->getFpmNameAttribute())->append($move)->interactive()->perform(); |
|
58
|
|
|
$results[$version->id] = ob_get_clean(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
foreach (PhpVersion::active()->get() as $version) { |
|
62
|
|
|
if ($results[$version->id]) { |
|
63
|
|
|
// If there was any output captured it's because it failed - the file wasn't able to be moved |
|
64
|
|
|
// Most likely because it was moved before |
|
65
|
|
|
continue; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$this->porter->softRestart($version->getFpmNameAttribute()); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|