1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\Base\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:base: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
|
|
|
* Create a new command instance. |
27
|
|
|
* |
28
|
|
|
* @return void |
|
|
|
|
29
|
|
|
*/ |
30
|
|
|
public function __construct() |
31
|
|
|
{ |
32
|
|
|
parent::__construct(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Execute the console command. |
37
|
|
|
* |
38
|
|
|
* @return mixed |
39
|
|
|
*/ |
40
|
|
|
public function handle() |
41
|
|
|
{ |
42
|
|
|
$this->comment('### PHP VERSION:'); |
43
|
|
|
$this->runCommand('php -v'); |
44
|
|
|
|
45
|
|
|
$this->comment('### BACKPACK PACKAGES VERSION:'); |
46
|
|
|
$this->runCommand('composer show | grep "backpack\|laravel/framework"'); |
47
|
|
|
|
48
|
|
|
$this->comment('### MYSQL VERSION:'); |
49
|
|
|
$this->runCommand('mysql --version'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Run a shell command in a separate process. |
54
|
|
|
* |
55
|
|
|
* @param string $command Text to be executed. |
56
|
|
|
* @return void |
57
|
|
|
*/ |
58
|
|
|
private function runCommand($command) { |
59
|
|
|
$process = new Process($command, null, null, null, 60, null); |
|
|
|
|
60
|
|
|
$process->run(function ($type, $buffer) { |
61
|
|
|
if (Process::ERR === $type) { |
62
|
|
|
$this->line($buffer); |
63
|
|
|
} else { |
64
|
|
|
$this->line($buffer); |
65
|
|
|
} |
66
|
|
|
}); |
67
|
|
|
|
68
|
|
|
// executes after the command finishes |
69
|
|
|
if (!$process->isSuccessful()) { |
70
|
|
|
throw new ProcessFailedException($process); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.