|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\app\Console\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
|
6
|
|
|
use Symfony\Component\Process\Exception\ProcessFailedException; |
|
7
|
|
|
use Symfony\Component\Process\Process; |
|
8
|
|
|
|
|
9
|
|
|
class Version extends Command |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* The name and signature of the console command. |
|
13
|
|
|
* |
|
14
|
|
|
* @var string |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $signature = 'backpack:version'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* The console command description. |
|
20
|
|
|
* |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $description = 'Show the version of PHP and Backpack packages.'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Execute the console command. |
|
27
|
|
|
* |
|
28
|
|
|
* @return mixed |
|
29
|
|
|
*/ |
|
30
|
|
|
public function handle() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->comment('### PHP VERSION:'); |
|
33
|
|
|
$this->runConsoleCommand(['php', '-v']); |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
$this->comment('### LARAVEL VERSION:'); |
|
36
|
|
|
$this->line(\PackageVersions\Versions::getVersion('laravel/framework')); |
|
37
|
|
|
$this->line(''); |
|
38
|
|
|
|
|
39
|
|
|
$this->comment('### BACKPACK PACKAGE VERSIONS:'); |
|
40
|
|
|
|
|
41
|
|
|
if (class_exists(\Composer\InstalledVersions::class, false)) { |
|
42
|
|
|
$this->getPackageVersionsFromComposer2(); |
|
43
|
|
|
} else { |
|
44
|
|
|
$this->getPackageVersionsFromComposer1(); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
private function getPackageVersionsFromComposer2() |
|
49
|
|
|
{ |
|
50
|
|
|
$packages = \Composer\InstalledVersions::getInstalledPackages(); |
|
51
|
|
|
foreach ($packages as $package) { |
|
52
|
|
|
if (substr($package, 0, 9) == 'backpack/') { |
|
53
|
|
|
$this->line($package.': '.\Composer\InstalledVersions::getPrettyVersion($package)); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
private function getPackageVersionsFromComposer1() |
|
59
|
|
|
{ |
|
60
|
|
|
$packages = \PackageVersions\Versions::VERSIONS; |
|
61
|
|
|
foreach ($packages as $package => $version) { |
|
62
|
|
|
if (substr($package, 0, 9) == 'backpack/') { |
|
63
|
|
|
$this->line($package.': '.strtok($version, '@')); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Run a shell command in a separate process. |
|
70
|
|
|
* |
|
71
|
|
|
* @param string $command Text to be executed. |
|
72
|
|
|
* @return void |
|
73
|
|
|
*/ |
|
74
|
|
|
private function runConsoleCommand($command) |
|
75
|
|
|
{ |
|
76
|
|
|
$process = new Process($command, null, null, null, 60, null); |
|
|
|
|
|
|
77
|
|
|
$process->run(function ($type, $buffer) { |
|
78
|
|
|
if (Process::ERR === $type) { |
|
79
|
|
|
$this->line($buffer); |
|
80
|
|
|
} else { |
|
81
|
|
|
$this->line($buffer); |
|
82
|
|
|
} |
|
83
|
|
|
}); |
|
84
|
|
|
|
|
85
|
|
|
// executes after the command finishes |
|
86
|
|
|
if (! $process->isSuccessful()) { |
|
87
|
|
|
throw new ProcessFailedException($process); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|