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(\Composer\InstalledVersions::getVersion('laravel/framework')); |
37
|
|
|
$this->line(''); |
38
|
|
|
|
39
|
|
|
$this->comment('### BACKPACK PACKAGE VERSIONS:'); |
40
|
|
|
$packages = \Composer\InstalledVersions::getInstalledPackages(); |
41
|
|
|
foreach ($packages as $package) { |
42
|
|
|
if (substr($package, 0, 9) == 'backpack/') { |
43
|
|
|
$this->line($package.': '.\Composer\InstalledVersions::getPrettyVersion($package)); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Run a shell command in a separate process. |
50
|
|
|
* |
51
|
|
|
* @param array $command Text to be executed. |
52
|
|
|
* @return void |
53
|
|
|
*/ |
54
|
|
|
private function runConsoleCommand($command) |
55
|
|
|
{ |
56
|
|
|
$process = new Process($command, null, null, null, 60, null); |
|
|
|
|
57
|
|
|
$process->run(function ($type, $buffer) { |
58
|
|
|
if (Process::ERR === $type) { |
59
|
|
|
$this->line($buffer); |
60
|
|
|
} else { |
61
|
|
|
$this->line($buffer); |
62
|
|
|
} |
63
|
|
|
}); |
64
|
|
|
|
65
|
|
|
// executes after the command finishes |
66
|
|
|
if (! $process->isSuccessful()) { |
67
|
|
|
throw new ProcessFailedException($process); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.