예제 #1
0
 /**
  * @param string $name
  * @param ConstraintInterface $constraint
  * @return \Composer\Package\PackageInterface
  */
 private function getPackage($name, ConstraintInterface $constraint)
 {
     $package = $this->repository->findPackage($name, $constraint);
     if ($package === NULL) {
         return new ComposerPackage($name, '0.0.0.1', '--no-dev');
     }
     return $package;
 }
예제 #2
0
 /**
  * Convert the information of all packages in a repository to an array used by json API.
  *
  * @param RepositoryInterface      $repository   The repository holding the packages to convert.
  *
  * @param bool                     $requiredOnly If true, return only the packages added to the root package as
  *                                               require.
  *
  * @param null|RepositoryInterface $upgradeList  The packages available as upgrades.
  *
  * @return JsonArray
  */
 public function convertRepositoryToArray(RepositoryInterface $repository, $requiredOnly = false, RepositoryInterface $upgradeList = null)
 {
     $requires = $requiredOnly ? $this->rootPackage->getRequires() : false;
     $packages = new JsonArray();
     /** @var \Composer\Package\PackageInterface $package */
     foreach ($repository->getPackages() as $package) {
         $name = $package->getPrettyName();
         $esc = $packages->escape($name);
         if (false === $requires || isset($requires[$name])) {
             $upgradePkg = null;
             if ($upgradeList) {
                 $upgradePkg = $upgradeList->findPackage($name, '*');
             }
             $packages->set($esc, $this->convertPackageToArray($package, $upgradePkg)->getData());
         }
     }
     return $packages;
 }
예제 #3
0
 /**
  * finds a package by name and version if provided
  *
  * @param  InputInterface            $input
  * @return PackageInterface
  * @throws \InvalidArgumentException
  */
 protected function getPackage(InputInterface $input, OutputInterface $output, RepositoryInterface $installedRepo, RepositoryInterface $repos)
 {
     // we have a name and a version so we can use ::findPackage
     if ($input->getArgument('version')) {
         return $repos->findPackage($input->getArgument('package'), $input->getArgument('version'));
     }
     // check if we have a local installation so we can grab the right package/version
     foreach ($installedRepo->getPackages() as $package) {
         if ($package->getName() === $input->getArgument('package')) {
             return $package;
         }
     }
     // we only have a name, so search for the highest version of the given package
     $highestVersion = null;
     foreach ($repos->findPackages($input->getArgument('package')) as $package) {
         if (null === $highestVersion || version_compare($package->getVersion(), $highestVersion->getVersion(), '>=')) {
             $highestVersion = $package;
         }
     }
     return $highestVersion;
 }
예제 #4
0
 /**
  * @return OperationInterface[] filtered operations, dev packages are uninstalled and all operations on them ignored
  */
 private function filterDevPackageOperations(array $devPackages, array $operations, RepositoryInterface $localRepo)
 {
     $finalOps = array();
     $packagesToSkip = array();
     foreach ($devPackages as $pkg) {
         $packagesToSkip[$pkg->getName()] = true;
         if ($installedDevPkg = $localRepo->findPackage($pkg->getName(), '*')) {
             $finalOps[] = new UninstallOperation($installedDevPkg, 'non-dev install removing it');
         }
     }
     // skip operations applied on dev packages
     foreach ($operations as $op) {
         $package = $op->getJobType() === 'update' ? $op->getTargetPackage() : $op->getPackage();
         if (isset($packagesToSkip[$package->getName()])) {
             continue;
         }
         $finalOps[] = $op;
     }
     return $finalOps;
 }