|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Bowerphp. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Massimiliano Arione <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Bowerphp\Command; |
|
13
|
|
|
|
|
14
|
|
|
use Bowerphp\Package\Package; |
|
15
|
|
|
use Bowerphp\Util\PackageNameVersionExtractor; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Info |
|
22
|
|
|
*/ |
|
23
|
|
|
class InfoCommand extends Command |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
*/ |
|
28
|
|
|
protected function configure() |
|
29
|
|
|
{ |
|
30
|
|
|
$this |
|
31
|
|
|
->setName('info') |
|
32
|
|
|
->setDescription('Displays overall information of a package or of a particular version') |
|
33
|
|
|
->addArgument('package', InputArgument::REQUIRED, 'Choose a package.') |
|
34
|
|
|
->addArgument('property', InputArgument::OPTIONAL, 'A property present in bower.json.') |
|
35
|
|
|
->setHelp(<<<'EOT' |
|
36
|
|
|
The <info>%command.name%</info> command displays overall information of a package or of a particular version. |
|
37
|
|
|
If you pass a property present in bower.json, you can get the correspondent value. |
|
38
|
|
|
|
|
39
|
|
|
<info>php %command.full_name% package</info> |
|
40
|
|
|
EOT |
|
41
|
|
|
) |
|
42
|
|
|
; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* {@inheritdoc} |
|
47
|
|
|
*/ |
|
48
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
49
|
|
|
{ |
|
50
|
|
|
$this->setGithubToken($output); |
|
51
|
|
|
|
|
52
|
|
|
$packageName = $input->getArgument('package'); |
|
53
|
|
|
$property = $input->getArgument('property'); |
|
54
|
|
|
|
|
55
|
|
|
$packageNameVersion = PackageNameVersionExtractor::fromString($packageName); |
|
56
|
|
|
|
|
57
|
|
|
$package = new Package($packageNameVersion->name, $packageNameVersion->version); |
|
58
|
|
|
$bowerphp = $this->getBowerphp($output); |
|
59
|
|
|
|
|
60
|
|
|
$bowerJsonFile = $bowerphp->getPackageBowerFile($package); |
|
61
|
|
|
if ('*' == $packageNameVersion->version) { |
|
62
|
|
|
$versions = $bowerphp->getPackageInfo($package, 'versions'); |
|
63
|
|
|
} |
|
64
|
|
|
if (!is_null($property)) { |
|
65
|
|
|
$bowerArray = json_decode($bowerJsonFile, true); |
|
66
|
|
|
$propertyValue = isset($bowerArray[$property]) ? $bowerArray[$property] : ''; |
|
67
|
|
|
$this->consoleOutput->writelnJsonText($propertyValue); |
|
68
|
|
|
|
|
69
|
|
|
return; |
|
70
|
|
|
} |
|
71
|
|
|
$this->consoleOutput->writelnJson($bowerJsonFile); |
|
72
|
|
|
if ('*' != $packageNameVersion->version) { |
|
73
|
|
|
return; |
|
74
|
|
|
} |
|
75
|
|
|
$output->writeln(''); |
|
76
|
|
|
if (empty($versions)) { |
|
77
|
|
|
$output->writeln('No versions available.'); |
|
78
|
|
|
} else { |
|
79
|
|
|
$output->writeln('<fg=cyan>Available versions:</fg=cyan>'); |
|
80
|
|
|
foreach ($versions as $vrs) { |
|
|
|
|
|
|
81
|
|
|
$output->writeln("- $vrs"); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.