Exemplo n.º 1
0
 /**
  * @param CompletePackageInterface $package
  *
  * @return Package
  */
 public static function createFromComposerPackage(CompletePackageInterface $package)
 {
     $class = new self();
     $class->type = $package->getType();
     $class->name = $package->getPrettyName();
     $class->description = $package->getDescription();
     $class->authors = $package->getAuthors();
     $class->keywords = $package->getKeywords();
     if ($package->getVersion() === '9999999-dev') {
         $class->version = sprintf('%s (%s)', $package->getPrettyVersion(), substr($package->getSourceReference(), 0, 6));
     } else {
         $class->version = $package->getPrettyVersion();
     }
     return $class;
 }
Exemplo n.º 2
0
 /**
  * Convert the data of a complete package to the passed json array.
  *
  * @param CompletePackageInterface $package The package to process.
  *
  * @param JsonArray                $data    The json array to push the data to.
  *
  * @return void
  */
 private function convertCompletePackage(CompletePackageInterface $package, $data)
 {
     $data->set('description', $package->getDescription());
     $data->set('license', $package->getLicense());
     if ($keywords = $package->getKeywords()) {
         $data->set('keywords', $keywords);
     }
     if ($homepage = $package->getHomepage()) {
         $data->set('homepage', $homepage);
     }
     if ($authors = $package->getAuthors()) {
         $data->set('authors', $authors);
     }
     if ($support = $package->getSupport()) {
         $data->set('support', $support);
     }
     if ($extra = $package->getExtra()) {
         $data->set('extra', $extra);
     }
     $data->set('abandoned', $package->isAbandoned());
     if ($package->isAbandoned()) {
         $data->set('replacement', $package->getReplacementPackage());
     }
 }
Exemplo n.º 3
0
 /**
  * tries to find a token within the name/keywords/description
  *
  * @param  CompletePackageInterface $package
  * @param  string                   $token
  * @return boolean
  */
 private function matchPackage(CompletePackageInterface $package, $token)
 {
     $score = 0;
     if (false !== stripos($package->getName(), $token)) {
         $score += 5;
     }
     if (!$this->onlyName && false !== stripos(join(',', $package->getKeywords() ?: array()), $token)) {
         $score += 3;
     }
     if (!$this->onlyName && false !== stripos($package->getDescription(), $token)) {
         $score += 1;
     }
     return $score;
 }
Exemplo n.º 4
0
 /**
  * prints package meta data
  */
 protected function printMeta(InputInterface $input, OutputInterface $output, CompletePackageInterface $package, array $versions, RepositoryInterface $installedRepo, RepositoryInterface $repos)
 {
     $output->writeln('<info>name</info>     : ' . $package->getPrettyName());
     $output->writeln('<info>descrip.</info> : ' . $package->getDescription());
     $output->writeln('<info>keywords</info> : ' . join(', ', $package->getKeywords() ?: array()));
     $this->printVersions($input, $output, $package, $versions, $installedRepo, $repos);
     $output->writeln('<info>type</info>     : ' . $package->getType());
     $output->writeln('<info>license</info>  : ' . implode(', ', $package->getLicense()));
     $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>names</info>    : ' . implode(', ', $package->getNames()));
     if ($package->getSupport()) {
         $output->writeln("\n<info>support</info>");
         foreach ($package->getSupport() as $type => $value) {
             $output->writeln('<comment>' . $type . '</comment> : ' . $value);
         }
     }
     if ($package->getAutoload()) {
         $output->writeln("\n<info>autoload</info>");
         foreach ($package->getAutoload() as $type => $autoloads) {
             $output->writeln('<comment>' . $type . '</comment>');
             if ($type === 'psr-0') {
                 foreach ($autoloads as $name => $path) {
                     $output->writeln(($name ?: '*') . ' => ' . (is_array($path) ? implode(', ', $path) : ($path ?: '.')));
                 }
             } elseif ($type === 'psr-4') {
                 foreach ($autoloads as $name => $path) {
                     $output->writeln(($name ?: '*') . ' => ' . (is_array($path) ? implode(', ', $path) : ($path ?: '.')));
                 }
             } elseif ($type === 'classmap') {
                 $output->writeln(implode(', ', $autoloads));
             }
         }
         if ($package->getIncludePaths()) {
             $output->writeln('<comment>include-path</comment>');
             $output->writeln(implode(', ', $package->getIncludePaths()));
         }
     }
 }
Exemplo n.º 5
0
 /**
  * Prints package metadata.
  *
  * @param CompletePackageInterface $package
  * @param array                    $versions
  * @param RepositoryInterface      $installedRepo
  */
 protected function printMeta(CompletePackageInterface $package, array $versions, RepositoryInterface $installedRepo, PackageInterface $latestPackage = null)
 {
     $io = $this->getIO();
     $io->write('<info>name</info>     : ' . $package->getPrettyName());
     $io->write('<info>descrip.</info> : ' . $package->getDescription());
     $io->write('<info>keywords</info> : ' . join(', ', $package->getKeywords() ?: array()));
     $this->printVersions($package, $versions, $installedRepo);
     if ($latestPackage) {
         $style = $this->getVersionStyle($latestPackage, $package);
         $io->write('<info>latest</info>   : <' . $style . '>' . $latestPackage->getPrettyVersion() . '</' . $style . '>');
     } else {
         $latestPackage = $package;
     }
     $io->write('<info>type</info>     : ' . $package->getType());
     $this->printLicenses($package);
     $io->write('<info>source</info>   : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getSourceType(), $package->getSourceUrl(), $package->getSourceReference()));
     $io->write('<info>dist</info>     : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getDistType(), $package->getDistUrl(), $package->getDistReference()));
     $io->write('<info>names</info>    : ' . implode(', ', $package->getNames()));
     if ($latestPackage->isAbandoned()) {
         $replacement = $latestPackage->getReplacementPackage() !== null ? ' The author suggests using the ' . $latestPackage->getReplacementPackage() . ' package instead.' : null;
         $io->writeError(sprintf('<warning>Attention: This package is abandoned and no longer maintained.%s</warning>', $replacement));
     }
     if ($package->getSupport()) {
         $io->write("\n<info>support</info>");
         foreach ($package->getSupport() as $type => $value) {
             $io->write('<comment>' . $type . '</comment> : ' . $value);
         }
     }
     if ($package->getAutoload()) {
         $io->write("\n<info>autoload</info>");
         foreach ($package->getAutoload() as $type => $autoloads) {
             $io->write('<comment>' . $type . '</comment>');
             if ($type === 'psr-0') {
                 foreach ($autoloads as $name => $path) {
                     $io->write(($name ?: '*') . ' => ' . (is_array($path) ? implode(', ', $path) : ($path ?: '.')));
                 }
             } elseif ($type === 'psr-4') {
                 foreach ($autoloads as $name => $path) {
                     $io->write(($name ?: '*') . ' => ' . (is_array($path) ? implode(', ', $path) : ($path ?: '.')));
                 }
             } elseif ($type === 'classmap') {
                 $io->write(implode(', ', $autoloads));
             }
         }
         if ($package->getIncludePaths()) {
             $io->write('<comment>include-path</comment>');
             $io->write(implode(', ', $package->getIncludePaths()));
         }
     }
 }