/**
  * {@inheritdoc}
  */
 public function rollback()
 {
     if ($this->previousDescriptor) {
         $this->rootModuleFile->addBindingDescriptor($this->previousDescriptor);
     } else {
         $this->rootModuleFile->removeBindingDescriptor($this->bindingDescriptor->getUuid());
     }
 }
 /**
  * {@inheritdoc}
  */
 public function rollback()
 {
     if ($this->bindingDescriptor->isLoaded() || !$this->containingPackage || !$this->typeDescriptor) {
         return;
     }
     // never fails with the check before, given that the type name of
     // the description/type didn't changed, which is impossible since
     // they're immutable
     $this->bindingDescriptor->load($this->containingPackage, $this->typeDescriptor);
     if ($this->wasRemoved) {
         // never fails
         $this->bindingDescriptors->add($this->bindingDescriptor);
     }
 }
 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 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 testWritePackageFileWritesDefaultParameterValuesOfBindings()
 {
     $packageFile = new PackageFile();
     $package = new Package($packageFile, '/path', new InstallInfo('vendor/package', '/path'));
     // We need to create a type and a binding in state ENABLED
     $bindingType = new BindingTypeDescriptor('my/type', null, array(new BindingParameterDescriptor('param', BindingParameterDescriptor::OPTIONAL, 'default')));
     $bindingType->load($package);
     $binding = new BindingDescriptor('/app/config*.yml', 'my/type', array(), 'glob', Uuid::fromString(self::BINDING_UUID1));
     $binding->load($package, $bindingType);
     // The default value is accessible
     $this->assertSame('default', $binding->getParameterValue('param'));
     // But not written by the writer
     $packageFile->addBindingDescriptor($binding);
     $this->writer->writePackageFile($packageFile, $this->tempFile);
     $this->assertFileExists($this->tempFile);
     $this->assertJsonFileEquals(__DIR__ . '/Fixtures/json/binding-no-default-params.json', $this->tempFile);
 }
 /**
  * Unloads and loads a binding descriptor.
  *
  * The descriptor is remembered and reloaded again in {@link postRollback()}
  * if the intercepted operation needs to be rolled back.
  *
  * @param BindingDescriptor $bindingDescriptor The descriptor to reload.
  */
 protected function reloadBindingDescriptor(BindingDescriptor $bindingDescriptor)
 {
     if (!$bindingDescriptor->isLoaded()) {
         return;
     }
     // Keep backup of containing package before calling unload()
     $containingPackage = $bindingDescriptor->getContainingPackage();
     $typeName = $bindingDescriptor->getTypeName();
     $typeDescriptor = $this->typeDescriptors->getEnabled($typeName);
     // never fails with the check in the beginning
     $bindingDescriptor->unload();
     // never fails after unloading, given that the type name matches
     // (which we can guarantee here)
     $bindingDescriptor->load($containingPackage, $typeDescriptor);
     $this->reloadedDescriptors[] = $bindingDescriptor;
 }
 private function syncBindingUuid(BindingDescriptor $enabledBefore = null, BindingDescriptor $enabledAfter = null)
 {
     if (!$enabledBefore && $enabledAfter) {
         $this->discovery->bind($enabledAfter->getQuery(), $enabledAfter->getTypeName(), $enabledAfter->getParameterValues(), $enabledAfter->getLanguage());
     } elseif ($enabledBefore && !$enabledAfter) {
         $this->discovery->unbind($enabledBefore->getQuery(), $enabledBefore->getTypeName(), $enabledBefore->getParameterValues(), $enabledBefore->getLanguage());
     }
 }
    public function testSerializePackageFileWritesDefaultParameterValuesOfBindings()
    {
        $packageFile = new PackageFile();
        $package = new Package($packageFile, '/path', new InstallInfo('vendor/package', '/path'));
        // We need to create a type and a binding in state ENABLED
        $bindingType = new BindingTypeDescriptor('my/type', null, array(new BindingParameterDescriptor('param', BindingParameterDescriptor::OPTIONAL, 'default')));
        $bindingType->load($package);
        $binding = new BindingDescriptor('/app/config*.yml', 'my/type', array(), 'glob', Uuid::fromString(self::BINDING_UUID1));
        $binding->load($package, $bindingType);
        // The default value is accessible
        $this->assertSame('default', $binding->getParameterValue('param'));
        // But not written by the serializer
        $packageFile->addBindingDescriptor($binding);
        $json = <<<JSON
{
    "version": "1.0",
    "bindings": {
        "2438256b-c2f5-4a06-a18f-f79755e027dd": {
            "query": "/app/config*.yml",
            "type": "my/type"
        }
    }
}

JSON;
        $this->assertJsonEquals($json, $this->serializer->serializePackageFile($packageFile));
    }
 /**
  * {@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());
 }
 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();
 }
Exemple #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;
 }
Exemple #13
0
 private function bindingsEqual(BindingDescriptor $descriptor1, BindingDescriptor $descriptor2)
 {
     return $descriptor1->getBinding() == $descriptor2->getBinding();
 }
Exemple #14
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());
 }
Exemple #15
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;
 }
 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());
 }
Exemple #17
0
 private function assertBindingValid(BindingDescriptor $bindingDescriptor)
 {
     if ($bindingDescriptor->isTypeNotFound() || $bindingDescriptor->isTypeNotEnabled()) {
         return;
     }
     foreach ($bindingDescriptor->getLoadErrors() as $exception) {
         throw $exception;
     }
 }
 /**
  * Adds a binding descriptor.
  *
  * @param BindingDescriptor $bindingDescriptor The binding descriptor.
  */
 public function add(BindingDescriptor $bindingDescriptor)
 {
     $this->map[$bindingDescriptor->getUuid()->toString()] = $bindingDescriptor;
 }
 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');
     $this->package->getInstallInfo()->addEnabledBindingUuid($uuid);
     $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')))));
 }
 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());
     }
 }
Exemple #21
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()));
 }
 private function assertBindingValid(BindingDescriptor $bindingDescriptor)
 {
     if ($bindingDescriptor->isTypeNotFound() || $bindingDescriptor->isTypeNotEnabled()) {
         return;
     }
     foreach ($bindingDescriptor->getViolations() as $violation) {
         switch ($violation->getCode()) {
             case ConstraintViolation::NO_SUCH_PARAMETER:
                 throw NoSuchParameterException::forParameterName($violation->getParameterName(), $violation->getTypeName());
             case ConstraintViolation::MISSING_PARAMETER:
                 throw MissingParameterException::forParameterName($violation->getParameterName(), $violation->getTypeName());
         }
     }
 }
 /**
  * @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);
 }