/**
  * Adds a package to the collection.
  *
  * @param Package $package The added package.
  */
 public function add(Package $package)
 {
     $this->packages[$package->getName()] = $package;
     if ($package instanceof RootPackage) {
         $this->rootPackage = $package;
     }
 }
 /**
  * {@inheritdoc}
  */
 public function rollback()
 {
     if (!$this->mapping->isLoaded()) {
         return;
     }
     $packageName = $this->containingPackage->getName();
     $this->mappings->remove($this->mapping->getRepositoryPath(), $packageName);
     foreach ($this->mapping->listRepositoryPaths() as $repositoryPath) {
         $this->mappingsByResource->remove($repositoryPath, $packageName);
         $this->conflictDetector->release($repositoryPath, $packageName);
     }
     // Unload after iterating, otherwise the paths are gone
     $this->mapping->unload();
 }
 /**
  * {@inheritdoc}
  */
 public function rollback()
 {
     // sanity check
     if (!$this->typeDescriptor->isLoaded()) {
         return;
     }
     $typeName = $this->typeDescriptor->getTypeName();
     // never fails with the check before
     $this->typeDescriptor->unload();
     if ($this->previousDescriptor && $this->previousDescriptor->isLoaded()) {
         // never fails
         $this->typeDescriptors->add($this->previousDescriptor);
     } else {
         // never fails
         $this->typeDescriptors->remove($typeName, $this->containingPackage->getName());
     }
 }
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     // sanity check
     if (!$this->typeDescriptor->isLoaded()) {
         return;
     }
     // never fails with the check before
     $this->containingPackage = $this->typeDescriptor->getContainingPackage();
     $typeName = $this->typeDescriptor->getTypeName();
     $packageName = $this->containingPackage->getName();
     // never fails with the check before
     $this->typeDescriptor->unload();
     if ($this->typeDescriptors->contains($typeName, $packageName) && $this->typeDescriptor === $this->typeDescriptors->get($typeName, $packageName)) {
         // never fails
         $this->typeDescriptors->remove($typeName, $packageName);
         $this->wasRemoved = true;
     }
 }
 public function testMatch()
 {
     $type = new BindingTypeDescriptor('vendor/type');
     $type->load($this->package);
     $this->assertFalse($type->match(Expr::same('foobar', BindingTypeDescriptor::NAME)));
     $this->assertTrue($type->match(Expr::same('vendor/type', BindingTypeDescriptor::NAME)));
     $this->assertFalse($type->match(Expr::same('foobar', BindingTypeDescriptor::CONTAINING_PACKAGE)));
     $this->assertTrue($type->match(Expr::same($this->package->getName(), BindingTypeDescriptor::CONTAINING_PACKAGE)));
     $this->assertFalse($type->match(Expr::same(BindingTypeState::DUPLICATE, BindingTypeDescriptor::STATE)));
     $this->assertTrue($type->match(Expr::same(BindingTypeState::ENABLED, BindingTypeDescriptor::STATE)));
 }
Example #6
0
 public function testMatch()
 {
     $mapping = new PathMapping('/path', 'resources');
     $mapping->load($this->package1, $this->packages);
     $this->assertFalse($mapping->match(Expr::same('foobar', PathMapping::CONTAINING_PACKAGE)));
     $this->assertTrue($mapping->match(Expr::same($this->package1->getName(), PathMapping::CONTAINING_PACKAGE)));
     $this->assertFalse($mapping->match(Expr::same(PathMappingState::CONFLICT, PathMapping::STATE)));
     $this->assertTrue($mapping->match(Expr::same(PathMappingState::ENABLED, PathMapping::STATE)));
     $this->assertFalse($mapping->match(Expr::startsWith('/foo', PathMapping::REPOSITORY_PATH)));
     $this->assertTrue($mapping->match(Expr::startsWith('/pa', PathMapping::REPOSITORY_PATH)));
 }
 /**
  * {@inheritdoc}
  */
 public function rollback()
 {
     if ($this->mapping->isLoaded() || !$this->containingPackage) {
         return;
     }
     $this->mapping->load($this->containingPackage, $this->packages);
     $packageName = $this->containingPackage->getName();
     foreach ($this->mapping->listRepositoryPaths() as $repositoryPath) {
         $this->mappings->add($this->mapping);
         $this->conflictDetector->claim($repositoryPath, $packageName);
     }
     // Restore conflicts
     foreach ($this->conflicts as $repositoryPath => $conflict) {
         $conflict->addMappings($this->conflictingMappings[$repositoryPath]);
     }
 }
 private function refreshState()
 {
     if (null === $this->typeDescriptor || !$this->typeDescriptor->isLoaded()) {
         $this->state = BindingState::TYPE_NOT_FOUND;
     } elseif (!$this->typeDescriptor->isEnabled()) {
         $this->state = BindingState::TYPE_NOT_ENABLED;
     } elseif (count($this->loadErrors) > 0) {
         $this->state = BindingState::INVALID;
     } elseif ($this->containingPackage instanceof RootPackage) {
         $this->state = BindingState::ENABLED;
     } elseif ($this->containingPackage->getInstallInfo()->hasDisabledBindingUuid($this->binding->getUuid())) {
         $this->state = BindingState::DISABLED;
     } else {
         $this->state = BindingState::ENABLED;
     }
 }
