/**
  * {@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 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;
     }
 }
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     if (!$this->snapshotTaken) {
         throw new LogicException('takeSnapshot() was not called');
     }
     // Remember for rollback()
     $this->enabledBindingAfter = null;
     if ($this->bindingDescriptors->contains($this->uuid)) {
         $bindingDescriptor = $this->bindingDescriptors->get($this->uuid);
         if ($bindingDescriptor->isEnabled()) {
             // Clone so that rollback() works if the binding is unloaded
             $this->enabledBindingAfter = clone $bindingDescriptor;
         }
     }
     $this->syncBindingUuid($this->enabledBindingBefore, $this->enabledBindingAfter);
 }
 private function loadPackages()
 {
     $this->typeDescriptors = new BindingTypeDescriptorCollection();
     $this->bindingDescriptors = new BindingDescriptorCollection();
     // First load all the types
     foreach ($this->packages as $package) {
         foreach ($package->getPackageFile()->getTypeDescriptors() as $typeDescriptor) {
             $this->loadTypeDescriptor($typeDescriptor, $package)->execute();
         }
     }
     // Then the bindings for the loaded types
     foreach ($this->packages as $package) {
         foreach ($package->getPackageFile()->getBindingDescriptors() as $bindingDescriptor) {
             // This REALLY shouldn't happen
             if ($this->bindingDescriptors->contains($bindingDescriptor->getUuid())) {
                 throw DuplicateBindingException::forUuid($bindingDescriptor->getUuid());
             }
             $this->loadBindingDescriptor($bindingDescriptor, $package)->execute();
         }
     }
 }