Ejemplo n.º 1
0
 /**
  * Returns the non-root packages selected in the console arguments.
  *
  * @param Args              $args     The console arguments.
  * @param PackageCollection $packages The available packages.
  *
  * @return string[] The package names.
  */
 public static function getPackageNamesWithoutRoot(Args $args, PackageCollection $packages)
 {
     // Display all packages if "all" is set
     if ($args->isOptionSet('all')) {
         return $packages->getInstalledPackageNames();
     }
     $packageNames = array();
     foreach ($args->getOption('package') as $packageName) {
         $packageNames[] = $packageName;
     }
     return $packageNames ?: $packages->getInstalledPackageNames();
 }
Ejemplo n.º 2
0
 public function testArrayAccess()
 {
     $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->assertFalse(isset($this->collection['vendor/package1']));
     $this->assertFalse(isset($this->collection['vendor/package2']));
     $this->assertFalse(isset($this->collection['vendor/root']));
     $this->collection[] = $package1;
     $this->collection[] = $package2;
     $this->collection[] = $rootPackage;
     $this->assertTrue(isset($this->collection['vendor/package1']));
     $this->assertTrue(isset($this->collection['vendor/package2']));
     $this->assertTrue(isset($this->collection['vendor/root']));
     $this->assertSame($rootPackage, $this->collection['vendor/root']);
     $this->assertSame($rootPackage, $this->collection->getRootPackage());
     $this->assertSame($package1, $this->collection['vendor/package1']);
     $this->assertSame($package2, $this->collection['vendor/package2']);
     unset($this->collection['vendor/package1']);
     $this->assertFalse(isset($this->collection['vendor/package1']));
     $this->assertTrue(isset($this->collection['vendor/package2']));
     $this->assertTrue(isset($this->collection['vendor/root']));
 }
 private function initDefaultManager()
 {
     $this->packages->add(new RootPackage($this->rootPackageFile, $this->rootDir));
     $this->packages->add(new Package($this->packageFile1, $this->packageDir1));
     $this->packages->add(new Package($this->packageFile2, $this->packageDir2));
     $this->packages->add(new Package($this->packageFile3, $this->packageDir3));
     $this->manager = new RepositoryManagerImpl($this->environment, $this->repo, $this->packages, $this->packageFileStorage);
 }
Ejemplo n.º 4
0
 /**
  * Handles the "puli map --delete" command.
  *
  * @param Args $args The console arguments.
  *
  * @return int The status code.
  */
 public function handleDelete(Args $args)
 {
     $repositoryPath = Path::makeAbsolute($args->getArgument('path'), $this->currentPath);
     if (!$this->repoManager->hasRootPathMapping($repositoryPath)) {
         throw new RuntimeException(sprintf('The path "%s" is not mapped in the package "%s".', $repositoryPath, $this->packages->getRootPackageName()));
     }
     $this->repoManager->removeRootPathMapping($repositoryPath);
     return 0;
 }
Ejemplo n.º 5
0
 /**
  * Handles the "bind --delete" command.
  *
  * @param Args $args The console arguments.
  *
  * @return int The status code.
  */
 public function handleDelete(Args $args)
 {
     $bindingToRemove = $this->getBindingByUuidPrefix($args->getArgument('uuid'));
     if (!$bindingToRemove->getContainingPackage() instanceof RootPackage) {
         throw new RuntimeException(sprintf('Can only delete bindings from the package "%s".', $this->packages->getRootPackageName()));
     }
     $this->discoveryManager->removeRootBindingDescriptor($bindingToRemove->getUuid());
     return 0;
 }
Ejemplo n.º 6
0
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage Cannot disable bindings in the package "vendor/root".
  */
 public function testDisableBindingFailsIfRoot()
 {
     $args = self::$disableCommand->parseArgs(new StringArgs('ab12'));
     $descriptor = new BindingDescriptor('/path', 'my/type', array(), 'glob');
     $descriptor->load($this->packages->getRootPackage());
     $this->discoveryManager->expects($this->once())->method('findBindings')->with($this->uuid('ab12'))->willReturn(array($descriptor));
     $this->discoveryManager->expects($this->never())->method('disableBinding');
     $this->handler->handleDisable($args, $this->io);
 }
Ejemplo n.º 7
0
 /**
  * Handles the "puli type --delete" command.
  *
  * @param Args $args The console arguments.
  *
  * @return int The status code.
  */
 public function handleDelete(Args $args)
 {
     $typeName = $args->getArgument('name');
     if (!$this->discoveryManager->hasRootTypeDescriptor($typeName)) {
         throw new RuntimeException(sprintf('The type "%s" does not exist in the package "%s".', $typeName, $this->packages->getRootPackageName()));
     }
     $this->discoveryManager->removeRootTypeDescriptor($typeName);
     return 0;
 }
