コード例 #1
0
 public function testToArray()
 {
     $packageFile1 = new PackageFile('vendor/package1');
     $package1 = new Package($packageFile1, '/path1');
     $packageFile2 = new PackageFile('vendor/package2');
     $package2 = new Package($packageFile2, '/path2');
     $rootPackageFile = new RootPackageFile('vendor/root');
     $rootPackage = new RootPackage($rootPackageFile, '/path3');
     $this->collection->add($package1);
     $this->collection->add($rootPackage);
     $this->collection->add($package2);
     $this->assertSame(array('vendor/package1' => $package1, 'vendor/root' => $rootPackage, 'vendor/package2' => $package2), $this->collection->toArray());
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function removePackages(Expression $expr)
 {
     $this->assertPackagesLoaded();
     $installInfos = $this->rootPackageFile->getInstallInfos();
     $packages = $this->packages->toArray();
     foreach ($this->packages->getInstalledPackages() as $package) {
         if ($package->match($expr)) {
             $this->rootPackageFile->removeInstallInfo($package->getName());
             $this->packages->remove($package->getName());
         }
     }
     if (!$installInfos) {
         return;
     }
     try {
         $this->packageFileStorage->saveRootPackageFile($this->rootPackageFile);
     } catch (Exception $e) {
         $this->rootPackageFile->setInstallInfos($installInfos);
         $this->packages->replace($packages);
         throw $e;
     }
 }
コード例 #3
0
 /**
  * Prints packages with intermediate headers for the package states.
  *
  * @param IO                $io       The I/O.
  * @param PackageCollection $packages The packages to print.
  * @param int[]             $states   The states to print.
  */
 private function printPackagesByState(IO $io, PackageCollection $packages, array $states)
 {
     $printStates = count($states) > 1;
     foreach ($states as $state) {
         $filteredPackages = array_filter($packages->toArray(), function (Package $package) use($state) {
             return $state === $package->getState();
         });
         if (0 === count($filteredPackages)) {
             continue;
         }
         if ($printStates) {
             $this->printPackageState($io, $state);
         }
         if (PackageState::NOT_LOADABLE === $state) {
             $this->printNotLoadablePackages($io, $filteredPackages, $printStates);
         } else {
             $styleTag = PackageState::ENABLED === $state ? null : 'bad';
             $this->printPackageTable($io, $filteredPackages, $styleTag, $printStates);
         }
         if ($printStates) {
             $io->writeLine('');
         }
     }
 }