Exemplo n.º 1
0
 private function dumpWeb(array $packages, OutputInterface $output, PackageInterface $rootPackage, $directory)
 {
     $templateDir = __DIR__ . '/../../../../views';
     $loader = new \Twig_Loader_Filesystem($templateDir);
     $twig = new \Twig_Environment($loader);
     $mappedPackages = $this->getMappedPackageList($packages);
     $name = $rootPackage->getPrettyName();
     if ($name === '__root__') {
         $name = 'A';
         $output->writeln('Define a "name" property in your json config to name the repository');
     }
     if (!$rootPackage->getHomepage()) {
         $output->writeln('Define a "homepage" property in your json config to configure the repository URL');
     }
     $output->writeln('<info>Writing web view</info>');
     $content = $twig->render('index.html.twig', array('name' => $name, 'url' => $rootPackage->getHomepage(), 'description' => $rootPackage->getDescription(), 'packages' => $mappedPackages));
     file_put_contents($directory . '/index.html', $content);
 }
Exemplo n.º 2
0
 /**
  * prints package meta data
  */
 protected function printMeta(InputInterface $input, OutputInterface $output, PackageInterface $package, 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, $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 ?: '*') . ' => ' . ($path ?: '.'));
                 }
             } elseif ($type === 'classmap') {
                 $output->writeln(implode(', ', $autoloads));
             }
         }
         if ($package->getIncludePaths()) {
             $output->writeln('<comment>include-path</comment>');
             $output->writeln(implode(', ', $package->getIncludePaths()));
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Display the tree
  *
  * @param PackageInterface|string $package
  * @param RepositoryInterface     $installedRepo
  * @param RepositoryInterface     $distantRepos
  */
 protected function displayPackageTree(PackageInterface $package, RepositoryInterface $installedRepo, RepositoryInterface $distantRepos)
 {
     $io = $this->getIO();
     $io->write(sprintf('<info>%s</info>', $package->getPrettyName()), false);
     $io->write(' ' . $package->getPrettyVersion(), false);
     $io->write(' ' . strtok($package->getDescription(), "\r\n"));
     if (is_object($package)) {
         $requires = $package->getRequires();
         $treeBar = '├';
         $j = 0;
         $total = count($requires);
         foreach ($requires as $requireName => $require) {
             $j++;
             if ($j == 0) {
                 $this->writeTreeLine($treeBar);
             }
             if ($j == $total) {
                 $treeBar = '└';
             }
             $level = 1;
             $color = $this->colors[$level];
             $info = sprintf('%s──<%s>%s</%s> %s', $treeBar, $color, $requireName, $color, $require->getPrettyConstraint());
             $this->writeTreeLine($info);
             $treeBar = str_replace('└', ' ', $treeBar);
             $packagesInTree = array($package->getName(), $requireName);
             $this->displayTree($requireName, $require, $installedRepo, $distantRepos, $packagesInTree, $treeBar, $level + 1);
         }
     }
 }
Exemplo n.º 4
0
 /**
  * tries to find a token within the name/keywords/description
  *
  * @param  PackageInterface $package
  * @param  string           $token
  * @return boolean
  */
 private function matchPackage(PackageInterface $package, $token)
 {
     $score = 0;
     if (false !== stripos($package->getName(), $token)) {
         $score += 5;
     }
     if (false !== stripos(join(',', $package->getKeywords() ?: array()), $token)) {
         $score += 3;
     }
     if (false !== stripos($package->getDescription(), $token)) {
         $score += 1;
     }
     return $score;
 }
Exemplo n.º 5
0
 private function updateInformation(Package $package, PackageInterface $data, $flags)
 {
     $em = $this->doctrine->getManager();
     $version = new Version();
     $normVersion = $data->getVersion();
     $existingVersion = $package->getVersion($normVersion);
     if ($existingVersion) {
         $source = $existingVersion->getSource();
         // update if the right flag is set, or the source reference has changed (re-tag or new commit on branch)
         if ($source['reference'] !== $data->getSourceReference() || $flags & self::UPDATE_EQUAL_REFS) {
             $version = $existingVersion;
         } else {
             // mark it updated to avoid it being pruned
             $existingVersion->setUpdatedAt(new \DateTime());
             return false;
         }
     }
     $version->setName($package->getName());
     $version->setVersion($data->getPrettyVersion());
     $version->setNormalizedVersion($normVersion);
     $version->setDevelopment($data->isDev());
     $em->persist($version);
     $descr = $this->sanitize($data->getDescription());
     $version->setDescription($descr);
     $package->setDescription($descr);
     $version->setHomepage($data->getHomepage());
     $version->setLicense($data->getLicense() ?: array());
     $version->setPackage($package);
     $version->setUpdatedAt(new \DateTime());
     $version->setReleasedAt($data->getReleaseDate());
     if ($data->getSourceType()) {
         $source['type'] = $data->getSourceType();
         $source['url'] = $data->getSourceUrl();
         $source['reference'] = $data->getSourceReference();
         $version->setSource($source);
     } else {
         $version->setSource(null);
     }
     if ($data->getDistType()) {
         $dist['type'] = $data->getDistType();
         $dist['url'] = $data->getDistUrl();
         $dist['reference'] = $data->getDistReference();
         $dist['shasum'] = $data->getDistSha1Checksum();
         $version->setDist($dist);
     } else {
         $version->setDist(null);
     }
     if ($data->getType()) {
         $type = $this->sanitize($data->getType());
         $version->setType($type);
         if ($type !== $package->getType()) {
             $package->setType($type);
         }
     }
     $version->setTargetDir($data->getTargetDir());
     $version->setAutoload($data->getAutoload());
     $version->setExtra($data->getExtra());
     $version->setBinaries($data->getBinaries());
     $version->setIncludePaths($data->getIncludePaths());
     $version->setSupport($data->getSupport());
     if ($data->getKeywords()) {
         $keywords = array();
         foreach ($data->getKeywords() as $keyword) {
             $keywords[mb_strtolower($keyword, 'UTF-8')] = $keyword;
         }
         $existingTags = [];
         foreach ($version->getTags() as $tag) {
             $existingTags[mb_strtolower($tag->getName(), 'UTF-8')] = $tag;
         }
         foreach ($keywords as $tagKey => $keyword) {
             if (isset($existingTags[$tagKey])) {
                 unset($existingTags[$tagKey]);
                 continue;
             }
             $tag = Tag::getByName($em, $keyword, true);
             if (!$version->getTags()->contains($tag)) {
                 $version->addTag($tag);
             }
         }
         foreach ($existingTags as $tag) {
             $version->getTags()->removeElement($tag);
         }
     } elseif (count($version->getTags())) {
         $version->getTags()->clear();
     }
     $authorRepository = $this->doctrine->getRepository('PackagistWebBundle:Author');
     $version->getAuthors()->clear();
     if ($data->getAuthors()) {
         foreach ($data->getAuthors() as $authorData) {
             $author = null;
             foreach (array('email', 'name', 'homepage', 'role') as $field) {
                 if (isset($authorData[$field])) {
                     $authorData[$field] = trim($authorData[$field]);
                     if ('' === $authorData[$field]) {
                         $authorData[$field] = null;
                     }
                 } else {
                     $authorData[$field] = null;
                 }
             }
             // skip authors with no information
             if (!isset($authorData['email']) && !isset($authorData['name'])) {
                 continue;
             }
             $author = $authorRepository->findOneBy(array('email' => $authorData['email'], 'name' => $authorData['name'], 'homepage' => $authorData['homepage'], 'role' => $authorData['role']));
             if (!$author) {
                 $author = new Author();
                 $em->persist($author);
             }
             foreach (array('email', 'name', 'homepage', 'role') as $field) {
                 if (isset($authorData[$field])) {
                     $author->{'set' . $field}($authorData[$field]);
                 }
             }
             // only update the author timestamp once a month at most as the value is kinda unused
             if ($author->getUpdatedAt() === null || $author->getUpdatedAt()->getTimestamp() < time() - 86400 * 30) {
                 $author->setUpdatedAt(new \DateTime());
             }
             if (!$version->getAuthors()->contains($author)) {
                 $version->addAuthor($author);
             }
             if (!$author->getVersions()->contains($version)) {
                 $author->addVersion($version);
             }
         }
     }
     // handle links
     foreach ($this->supportedLinkTypes as $linkType => $opts) {
         $links = array();
         foreach ($data->{$opts['method']}() as $link) {
             $constraint = $link->getPrettyConstraint();
             if (false !== strpos($constraint, ',') && false !== strpos($constraint, '@')) {
                 $constraint = preg_replace_callback('{([><]=?\\s*[^@]+?)@([a-z]+)}i', function ($matches) {
                     if ($matches[2] === 'stable') {
                         return $matches[1];
                     }
                     return $matches[1] . '-' . $matches[2];
                 }, $constraint);
             }
             $links[$link->getTarget()] = $constraint;
         }
         foreach ($version->{'get' . $linkType}() as $link) {
             // clear links that have changed/disappeared (for updates)
             if (!isset($links[$link->getPackageName()]) || $links[$link->getPackageName()] !== $link->getPackageVersion()) {
                 $version->{'get' . $linkType}()->removeElement($link);
                 $em->remove($link);
             } else {
                 // clear those that are already set
                 unset($links[$link->getPackageName()]);
             }
         }
         foreach ($links as $linkPackageName => $linkPackageVersion) {
             $class = 'Packagist\\WebBundle\\Entity\\' . $opts['entity'];
             $link = new $class();
             $link->setPackageName($linkPackageName);
             $link->setPackageVersion($linkPackageVersion);
             $version->{'add' . $linkType . 'Link'}($link);
             $link->setVersion($version);
             $em->persist($link);
         }
     }
     // handle suggests
     if ($suggests = $data->getSuggests()) {
         foreach ($version->getSuggest() as $link) {
             // clear links that have changed/disappeared (for updates)
             if (!isset($suggests[$link->getPackageName()]) || $suggests[$link->getPackageName()] !== $link->getPackageVersion()) {
                 $version->getSuggest()->removeElement($link);
                 $em->remove($link);
             } else {
                 // clear those that are already set
                 unset($suggests[$link->getPackageName()]);
             }
         }
         foreach ($suggests as $linkPackageName => $linkPackageVersion) {
             $link = new SuggestLink();
             $link->setPackageName($linkPackageName);
             $link->setPackageVersion($linkPackageVersion);
             $version->addSuggestLink($link);
             $link->setVersion($version);
             $em->persist($link);
         }
     } elseif (count($version->getSuggest())) {
         // clear existing suggests if present
         foreach ($version->getSuggest() as $link) {
             $em->remove($link);
         }
         $version->getSuggest()->clear();
     }
     if (!$package->getVersions()->contains($version)) {
         $package->addVersions($version);
     }
     return true;
 }
Exemplo n.º 6
0
 private function updateInformation(Package $package, PackageInterface $data, $flags)
 {
     $em = $this->doctrine->getEntityManager();
     $version = new Version();
     $version->setNormalizedVersion($data->getVersion());
     // check if we have that version yet
     foreach ($package->getVersions() as $existingVersion) {
         if ($existingVersion->getNormalizedVersion() === $version->getNormalizedVersion()) {
             if ($existingVersion->getDevelopment() || $flags & self::UPDATE_TAGS) {
                 $version = $existingVersion;
                 break;
             }
             // mark it updated to avoid it being pruned
             $existingVersion->setUpdatedAt(new \DateTime());
             return;
         }
     }
     $version->setName($package->getName());
     $version->setVersion($data->getPrettyVersion());
     $version->setDevelopment($data->isDev());
     $em->persist($version);
     $version->setDescription($data->getDescription());
     $package->setDescription($data->getDescription());
     $version->setHomepage($data->getHomepage());
     $version->setLicense($data->getLicense() ?: array());
     $version->setPackage($package);
     $version->setUpdatedAt(new \DateTime());
     $version->setReleasedAt($data->getReleaseDate());
     if ($data->getSourceType()) {
         $source['type'] = $data->getSourceType();
         $source['url'] = $data->getSourceUrl();
         $source['reference'] = $data->getSourceReference();
         $version->setSource($source);
     }
     if ($data->getDistType()) {
         $dist['type'] = $data->getDistType();
         $dist['url'] = $data->getDistUrl();
         $dist['reference'] = $data->getDistReference();
         $dist['shasum'] = $data->getDistSha1Checksum();
         $version->setDist($dist);
     }
     if ($data->getType()) {
         $version->setType($data->getType());
         if ($data->getType() && $data->getType() !== $package->getType()) {
             $package->setType($data->getType());
         }
     }
     $version->setTargetDir($data->getTargetDir());
     $version->setAutoload($data->getAutoload());
     $version->setExtra($data->getExtra());
     $version->setBinaries($data->getBinaries());
     $version->setIncludePaths($data->getIncludePaths());
     $version->setSupport($data->getSupport());
     $version->getTags()->clear();
     if ($data->getKeywords()) {
         foreach ($data->getKeywords() as $keyword) {
             $tag = Tag::getByName($em, $keyword, true);
             if (!$version->getTags()->contains($tag)) {
                 $version->addTag($tag);
             }
         }
     }
     $authorRepository = $this->doctrine->getRepository('PackagistWebBundle:Author');
     $version->getAuthors()->clear();
     if ($data->getAuthors()) {
         foreach ($data->getAuthors() as $authorData) {
             $author = null;
             // skip authors with no information
             if (empty($authorData['email']) && empty($authorData['name'])) {
                 continue;
             }
             if (!empty($authorData['email'])) {
                 $author = $authorRepository->findOneByEmail($authorData['email']);
             }
             if (!$author && !empty($authorData['homepage'])) {
                 $author = $authorRepository->findOneBy(array('name' => $authorData['name'], 'homepage' => $authorData['homepage']));
             }
             if (!$author && !empty($authorData['name'])) {
                 $author = $authorRepository->findOneByNameAndPackage($authorData['name'], $package);
             }
             if (!$author) {
                 $author = new Author();
                 $em->persist($author);
             }
             foreach (array('email', 'name', 'homepage', 'role') as $field) {
                 if (isset($authorData[$field])) {
                     $author->{'set' . $field}($authorData[$field]);
                 }
             }
             $author->setUpdatedAt(new \DateTime());
             if (!$version->getAuthors()->contains($author)) {
                 $version->addAuthor($author);
             }
             if (!$author->getVersions()->contains($version)) {
                 $author->addVersion($version);
             }
         }
     }
     // handle links
     foreach ($this->supportedLinkTypes as $linkType => $opts) {
         $links = array();
         foreach ($data->{$opts['method']}() as $link) {
             $constraint = $link->getPrettyConstraint();
             if (false !== strpos($constraint, '~')) {
                 $constraint = str_replace(array('[', ']'), '', $link->getConstraint());
                 $constraint = preg_replace('{(\\d\\.\\d)(\\.0)+(?=$|,|-)}', '$1', $constraint);
                 $constraint = preg_replace('{([><=,]) }', '$1', $constraint);
                 $constraint = preg_replace('{(<[0-9.]+)-dev}', '$1', $constraint);
             }
             if (false !== strpos($constraint, ',') && false !== strpos($constraint, '@')) {
                 $constraint = preg_replace_callback('{([><]=?\\s*[^@]+?)@([a-z]+)}i', function ($matches) {
                     if ($matches[2] === 'stable') {
                         return $matches[1];
                     }
                     return $matches[1] . '-' . $matches[2];
                 }, $constraint);
             }
             $links[$link->getTarget()] = $constraint;
         }
         foreach ($version->{'get' . $linkType}() as $link) {
             // clear links that have changed/disappeared (for updates)
             if (!isset($links[$link->getPackageName()]) || $links[$link->getPackageName()] !== $link->getPackageVersion()) {
                 $version->{'get' . $linkType}()->removeElement($link);
                 $em->remove($link);
             } else {
                 // clear those that are already set
                 unset($links[$link->getPackageName()]);
             }
         }
         foreach ($links as $linkPackageName => $linkPackageVersion) {
             $class = 'Packagist\\WebBundle\\Entity\\' . $opts['entity'];
             $link = new $class();
             $link->setPackageName($linkPackageName);
             $link->setPackageVersion($linkPackageVersion);
             $version->{'add' . $linkType . 'Link'}($link);
             $link->setVersion($version);
             $em->persist($link);
         }
     }
     // handle suggests
     if ($suggests = $data->getSuggests()) {
         foreach ($version->getSuggest() as $link) {
             // clear links that have changed/disappeared (for updates)
             if (!isset($suggests[$link->getPackageName()]) || $suggests[$link->getPackageName()] !== $link->getPackageVersion()) {
                 $version->getSuggest()->removeElement($link);
                 $em->remove($link);
             } else {
                 // clear those that are already set
                 unset($suggests[$link->getPackageName()]);
             }
         }
         foreach ($suggests as $linkPackageName => $linkPackageVersion) {
             $link = new SuggestLink();
             $link->setPackageName($linkPackageName);
             $link->setPackageVersion($linkPackageVersion);
             $version->addSuggestLink($link);
             $link->setVersion($version);
             $em->persist($link);
         }
     }
     if (!$package->getVersions()->contains($version)) {
         $package->addVersions($version);
     }
 }
Exemplo n.º 7
0
 private function updateInformation(OutputInterface $output, RegistryInterface $doctrine, $package, PackageInterface $data)
 {
     $em = $doctrine->getEntityManager();
     $version = new Version();
     $version->setName($package->getName());
     $version->setNormalizedVersion(preg_replace('{-dev$}i', '', $data->getVersion()));
     // check if we have that version yet
     foreach ($package->getVersions() as $existingVersion) {
         if ($existingVersion->equals($version)) {
             // avoid updating newer versions, in case two branches have the same version in their composer.json
             if ($existingVersion->getReleasedAt() > $data->getReleaseDate()) {
                 return;
             }
             if ($existingVersion->getDevelopment()) {
                 $version = $existingVersion;
                 break;
             }
             return;
         }
     }
     $version->setVersion($data->getPrettyVersion());
     $version->setDevelopment(substr($data->getVersion(), -4) === '-dev');
     $em->persist($version);
     $version->setDescription($data->getDescription());
     $package->setDescription($data->getDescription());
     $version->setHomepage($data->getHomepage());
     $version->setLicense($data->getLicense() ?: array());
     $version->setPackage($package);
     $version->setUpdatedAt(new \DateTime());
     $version->setReleasedAt($data->getReleaseDate());
     if ($data->getSourceType()) {
         $source['type'] = $data->getSourceType();
         $source['url'] = $data->getSourceUrl();
         $source['reference'] = $data->getSourceReference();
         $version->setSource($source);
     }
     if ($data->getDistType()) {
         $dist['type'] = $data->getDistType();
         $dist['url'] = $data->getDistUrl();
         $dist['reference'] = $data->getDistReference();
         $dist['shasum'] = $data->getDistSha1Checksum();
         $version->setDist($dist);
     }
     if ($data->getType()) {
         $version->setType($data->getType());
         if ($data->getType() && $data->getType() !== $package->getType()) {
             $package->setType($data->getType());
         }
     }
     $version->setTargetDir($data->getTargetDir());
     $version->setAutoload($data->getAutoload());
     $version->setExtra($data->getExtra());
     $version->setBinaries($data->getBinaries());
     $version->getTags()->clear();
     if ($data->getKeywords()) {
         foreach ($data->getKeywords() as $keyword) {
             $version->addTag(Tag::getByName($em, $keyword, true));
         }
     }
     $version->getAuthors()->clear();
     if ($data->getAuthors()) {
         foreach ($data->getAuthors() as $authorData) {
             $author = null;
             // skip authors with no information
             if (empty($authorData['email']) && empty($authorData['name'])) {
                 continue;
             }
             if (!empty($authorData['email'])) {
                 $author = $doctrine->getRepository('PackagistWebBundle:Author')->findOneByEmail($authorData['email']);
             }
             if (!$author && !empty($authorData['homepage'])) {
                 $author = $doctrine->getRepository('PackagistWebBundle:Author')->findOneBy(array('name' => $authorData['name'], 'homepage' => $authorData['homepage']));
             }
             if (!$author && !empty($authorData['name'])) {
                 $author = $doctrine->getRepository('PackagistWebBundle:Author')->findOneByNameAndPackage($authorData['name'], $package);
             }
             if (!$author) {
                 $author = new Author();
                 $em->persist($author);
             }
             foreach (array('email', 'name', 'homepage') as $field) {
                 if (isset($authorData[$field])) {
                     $author->{'set' . $field}($authorData[$field]);
                 }
             }
             $author->setUpdatedAt(new \DateTime());
             if (!$version->getAuthors()->contains($author)) {
                 $version->addAuthor($author);
             }
             if (!$author->getVersions()->contains($version)) {
                 $author->addVersion($version);
             }
         }
     }
     foreach ($this->supportedLinkTypes as $linkType => $linkEntity) {
         $links = array();
         foreach ($data->{'get' . $linkType . 's'}() as $link) {
             $links[$link->getTarget()] = $link->getPrettyConstraint();
         }
         foreach ($version->{'get' . $linkType}() as $link) {
             // clear links that have changed/disappeared (for updates)
             if (!isset($links[$link->getPackageName()]) || $links[$link->getPackageName()] !== $link->getPackageVersion()) {
                 $version->{'get' . $linkType}()->removeElement($link);
                 $em->remove($link);
             } else {
                 // clear those that are already set
                 unset($links[$link->getPackageName()]);
             }
         }
         foreach ($links as $linkPackageName => $linkPackageVersion) {
             $class = 'Packagist\\WebBundle\\Entity\\' . $linkEntity;
             $link = new $class();
             $link->setPackageName($linkPackageName);
             $link->setPackageVersion($linkPackageVersion);
             $version->{'add' . $linkType . 'Link'}($link);
             $link->setVersion($version);
             $em->persist($link);
         }
     }
     if (!$package->getVersions()->contains($version)) {
         $package->addVersions($version);
     }
 }
Exemplo n.º 8
0
 public function getDescription()
 {
     return $this->aliasOf->getDescription();
 }
Exemplo n.º 9
0
 /**
  * tries to find a token within the name/keywords/description
  *
  * @param PackageInterface $package
  * @param string $token
  * @return boolean
  */
 private function matchPackage(PackageInterface $package, $token)
 {
     return false !== stripos($package->getName(), $token) || false !== stripos(join(',', $package->getKeywords() ?: array()), $token) || false !== stripos($package->getDescription(), $token);
 }