Ejemplo n.º 8
0
 /**
  * @expectedException \RuntimeException
  */
 public function testUpdateTypeFailsIfNoChanges()
 {
     $args = self::$updateCommand->parseArgs(new StringArgs('my/type'));
     $typeDescriptor = new BindingTypeDescriptor('my/type');
     $typeDescriptor->load($this->packages->getRootPackage());
     $this->discoveryManager->expects($this->once())->method('getRootBindingType')->with('my/type')->willReturn($typeDescriptor);
     $this->discoveryManager->expects($this->never())->method('addRootBindingType');
     $this->handler->handleUpdate($args);
 }
 private function initDefaultManager()
 {
     $this->rootPackageFile->addInstallInfo($this->installInfo1);
     $this->rootPackageFile->addInstallInfo($this->installInfo2);
     $this->rootPackageFile->addInstallInfo($this->installInfo3);
     $this->packages->add(new RootPackage($this->rootPackageFile, $this->rootDir));
     $this->packages->add(new Package($this->packageFile1, $this->packageDir1, $this->installInfo1));
     $this->packages->add(new Package($this->packageFile2, $this->packageDir2, $this->installInfo2));
     $this->packages->add(new Package($this->packageFile3, $this->packageDir3, $this->installInfo3));
     $this->manager = new DiscoveryManagerImpl($this->environment, $this->discovery, $this->packages, $this->packageFileStorage, $this->logger);
 }
Ejemplo n.º 10
0
 private function initDefaultManager()
 {
     $conflictMappingRoot1 = new PathMapping('/conflict1', array('res', 'assets'));
     $conflictMappingPackage11 = new PathMapping('/conflict1', array('res', '@vendor/package2:res'));
     $conflictMappingPackage12 = new PathMapping('/conflict2', 'res');
     $conflictMappingPackage21 = new PathMapping('/conflict1', 'res');
     $conflictMappingPackage22 = new PathMapping('/conflict2', 'res');
     $conflictMappingRoot1->load($this->packages->getRootPackage(), $this->packages);
     $conflictMappingPackage11->load($this->packages->get('vendor/package1'), $this->packages);
     $conflictMappingPackage12->load($this->packages->get('vendor/package1'), $this->packages);
     $conflictMappingPackage21->load($this->packages->get('vendor/package2'), $this->packages);
     $conflictMappingPackage22->load($this->packages->get('vendor/package2'), $this->packages);
     $conflict1 = new PathConflict('/conflict1');
     $conflict1->addMappings(array($conflictMappingRoot1, $conflictMappingPackage11, $conflictMappingPackage21));
     $conflict2 = new PathConflict('/conflict2/sub/path');
     $conflict2->addMappings(array($conflictMappingPackage12, $conflictMappingPackage22));
     $this->repoManager->expects($this->any())->method('findPathMappings')->willReturnCallback($this->returnFromMap(array(array($this->packageAndState('vendor/root', PathMappingState::ENABLED), array(new PathMapping('/root/enabled', array('res', 'assets')))), array($this->packageAndState('vendor/package1', PathMappingState::ENABLED), array(new PathMapping('/package1/enabled', array('res', '@vendor/package2:res')))), array($this->packageAndState('vendor/package2', PathMappingState::ENABLED), array(new PathMapping('/package2/enabled', 'res'))), array($this->packageAndState('vendor/root', PathMappingState::NOT_FOUND), array(new PathMapping('/root/not-found', 'res'))), array($this->packageAndState('vendor/package1', PathMappingState::NOT_FOUND), array(new PathMapping('/package1/not-found', 'res'))), array($this->packageAndState('vendor/package2', PathMappingState::NOT_FOUND), array(new PathMapping('/package2/not-found', 'res'))), array($this->packagesAndState(array('vendor/root'), PathMappingState::CONFLICT), array($conflictMappingRoot1)), array($this->packagesAndState(array('vendor/package1'), PathMappingState::CONFLICT), array($conflictMappingPackage11, $conflictMappingPackage12)), array($this->packagesAndState(array('vendor/package2'), PathMappingState::CONFLICT), array($conflictMappingPackage21, $conflictMappingPackage22)), array($this->packagesAndState(array('vendor/root', 'vendor/package1'), PathMappingState::CONFLICT), array($conflictMappingRoot1, $conflictMappingPackage11, $conflictMappingPackage12)), array($this->packagesAndState(array('vendor/root', 'vendor/package2'), PathMappingState::CONFLICT), array($conflictMappingRoot1, $conflictMappingPackage21, $conflictMappingPackage22)), array($this->packagesAndState(array('vendor/package1', 'vendor/package2'), PathMappingState::CONFLICT), array($conflictMappingPackage11, $conflictMappingPackage12, $conflictMappingPackage21, $conflictMappingPackage22)), array($this->packagesAndState(array('vendor/root', 'vendor/package1', 'vendor/package2'), PathMappingState::CONFLICT), array($conflictMappingRoot1, $conflictMappingPackage11, $conflictMappingPackage12, $conflictMappingPackage21, $conflictMappingPackage22)))));
 }
