/**
  * {@inheritdoc}
  */
 public function rollback()
 {
     if ($this->previousDescriptor) {
         $this->rootModuleFile->addBindingDescriptor($this->previousDescriptor);
     } else {
         $this->rootModuleFile->removeBindingDescriptor($this->bindingDescriptor->getUuid());
     }
 }
 /**
  * {@inheritdoc}
  */
 public function rollback()
 {
     // sanity check
     if (!$this->bindingDescriptor->isLoaded()) {
         return;
     }
     // never fails with the check before
     $this->bindingDescriptor->unload();
     if ($this->previousDescriptor) {
         // never fails
         $this->bindingDescriptors->add($this->previousDescriptor);
     } else {
         // never fails
         $this->bindingDescriptors->remove($this->bindingDescriptor->getUuid());
     }
 }
 public function testFindRootAssetMappings()
 {
     $this->discoveryManager->expects($this->once())->method('findRootBindings')->with($this->webPath('/other/path'))->willReturn(array($this->binding2));
     $expr = Expr::same('/other/path', AssetMapping::SERVER_PATH);
     $expected = new AssetMapping('/other/path', 'target2', '/js', $this->binding2->getUuid());
     $this->assertEquals(array($expected), $this->manager->findRootAssetMappings($expr));
 }
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     // sanity check
     if (!$this->bindingDescriptor->isLoaded()) {
         return;
     }
     $this->containingPackage = $this->bindingDescriptor->getContainingPackage();
     $this->typeDescriptor = $this->bindingDescriptor->getTypeDescriptor();
     $uuid = $this->bindingDescriptor->getUuid();
     // never fails with the check in the beginning
     $this->bindingDescriptor->unload();
     if ($this->bindingDescriptors->contains($uuid) && $this->bindingDescriptor === $this->bindingDescriptors->get($uuid)) {
         // never fails
         $this->bindingDescriptors->remove($uuid);
         $this->wasRemoved = true;
     }
 }
 public function testBuildDiscoveryOnlyIncludesEnabledBindingsOfInstalledPackages()
 {
     $this->initDefaultManager();
     $this->packageFile1->addBindingDescriptor($binding1 = new BindingDescriptor('/path1', 'my/type'));
     $this->packageFile1->addBindingDescriptor($binding2 = new BindingDescriptor('/path2', 'my/type'));
     $this->packageFile1->addBindingDescriptor($binding3 = new BindingDescriptor('/path3', 'my/type'));
     $this->installInfo1->addEnabledBindingUuid($binding2->getUuid());
     $this->installInfo1->addDisabledBindingUuid($binding3->getUuid());
     $this->packageFile1->addTypeDescriptor($bindingType = new BindingTypeDescriptor('my/type'));
     $this->discovery->expects($this->once())->method('defineType')->with($bindingType->toBindingType());
     $this->discovery->expects($this->once())->method('bind')->with('/path2', 'my/type', array(), 'glob');
     $this->manager->buildDiscovery();
 }
Example #6
0
 public static function compareBindingDescriptors(BindingDescriptor $a, BindingDescriptor $b)
 {
     // Make sure that bindings are always printed in the same order
     return strcmp($a->getUuid()->toString(), $b->getUuid()->toString());
 }
 private function bindingToMapping(BindingDescriptor $binding)
 {
     return new AssetMapping(substr($binding->getQuery(), 0, -8), $binding->getParameterValue(DiscoveryUrlGenerator::SERVER_PARAMETER), $binding->getParameterValue(DiscoveryUrlGenerator::PATH_PARAMETER), $binding->getUuid());
 }
Example #8
0
 private function bindingsEqual(BindingDescriptor $binding1, BindingDescriptor $binding2)
 {
     if ($binding1->getUuid() !== $binding2->getUuid()) {
         return false;
     }
     if ($binding1->getTypeName() !== $binding2->getTypeName()) {
         return false;
     }
     if ($binding1->getQuery() !== $binding2->getQuery()) {
         return false;
     }
     if ($binding1->getLanguage() !== $binding2->getLanguage()) {
         return false;
     }
     if ($binding1->getParameterValues() !== $binding2->getParameterValues()) {
         return false;
     }
     return true;
 }
 public function testUuidDependsOnLanguage()
 {
     $descriptor1 = new BindingDescriptor('/path', 'vendor/type', array('param' => 'value'), 'language1');
     $descriptor2 = new BindingDescriptor('/path', 'vendor/type', array('param' => 'value'), 'language2');
     $this->assertNotEquals($descriptor1->getUuid(), $descriptor2->getUuid());
 }
 private function syncBindingUuid(BindingDescriptor $enabledBefore = null, BindingDescriptor $enabledAfter = null)
 {
     if (!$enabledBefore && $enabledAfter) {
         $this->discovery->addBinding($enabledAfter->getBinding());
     } elseif ($enabledBefore && !$enabledAfter) {
         $this->discovery->removeBinding($enabledBefore->getUuid());
     }
 }
Example #11
0
 public function testHasBindingDescriptor()
 {
     $packageFile = new PackageFile();
     $binding = new BindingDescriptor('/path', 'my/type');
     $this->assertFalse($packageFile->hasBindingDescriptor($binding->getUuid()));
     $packageFile->addBindingDescriptor($binding);
     $this->assertTrue($packageFile->hasBindingDescriptor($binding->getUuid()));
 }
