コード例 #1
0
    public function markAliasInstalled(RepositoryInterface $repo, MarkAliasInstalledOperation $operation)
    {
        $package = $operation->getPackage();

        $this->installed[] = $package;
        $this->trace[] = (string) $operation;

        if (!$repo->hasPackage($package)) {
            $repo->addPackage($package);
        }
    }
コード例 #2
0
 /**
  * Executes markAliasInstalled operation.
  *
  * @param RepositoryInterface         $repo      repository in which to check
  * @param MarkAliasInstalledOperation $operation operation instance
  */
 public function markAliasInstalled(RepositoryInterface $repo, MarkAliasInstalledOperation $operation)
 {
     $package = $operation->getPackage();
     if (!$repo->hasPackage($package)) {
         $repo->addPackage(clone $package);
     }
 }
コード例 #3
0
ファイル: ShowCommand.php プロジェクト: nicodmf/composer
 /**
  * prints all available versions of this package and highlights the installed one if any
  */
 protected function printVersions(InputInterface $input, OutputInterface $output, PackageInterface $package, RepositoryInterface $installedRepo, RepositoryInterface $repos)
 {
     if ($input->getArgument('version')) {
         $output->writeln('<info>version</info>  : ' . $package->getPrettyVersion());
         return;
     }
     $versions = array();
     foreach ($repos->findPackages($package->getName()) as $version) {
         $versions[$version->getPrettyVersion()] = $version->getVersion();
     }
     uasort($versions, 'version_compare');
     $versions = implode(', ', array_keys(array_reverse($versions)));
     // highlight installed version
     if ($installedRepo->hasPackage($package)) {
         $versions = str_replace($package->getPrettyVersion(), '<info>* ' . $package->getPrettyVersion() . '</info>', $versions);
     }
     $output->writeln('<info>versions</info> : ' . $versions);
 }
コード例 #4
0
ファイル: ManagerController.php プロジェクト: jarves/jarves
 protected function getPackage(RepositoryInterface $installedRepo, RepositoryInterface $repos, $name, $version = null)
 {
     $name = strtolower($name);
     $constraint = null;
     if ($version) {
         $constraint = $this->versionParser->parseConstraints($version);
     }
     $policy = new DefaultPolicy();
     $pool = new Pool('dev');
     $pool->addRepository($repos);
     $matchedPackage = null;
     $versions = array();
     $matches = $pool->whatProvides($name, $constraint);
     foreach ($matches as $index => $package) {
         // skip providers/replacers
         if ($package->getName() !== $name) {
             unset($matches[$index]);
             continue;
         }
         // select an exact match if it is in the installed repo and no specific version was required
         if (null === $version && $installedRepo->hasPackage($package)) {
             $matchedPackage = $package;
         }
         $versions[$package->getPrettyVersion()] = $package->getVersion();
         $matches[$index] = $package->getId();
     }
     // select prefered package according to policy rules
     if (!$matchedPackage && $matches && ($prefered = $policy->selectPreferedPackages($pool, array(), $matches))) {
         $matchedPackage = $pool->literalToPackage($prefered[0]);
     }
     return array($matchedPackage, $versions);
 }
コード例 #5
0
ファイル: ShowCommand.php プロジェクト: aminembarki/composer
 /**
  * prints all available versions of this package and highlights the installed one if any
  */
 protected function printVersions(InputInterface $input, OutputInterface $output, CompletePackageInterface $package, array $versions, RepositoryInterface $installedRepo, RepositoryInterface $repos)
 {
     uasort($versions, 'version_compare');
     $versions = array_keys(array_reverse($versions));
     // highlight installed version
     if ($installedRepo->hasPackage($package)) {
         $installedVersion = $package->getPrettyVersion();
         $key = array_search($installedVersion, $versions);
         if (false !== $key) {
             $versions[$key] = '<info>* ' . $installedVersion . '</info>';
         }
     }
     $versions = implode(', ', $versions);
     $output->writeln('<info>versions</info> : ' . $versions);
 }
コード例 #6
0
ファイル: ShowPackage.php プロジェクト: nectd/nectd-web
 /**
  * Finds a package by name and version if provided.
  *
  * @param RepositoryInterface $installedRepo
  * @param RepositoryInterface $repos
  * @param string              $name
  * @param string|null         $version
  *
  * @throws \InvalidArgumentException
  *
  * @return array [CompletePackageInterface, array of versions]
  */
 protected function getPackage(RepositoryInterface $installedRepo, RepositoryInterface $repos, $name, $version = null)
 {
     $name = strtolower($name);
     $constraint = null;
     if ($version !== null) {
         $constraint = $this->versionParser->parseConstraints($version);
     }
     $policy = new DefaultPolicy();
     $pool = new Pool('dev');
     $pool->addRepository($repos);
     $matchedPackage = null;
     $versions = [];
     $matches = $pool->whatProvides($name, $constraint);
     foreach ($matches as $index => $package) {
         // Skip providers/replacers.
         if ($package->getName() !== $name) {
             unset($matches[$index]);
             continue;
         }
         // Select an exact match if it is in the installed repo and no specific version was required.
         if ($version === null && $installedRepo->hasPackage($package)) {
             $matchedPackage = $package;
         }
         $versions[$package->getPrettyVersion()] = $package->getVersion();
         $matches[$index] = $package->getId();
     }
     // Select prefered package according to policy rules.
     if (!$matchedPackage && !empty($matches) && ($prefered = $policy->selectPreferredPackages($pool, [], $matches))) {
         $matchedPackage = $pool->literalToPackage($prefered[0]);
     }
     // If we have package result, return them.
     if ($matchedPackage) {
         return [$matchedPackage->getName() => ['package' => $matchedPackage, 'versions' => $versions]];
     }
     return null;
 }