/** * {@inheritdoc} */ public function execute() { // sanity check if ($this->bindingDescriptor->isLoaded()) { return; } $typeName = $this->bindingDescriptor->getTypeName(); $typeDescriptor = $this->typeDescriptors->contains($typeName) ? $this->typeDescriptors->getFirst($typeName) : null; $this->bindingDescriptor->load($this->containingPackage, $typeDescriptor); $uuid = $this->bindingDescriptor->getUuid(); if ($this->bindingDescriptors->contains($uuid)) { $this->previousDescriptor = $this->bindingDescriptors->get($uuid); } $this->bindingDescriptors->add($this->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; } }
/** * {@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; } }