Example #9
0
 public function testMatch()
 {
     $type = new BindingTypeDescriptor('vendor/type', null, array(new BindingParameterDescriptor('param')));
     $type->load($this->package);
     $uuid = Uuid::fromString('abcdb814-9dad-11d1-80b4-00c04fd430c8');
     $binding = new BindingDescriptor('/path', 'vendor/type', array('param' => 'value'), 'glob', $uuid);
     $binding->load($this->package, $type);
     $this->assertFalse($binding->match(Expr::same('foobar', BindingDescriptor::CONTAINING_PACKAGE)));
     $this->assertTrue($binding->match(Expr::same($this->package->getName(), BindingDescriptor::CONTAINING_PACKAGE)));
     $this->assertFalse($binding->match(Expr::same(BindingState::DISABLED, BindingDescriptor::STATE)));
     $this->assertTrue($binding->match(Expr::same(BindingState::ENABLED, BindingDescriptor::STATE)));
     $this->assertFalse($binding->match(Expr::startsWith('abce', BindingDescriptor::UUID)));
     $this->assertTrue($binding->match(Expr::startsWith('abcd', BindingDescriptor::UUID)));
     $this->assertFalse($binding->match(Expr::same('/path/nested', BindingDescriptor::QUERY)));
     $this->assertTrue($binding->match(Expr::same('/path', BindingDescriptor::QUERY)));
     $this->assertFalse($binding->match(Expr::same('xpath', BindingDescriptor::LANGUAGE)));
     $this->assertTrue($binding->match(Expr::same('glob', BindingDescriptor::LANGUAGE)));
     $this->assertFalse($binding->match(Expr::same('vendor/other', BindingDescriptor::TYPE_NAME)));
     $this->assertTrue($binding->match(Expr::same('vendor/type', BindingDescriptor::TYPE_NAME)));
     $this->assertFalse($binding->match(Expr::key(BindingDescriptor::PARAMETER_VALUES, Expr::key('param', Expr::same('foobar')))));
     $this->assertTrue($binding->match(Expr::key(BindingDescriptor::PARAMETER_VALUES, Expr::key('param', Expr::same('value')))));
 }
Example #10
0
 private function assertFileExists($absolutePath, $relativePath, Package $containingPackage)
 {
     if (!file_exists($absolutePath)) {
         throw new FileNotFoundException(sprintf('The path %s mapped to %s by package "%s" does not exist.', $relativePath, $this->repositoryPath, $containingPackage->getName()));
     }
 }
 private function renameNonRootPackage(Package $package, $newName)
 {
     $previousInstallInfo = $package->getInstallInfo();
     $installInfo = new InstallInfo($newName, $previousInstallInfo->getInstallPath());
     $installInfo->setInstallerName($previousInstallInfo->getInstallerName());
     foreach ($previousInstallInfo->getEnabledBindingUuids() as $uuid) {
         $installInfo->addEnabledBindingUuid($uuid);
     }
     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()));
 }
