2011-12-07 16:09:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Command;
|
|
|
|
|
2011-12-12 21:47:41 +00:00
|
|
|
use Composer\Composer;
|
|
|
|
use Composer\Package\PackageInterface;
|
2011-12-07 16:09:01 +00:00
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Robert Schönthal <seroscho@googlemail.com>
|
2011-12-12 21:47:41 +00:00
|
|
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
2011-12-07 16:09:01 +00:00
|
|
|
*/
|
|
|
|
class ShowCommand extends Command
|
|
|
|
{
|
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
$this
|
|
|
|
->setName('show')
|
|
|
|
->setDescription('show package details')
|
|
|
|
->setDefinition(array(
|
|
|
|
new InputArgument('package', InputArgument::REQUIRED, 'the package to inspect'),
|
|
|
|
new InputArgument('version', InputArgument::OPTIONAL, 'the version'),
|
|
|
|
))
|
|
|
|
->setHelp(<<<EOT
|
|
|
|
The show command displays detailed information about a package
|
|
|
|
<info>php composer.phar show composer/composer master-dev</info>
|
|
|
|
|
|
|
|
EOT
|
|
|
|
)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
2011-12-12 21:47:41 +00:00
|
|
|
$composer = $this->getComposer();
|
|
|
|
$package = $this->getPackage($input, $output, $composer);
|
|
|
|
if (!$package) {
|
|
|
|
throw new \InvalidArgumentException('no package found');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->printMeta($input, $output, $package, $composer);
|
|
|
|
$this->printLinks($input, $output, $package, 'requires');
|
|
|
|
$this->printLinks($input, $output, $package, 'recommends');
|
|
|
|
$this->printLinks($input, $output, $package, 'replaces');
|
2011-12-07 16:09:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* finds a package by name and version if provided
|
2011-12-12 21:47:41 +00:00
|
|
|
*
|
2011-12-07 16:09:01 +00:00
|
|
|
* @param InputInterface $input
|
|
|
|
* @return PackageInterface
|
2011-12-12 21:47:41 +00:00
|
|
|
* @throws \InvalidArgumentException
|
2011-12-07 16:09:01 +00:00
|
|
|
*/
|
2011-12-12 21:47:41 +00:00
|
|
|
protected function getPackage(InputInterface $input, OutputInterface $output, Composer $composer)
|
2011-12-07 16:09:01 +00:00
|
|
|
{
|
2011-12-12 21:47:41 +00:00
|
|
|
// we have a name and a version so we can use ::findPackage
|
2011-12-07 16:09:01 +00:00
|
|
|
if ($input->getArgument('version')) {
|
|
|
|
return $composer->getRepositoryManager()->findPackage($input->getArgument('package'), $input->getArgument('version'));
|
|
|
|
}
|
2011-12-12 21:47:41 +00:00
|
|
|
|
|
|
|
// check if we have a local installation so we can grab the right package/version
|
|
|
|
$localRepo = $composer->getRepositoryManager()->getLocalRepository();
|
2011-12-07 16:09:01 +00:00
|
|
|
foreach ($localRepo->getPackages() as $package) {
|
|
|
|
if ($package->getName() === $input->getArgument('package')) {
|
|
|
|
return $package;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-12 21:47:41 +00:00
|
|
|
// we only have a name, so search for the first package where the name matches
|
2011-12-07 16:09:01 +00:00
|
|
|
foreach ($composer->getRepositoryManager()->getRepositories() as $repository) {
|
|
|
|
foreach ($repository->getPackages() as $package) {
|
2011-12-12 21:47:41 +00:00
|
|
|
if ($package->getName() === $input->getArgument('package')) {
|
2011-12-07 16:09:01 +00:00
|
|
|
return $package;
|
|
|
|
}
|
|
|
|
}
|
2011-12-12 21:47:41 +00:00
|
|
|
}
|
2011-12-07 16:09:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* prints package meta data
|
|
|
|
*/
|
2011-12-12 21:47:41 +00:00
|
|
|
protected function printMeta(InputInterface $input, OutputInterface $output, PackageInterface $package, Composer $composer)
|
2011-12-07 16:09:01 +00:00
|
|
|
{
|
2011-12-12 21:47:41 +00:00
|
|
|
$output->writeln('<info>name</info> : ' . $package->getPrettyName());
|
|
|
|
$this->printVersions($input, $output, $package, $composer);
|
|
|
|
$output->writeln('<info>type</info> : ' . $package->getType());
|
|
|
|
$output->writeln('<info>names</info> : ' . join(', ', $package->getNames()));
|
|
|
|
$output->writeln('<info>source</info> : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getSourceType(), $package->getSourceUrl(), $package->getSourceReference()));
|
|
|
|
$output->writeln('<info>dist</info> : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getDistType(), $package->getDistUrl(), $package->getDistReference()));
|
|
|
|
$output->writeln('<info>licence</info> : ' . join(', ', $package->getLicense()));
|
|
|
|
|
|
|
|
if ($package->getAutoload()) {
|
|
|
|
$output->writeln("\n<info>autoload</info>");
|
|
|
|
foreach ($package->getAutoload() as $type => $autoloads) {
|
|
|
|
$output->writeln('<comment>' . $type . '</comment>');
|
|
|
|
|
2011-12-07 16:09:01 +00:00
|
|
|
foreach ($autoloads as $name => $path) {
|
2011-12-12 21:47:41 +00:00
|
|
|
$output->writeln($name . ' : ' . ($path ?: '.'));
|
2011-12-07 16:09:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* prints all available versions of this package and highlights the installed one if any
|
|
|
|
*/
|
2011-12-12 21:47:41 +00:00
|
|
|
protected function printVersions(InputInterface $input, OutputInterface $output, PackageInterface $package, Composer $composer)
|
2011-12-07 16:09:01 +00:00
|
|
|
{
|
|
|
|
if ($input->getArgument('version')) {
|
2011-12-12 21:47:41 +00:00
|
|
|
$output->writeln('<info>version</info> : ' . $package->getPrettyVersion());
|
2011-12-07 16:09:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-12-12 21:47:41 +00:00
|
|
|
|
2011-12-07 16:09:01 +00:00
|
|
|
$versions = array();
|
|
|
|
|
2011-12-12 21:47:41 +00:00
|
|
|
foreach ($composer->getRepositoryManager()->getRepositories() as $repository) {
|
|
|
|
foreach ($repository->getPackages() as $version) {
|
|
|
|
if ($version->getName() === $package->getName()) {
|
|
|
|
$versions[] = $version->getPrettyVersion();
|
2011-12-07 16:09:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-12 21:47:41 +00:00
|
|
|
$versions = join(', ', $versions);
|
|
|
|
|
|
|
|
// highlight installed version
|
|
|
|
if ($composer->getRepositoryManager()->getLocalRepository()->hasPackage($package)) {
|
|
|
|
$versions = str_replace($package->getPrettyVersion(), '<info>* ' . $package->getPrettyVersion() . '</info>', $versions);
|
|
|
|
}
|
2011-12-07 16:09:01 +00:00
|
|
|
|
2011-12-12 21:47:41 +00:00
|
|
|
$output->writeln('<info>versions</info> : ' . $versions);
|
2011-12-07 16:09:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* print link objects
|
2011-12-12 21:47:41 +00:00
|
|
|
*
|
|
|
|
* @param string $linkType
|
2011-12-07 16:09:01 +00:00
|
|
|
*/
|
2011-12-12 21:47:41 +00:00
|
|
|
protected function printLinks(InputInterface $input, OutputInterface $output, PackageInterface $package, $linkType)
|
2011-12-07 16:09:01 +00:00
|
|
|
{
|
2011-12-12 21:47:41 +00:00
|
|
|
if ($links = $package->{'get'.ucfirst($linkType)}()) {
|
|
|
|
$output->writeln("\n<info>" . $linkType . "</info>");
|
2011-12-07 16:09:01 +00:00
|
|
|
|
2011-12-12 21:47:41 +00:00
|
|
|
foreach ($links as $link) {
|
|
|
|
$output->writeln($link->getTarget() . ' <comment>' . $link->getPrettyConstraint() . '</comment>');
|
2011-12-07 16:09:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|