1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the wow-apps/symfony-packagist project |
4
|
|
|
* https://github.com/wow-apps/symfony-packagist |
5
|
|
|
* |
6
|
|
|
* (c) 2017 WoW-Apps |
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 WowApps\PackagistBundle\Command; |
13
|
|
|
|
14
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
15
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
18
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
19
|
|
|
use WowApps\PackagistBundle\DTO\Package; |
20
|
|
|
use WowApps\PackagistBundle\DTO\PackageAuthor; |
21
|
|
|
use WowApps\PackagistBundle\DTO\PackageDependency; |
22
|
|
|
use WowApps\PackagistBundle\Exception\PackagistException; |
23
|
|
|
use WowApps\PackagistBundle\Service\Packagist; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class WowAppsPackagistPackageCommand |
27
|
|
|
* |
28
|
|
|
* @author Alexey Samara <[email protected]> |
29
|
|
|
* @package wow-apps/symfony-packagist |
30
|
|
|
*/ |
31
|
|
|
class WowAppsPackagistPackageCommand extends ContainerAwareCommand |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* @return void |
35
|
|
|
*/ |
36
|
|
|
protected function configure() |
37
|
|
|
{ |
38
|
|
|
$this |
39
|
|
|
->setName('wowapps:packagist:package') |
40
|
|
|
->setDescription('Get selected package and show it\'s data') |
41
|
|
|
->addArgument('package_name', InputArgument::OPTIONAL, 'Package name') |
42
|
|
|
; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param InputInterface $input |
47
|
|
|
* @param OutputInterface $output |
48
|
|
|
* @return void |
49
|
|
|
* @throws PackagistException |
50
|
|
|
*/ |
51
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
52
|
|
|
{ |
53
|
|
|
/** @var Packagist $packagist */ |
54
|
|
|
$packagist = $this->getContainer()->get('wowapps.packagist'); |
55
|
|
|
$argument = strtolower($input->getArgument('package_name')); |
56
|
|
|
$symfonyStyle = new SymfonyStyle($input, $output); |
57
|
|
|
|
58
|
|
|
echo PHP_EOL; |
59
|
|
|
$output->writeln('<bg=green;options=bold;fg=white> </>'); |
60
|
|
|
$output->writeln('<bg=green;options=bold;fg=white> Symfony Packagist API Bundle </>'); |
61
|
|
|
$output->writeln('<bg=green;options=bold;fg=white> </>'); |
62
|
|
|
echo PHP_EOL; |
63
|
|
|
|
64
|
|
|
if (empty($argument)) { |
65
|
|
|
$symfonyStyle->error([ |
66
|
|
|
PackagistException::E_EMPTY_PACKAGE_NAME, |
67
|
|
|
PackagistException::E_EMPTY_PACKAGE_NAME_DESCRIPTION, |
68
|
|
|
]); |
69
|
|
|
|
70
|
|
|
return; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$symfonyStyle->title('Getting package ' . $argument); |
74
|
|
|
|
75
|
|
|
$package = $packagist->getPackage($argument); |
76
|
|
|
|
77
|
|
|
$output->writeln('<options=bold;fg=yellow>Package name:</> ' . $package->getName()); |
78
|
|
|
$output->writeln('<options=bold;fg=yellow>Package description:</> ' . $package->getDescription()); |
79
|
|
|
$output->writeln('<options=bold;fg=yellow>Package version:</> ' . $package->getVersion()); |
80
|
|
|
$output->writeln('<options=bold;fg=yellow>Package time:</> ' . $package->getTime()); |
81
|
|
|
$output->writeln('<options=bold;fg=yellow>Package type:</> ' . $package->getType()); |
82
|
|
|
$output->writeln('<options=bold;fg=yellow>Package repository:</> ' . $package->getRepository()); |
83
|
|
|
$output->writeln( |
84
|
|
|
'<options=bold;fg=yellow>Package keywords:</> ' |
85
|
|
|
. implode(', ', $package->getVersions()->offsetGet($package->getVersion())->getKeywords()) |
86
|
|
|
); |
87
|
|
|
$output->writeln('<options=bold;fg=yellow>Package GitHub stat:</>'); |
88
|
|
|
$symfonyStyle->listing([ |
89
|
|
|
'Stars: ' . $package->getGithub()->getStars(), |
90
|
|
|
'Watchers: ' . $package->getGithub()->getWatchers(), |
91
|
|
|
'Forks: ' . $package->getGithub()->getForks(), |
92
|
|
|
'Open issues: ' . $package->getGithub()->getOpenIssues(), |
93
|
|
|
]); |
94
|
|
|
$output->writeln('<options=bold;fg=yellow>Package language:</> ' . $package->getLanguage()); |
95
|
|
|
$output->writeln('<options=bold;fg=yellow>Package dependents:</> ' . $package->getDependents()); |
96
|
|
|
$output->writeln('<options=bold;fg=yellow>Package suggesters:</> ' . $package->getSuggesters()); |
97
|
|
|
$output->writeln('<options=bold;fg=yellow>Package downloads stat:</>'); |
98
|
|
|
$symfonyStyle->listing([ |
99
|
|
|
'Total: ' . $package->getDownloads()->getTotal(), |
100
|
|
|
'Monthly: ' . $package->getDownloads()->getMonthly(), |
101
|
|
|
'Daily: ' . $package->getDownloads()->getDaily(), |
102
|
|
|
]); |
103
|
|
|
$output->writeln('<options=bold;fg=yellow>Package favers:</> ' . $package->getFavers()); |
104
|
|
|
$output->writeln('<options=bold;fg=yellow>Package authors:</>'); |
105
|
|
|
$authors = []; |
106
|
|
|
if (!empty($package->getMaintainers())) { |
107
|
|
|
foreach ($package->getMaintainers() as $maintainer) { |
108
|
|
|
$authors[] = $maintainer->getName(); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
$symfonyStyle->listing($authors); |
112
|
|
|
|
113
|
|
|
$this->viewVersionHistory($symfonyStyle, $package); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param SymfonyStyle $symfonyStyle |
118
|
|
|
* @param Package $package |
119
|
|
|
*/ |
120
|
|
|
private function viewVersionHistory(SymfonyStyle $symfonyStyle, Package $package) |
121
|
|
|
{ |
122
|
|
|
$versions = ['exit']; |
123
|
|
|
if (!empty($package->getVersions())) { |
124
|
|
|
foreach ($package->getVersions() as $version) { |
125
|
|
|
$versions[] = $version->getVersion(); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
$showVersionsHistory = $symfonyStyle->choice('Do you want to view version history?', $versions, 'exit'); |
130
|
|
|
|
131
|
|
|
if ($showVersionsHistory != 'exit') { |
132
|
|
|
$header = ['Key', 'Value']; |
133
|
|
|
|
134
|
|
|
$authors = []; |
135
|
|
|
/** @var PackageAuthor $author */ |
136
|
|
|
foreach ($package->getVersions()->offsetGet($showVersionsHistory)->getAuthors() as $author) { |
137
|
|
|
$authors[] = "[" . $author->getRole() . "] " . $author->getName() . " (" . $author->getEmail() . ")"; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
$source = "[" . $package->getVersions()->offsetGet($showVersionsHistory)->getSource()->getType() . "] "; |
141
|
|
|
$source .= $package->getVersions()->offsetGet($showVersionsHistory)->getSource()->getUrl(); |
142
|
|
|
|
143
|
|
|
$dist = "[" . $package->getVersions()->offsetGet($showVersionsHistory)->getDist()->getType() . "] "; |
144
|
|
|
$dist .= $package->getVersions()->offsetGet($showVersionsHistory)->getDist()->getUrl(); |
145
|
|
|
|
146
|
|
|
$require = []; |
147
|
|
|
/** @var PackageDependency $dependency */ |
148
|
|
|
foreach ($package->getVersions()->offsetGet($showVersionsHistory)->getRequire() as $dependency) { |
149
|
|
|
$require[] = $dependency->getName() . " => " . $dependency->getVersion(); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
$body = [ |
153
|
|
|
['version', $package->getVersions()->offsetGet($showVersionsHistory)->getVersion()], |
154
|
|
|
['name', $package->getVersions()->offsetGet($showVersionsHistory)->getName()], |
155
|
|
|
['description', $package->getVersions()->offsetGet($showVersionsHistory)->getDescription()], |
156
|
|
|
['type', $package->getVersions()->offsetGet($showVersionsHistory)->getType()], |
157
|
|
|
['time', $package->getVersions()->offsetGet($showVersionsHistory)->getTime()], |
158
|
|
|
['keywords', implode(', ', $package->getVersions()->offsetGet($showVersionsHistory)->getKeywords())], |
159
|
|
|
['homepage', $package->getVersions()->offsetGet($showVersionsHistory)->getHomePage()], |
160
|
|
|
['version_normalized', $package->getVersions()->offsetGet($showVersionsHistory)->getVersionNormalized()], |
161
|
|
|
['license', $package->getVersions()->offsetGet($showVersionsHistory)->getLicense()], |
162
|
|
|
['authors', implode("\n", $authors)], |
163
|
|
|
['source', $source], |
164
|
|
|
['dist', $dist], |
165
|
|
|
['require', implode("\n", $require)], |
166
|
|
|
]; |
167
|
|
|
|
168
|
|
|
$symfonyStyle->table($header, $body); |
169
|
|
|
|
170
|
|
|
$this->viewVersionHistory($symfonyStyle, $package); |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
|