Example #12
0
 public function testMatch()
 {
     $packageFile = new PackageFile('vendor/name');
     $package = new Package($packageFile, __DIR__);
     $this->assertFalse($package->match(Expr::same('foobar', Package::NAME)));
     $this->assertTrue($package->match(Expr::same('vendor/name', Package::NAME)));
     $this->assertFalse($package->match(Expr::same('/path/foo', Package::INSTALL_PATH)));
     $this->assertTrue($package->match(Expr::same(__DIR__, Package::INSTALL_PATH)));
     $this->assertFalse($package->match(Expr::same(PackageState::NOT_LOADABLE, Package::STATE)));
     $this->assertTrue($package->match(Expr::same(PackageState::ENABLED, Package::STATE)));
     $this->assertFalse($package->match(Expr::same('webmozart', Package::INSTALLER)));
     $installInfo = new InstallInfo('vendor/install-info', '/path');
     $installInfo->setInstallerName('webmozart');
     $packageWithInstallInfo = new Package($packageFile, __DIR__, $installInfo);
     $this->assertFalse($packageWithInstallInfo->match(Expr::same('foobar', Package::INSTALLER)));
     $this->assertTrue($packageWithInstallInfo->match(Expr::same('webmozart', Package::INSTALLER)));
 }
 private function loadInstallers(Package $package)
 {
     foreach (self::$builtinInstallers as $name => $installerData) {
         $installer = $this->dataToInstaller($name, (object) $installerData);
         $this->installerDescriptors[$name] = $installer;
     }
     $packageFile = $package->getPackageFile();
     if (!$packageFile) {
         return;
     }
     $packageName = $package->getName();
     $installersData = $packageFile->getExtraKey(self::INSTALLERS_KEY);
     if (!$installersData) {
         return;
     }
     $jsonValidator = new JsonValidator();
     $errors = $jsonValidator->validate($installersData, __DIR__ . '/../../res/schema/installers-schema-1.0.json');
     if (count($errors) > 0) {
         throw new ValidationFailedException(sprintf("The extra key \"%s\" of package \"%s\" is invalid:\n%s", self::INSTALLERS_KEY, $packageName, implode("\n", $errors)));
     }
     foreach ($installersData as $name => $installerData) {
         $installer = $this->dataToInstaller($name, $installerData);
         $this->installerDescriptors[$name] = $installer;
         if ($package instanceof RootPackage) {
             $this->rootInstallerDescriptors[$name] = $installer;
         }
     }
 }
 /**
  * Returns whether the binding type matches the given expression.
  *
  * @param Expression $expr The search criteria. You can use the fields
  *                         {@link NAME}, {@link PARAMETERS},
  *                         {@link STATE} and {@link CONTAINING_PACKAGE}
  *                         in the expression.
  *
  * @return bool Returns `true` if the binding type matches the expression
  *              and `false` otherwise.
  */
 public function match(Expression $expr)
 {
     return $expr->evaluate(array(self::NAME => $this->name, self::STATE => $this->state, self::CONTAINING_PACKAGE => $this->containingPackage->getName()));
 }
Example #15
0
 public function testMatch()
 {
     $packageFile = new PackageFile('vendor/name');
     $package = new Package($packageFile, __DIR__);
     $this->assertFalse($package->match(Expr::same('foobar', Package::NAME)));
     $this->assertTrue($package->match(Expr::same('vendor/name', Package::NAME)));
     $this->assertFalse($package->match(Expr::same('/path/foo', Package::INSTALL_PATH)));
     $this->assertTrue($package->match(Expr::same(__DIR__, Package::INSTALL_PATH)));
     $this->assertFalse($package->match(Expr::same(PackageState::NOT_LOADABLE, Package::STATE)));
     $this->assertTrue($package->match(Expr::same(PackageState::ENABLED, Package::STATE)));
     $this->assertFalse($package->match(Expr::same('webmozart', Package::INSTALLER)));
     // Packages without install info (= the root package) are assumed to be
     // installed in the production environment
     $this->assertTrue($package->match(Expr::same(Environment::PROD, Package::ENVIRONMENT)));
     $installInfo = new InstallInfo('vendor/install-info', '/path');
     $installInfo->setInstallerName('webmozart');
     $packageWithInstallInfo = new Package($packageFile, __DIR__, $installInfo);
     $this->assertFalse($packageWithInstallInfo->match(Expr::same('foobar', Package::INSTALLER)));
     $this->assertTrue($packageWithInstallInfo->match(Expr::same('webmozart', Package::INSTALLER)));
     $this->assertTrue($packageWithInstallInfo->match(Expr::notsame(Environment::DEV, Package::ENVIRONMENT)));
     $installInfo2 = new InstallInfo('vendor/install-info', '/path');
     $installInfo2->setEnvironment(Environment::DEV);
     $packageWithInstallInfo2 = new Package($packageFile, __DIR__, $installInfo2);
     $this->assertTrue($packageWithInstallInfo2->match(Expr::same(Environment::DEV, Package::ENVIRONMENT)));
 }