Ejemplo n.º 11
0
 private function renameNonRootPackage(Package $package, $newName)
 {
     $previousInstallInfo = $package->getInstallInfo();
     $installInfo = new InstallInfo($newName, $previousInstallInfo->getInstallPath());
     $installInfo->setInstallerName($previousInstallInfo->getInstallerName());
     foreach ($previousInstallInfo->getDisabledBindingUuids() as $uuid) {
         $installInfo->addDisabledBindingUuid($uuid);
     }
     $this->rootPackageFile->removeInstallInfo($package->getName());
     $this->rootPackageFile->addInstallInfo($installInfo);
     try {
         $this->packageFileStorage->saveRootPackageFile($this->rootPackageFile);
     } catch (Exception $e) {
         $this->rootPackageFile->removeInstallInfo($newName);
         $this->rootPackageFile->addInstallInfo($previousInstallInfo);
         throw $e;
     }
     $this->packages->remove($package->getName());
     $this->packages->add(new Package($package->getPackageFile(), $package->getInstallPath(), $installInfo, $package->getLoadErrors()));
 }
Ejemplo n.º 12
0
 /**
  * Creates a tag manager.
  *
  * @param ProjectEnvironment $environment
  * @param EditableDiscovery  $discovery
  * @param PackageCollection  $packages
  * @param PackageFileStorage $packageFileStorage
  * @param LoggerInterface    $logger
  */
 public function __construct(ProjectEnvironment $environment, EditableDiscovery $discovery, PackageCollection $packages, PackageFileStorage $packageFileStorage, LoggerInterface $logger = null)
 {
     $this->environment = $environment;
     $this->discovery = $discovery;
     $this->packages = $packages;
     $this->packageFileStorage = $packageFileStorage;
     $this->rootPackage = $packages->getRootPackage();
     $this->rootPackageFile = $environment->getRootPackageFile();
     $this->logger = $logger ?: new NullLogger();
 }
Ejemplo n.º 13
0
 /**
  * Creates a repository manager.
  *
  * @param ProjectEnvironment $environment
  * @param EditableRepository $repo
  * @param PackageCollection  $packages
  * @param PackageFileStorage $packageFileStorage
  */
 public function __construct(ProjectEnvironment $environment, EditableRepository $repo, PackageCollection $packages, PackageFileStorage $packageFileStorage)
 {
     $this->environment = $environment;
     $this->dispatcher = $environment->getEventDispatcher();
     $this->repo = $repo;
     $this->config = $environment->getConfig();
     $this->rootDir = $environment->getRootDirectory();
     $this->rootPackage = $packages->getRootPackage();
     $this->rootPackageFile = $environment->getRootPackageFile();
     $this->packages = $packages;
     $this->packageFileStorage = $packageFileStorage;
 }
Ejemplo n.º 14
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('');
         }
     }
 }
Ejemplo n.º 15
0
 /**
  * Creates an override graph for the given packages.
  *
  * @param PackageCollection $packages The packages to load.
  *
  * @return static The created override graph.
  */
 public static function forPackages(PackageCollection $packages)
 {
     $graph = new static($packages->getPackageNames());
     foreach ($packages as $package) {
         foreach ($package->getPackageFile()->getOverriddenPackages() as $overriddenPackage) {
             if ($graph->hasPackageName($overriddenPackage)) {
                 $graph->addEdge($overriddenPackage, $package->getName());
             }
         }
     }
     // Make sure we have numeric, ascending keys here
     $packageOrder = array_values($packages->getRootPackage()->getPackageFile()->getOverrideOrder());
     // Each package overrides the previous one in the list
     for ($i = 1, $l = count($packageOrder); $i < $l; ++$i) {
         $overriddenPackage = $packageOrder[$i - 1];
         $overridingPackage = $packageOrder[$i];
         if ($graph->hasPackageName($overriddenPackage)) {
             $graph->addEdge($overriddenPackage, $overridingPackage);
         }
     }
     return $graph;
 }
Ejemplo n.º 16
0
 public function __construct(RootPackageFileManager $rootPackageFileManager, PackageCollection $packages)
 {
     $this->rootPackageFileManager = $rootPackageFileManager;
     $this->packages = $packages;
     $this->rootPackage = $packages->getRootPackage();
 }
Ejemplo n.º 17
0
 private function makeAbsolute($relativePath, Package $containingPackage, PackageCollection $packages)
 {
     // Reference to install path of other package
     if ('@' !== $relativePath[0] || false === ($pos = strpos($relativePath, ':'))) {
         return $containingPackage->getInstallPath() . '/' . $relativePath;
     }
     $refPackageName = substr($relativePath, 1, $pos - 1);
     if (!$packages->contains($refPackageName)) {
         throw new NoSuchPackageException(sprintf('The package "%s" referenced in the resource path "%s" was not ' . 'found. Maybe the package is not installed?', $refPackageName, $relativePath));
     }
     $refPackage = $packages->get($refPackageName);
     return $refPackage->getInstallPath() . '/' . substr($relativePath, $pos + 1);
 }