Example #12
0
 /**
  * Adds a binding descriptor.
  *
  * @param BindingDescriptor $descriptor The binding descriptor to add.
  */
 public function addBindingDescriptor(BindingDescriptor $descriptor)
 {
     $this->bindingDescriptors[$descriptor->getUuid()->toString()] = $descriptor;
 }
Example #13
0
 /**
  * {@inheritdoc}
  */
 public function rollback()
 {
     $this->discovery->removeBinding($this->bindingDescriptor->getUuid());
 }
 private function bindingToMapping(BindingDescriptor $binding)
 {
     return new AssetMapping(substr($binding->getQuery(), 0, -8), $binding->getParameterValue(AssetPlugin::TARGET_PARAMETER), $binding->getParameterValue(AssetPlugin::PATH_PARAMETER), $binding->getUuid());
 }
Example #15
0
 /**
  * {@inheritdoc}
  */
 public function addRootBindingDescriptor(BindingDescriptor $bindingDescriptor, $flags = 0)
 {
     $this->assertModulesLoaded();
     $typeName = $bindingDescriptor->getTypeName();
     $typeExists = $this->typeDescriptors->contains($typeName);
     if (!($flags & self::IGNORE_TYPE_NOT_FOUND) && !$typeExists) {
         throw NoSuchTypeException::forTypeName($typeName);
     }
     if (!($flags & self::IGNORE_TYPE_NOT_ENABLED) && $typeExists && !$this->typeDescriptors->getFirst($typeName)->isEnabled()) {
         throw TypeNotEnabledException::forTypeName($typeName);
     }
     $uuid = $bindingDescriptor->getUuid();
     $exists = $this->bindingDescriptors->contains($uuid);
     $existsInNonRoot = $exists ? !$this->bindingDescriptors->get($uuid)->getContainingModule() instanceof RootModule : false;
     // We can only override bindings in the root module
     if ($existsInNonRoot || $exists && !($flags & self::OVERRIDE)) {
         throw DuplicateBindingException::forUuid($uuid);
     }
     $tx = new Transaction();
     try {
         $syncOp = $this->syncBindingUuid($uuid);
         $syncOp->takeSnapshot();
         $tx->execute($this->loadBindingDescriptor($bindingDescriptor, $this->rootModule));
         $this->assertBindingValid($bindingDescriptor);
         $tx->execute($this->addBindingDescriptorToModuleFile($bindingDescriptor));
         $tx->execute($syncOp);
         $this->saveRootModuleFile();
         $tx->commit();
     } catch (Exception $e) {
         $tx->rollback();
         throw $e;
     }
 }
 /**
  * Adds a binding descriptor.
  *
  * @param BindingDescriptor $bindingDescriptor The binding descriptor.
  */
 public function add(BindingDescriptor $bindingDescriptor)
 {
     $this->map[$bindingDescriptor->getUuid()->toString()] = $bindingDescriptor;
 }
 /**
  * {@inheritdoc}
  */
 public function addRootBinding(BindingDescriptor $bindingDescriptor, $flags = 0)
 {
     $this->assertPackagesLoaded();
     $typeName = $bindingDescriptor->getTypeName();
     $typeExists = $this->typeDescriptors->contains($typeName);
     if (!($flags & self::IGNORE_TYPE_NOT_FOUND) && !$typeExists) {
         throw NoSuchTypeException::forTypeName($typeName);
     }
     if (!($flags & self::IGNORE_TYPE_NOT_ENABLED) && $typeExists && !$this->typeDescriptors->getFirst($typeName)->isEnabled()) {
         throw TypeNotEnabledException::forTypeName($typeName);
     }
     $uuid = $bindingDescriptor->getUuid();
     if ($this->bindingDescriptors->contains($uuid)) {
         throw DuplicateBindingException::forUuid($uuid);
     }
     $tx = new Transaction();
     try {
         $syncOp = $this->syncBindingUuid($uuid);
         $syncOp->takeSnapshot();
         $tx->execute($this->loadBindingDescriptor($bindingDescriptor, $this->rootPackage));
         $this->assertBindingValid($bindingDescriptor);
         $tx->execute($this->addBindingDescriptorToPackageFile($bindingDescriptor));
         $tx->execute($syncOp);
         $this->saveRootPackageFile();
         $tx->commit();
     } catch (Exception $e) {
         $tx->rollback();
         throw $e;
     }
 }
Example #18
0
 public function testDisableBinding()
 {
     $args = self::$disableCommand->parseArgs(new StringArgs('ab12'));
     $descriptor = new BindingDescriptor('/path', 'my/type', array(), 'glob');
     $descriptor->load($this->packages->get('vendor/package1'));
     $this->discoveryManager->expects($this->once())->method('findBindings')->with($this->uuid('ab12'))->willReturn(array($descriptor));
     $this->discoveryManager->expects($this->once())->method('disableBinding')->with($descriptor->getUuid());
     $statusCode = $this->handler->handleDisable($args, $this->io);
     $this->assertSame(0, $statusCode);
     $this->assertEmpty($this->io->fetchOutput());
     $this->assertEmpty($this->io->fetchErrors());
 }