public function rollback()
 {
     if ($this->previousDescriptor) {
         $this->rootPackageFile->addTypeDescriptor($this->previousDescriptor);
     } else {
         $this->rootPackageFile->removeTypeDescriptor($this->typeDescriptor->getName());
     }
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function rollback()
 {
     // sanity check
     if (!$this->typeDescriptor->isLoaded()) {
         return;
     }
     $typeName = $this->typeDescriptor->getName();
     // 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->getName();
     $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;
     }
 }
 private function unloadTypeDescriptor(BindingTypeDescriptor $typeDescriptor)
 {
     $typeName = $typeDescriptor->getName();
     return new InterceptedOperation(new UnloadTypeDescriptor($typeDescriptor, $this->typeDescriptors), array(new UpdateDuplicateMarksForTypeName($typeName, $this->typeDescriptors), new ReloadBindingDescriptorsByTypeName($typeName, $this->bindingDescriptors, $this->typeDescriptors)));
 }
Beispiel #5
0
 /**
  * Loads the binding descriptor.
  *
  * @param Package               $containingPackage The package that contains
  *                                                 the descriptor.
  * @param BindingTypeDescriptor $typeDescriptor    The type descriptor.
  *
  * @throws AlreadyLoadedException If the descriptor is already loaded.
  */
 public function load(Package $containingPackage, BindingTypeDescriptor $typeDescriptor = null)
 {
     if (null !== $this->state) {
         throw new AlreadyLoadedException('The binding descriptor is already loaded.');
     }
     if ($typeDescriptor && $this->typeName !== $typeDescriptor->getName()) {
         throw new InvalidArgumentException(sprintf('The passed type "%s" does not match the stored type name "%s".', $typeDescriptor->getName(), $this->typeName));
     }
     $this->violations = array();
     if ($typeDescriptor && $typeDescriptor->isLoaded() && $typeDescriptor->isEnabled()) {
         $validator = new SimpleParameterValidator();
         $bindingType = $typeDescriptor->toBindingType();
         $this->violations = $validator->validate($this->parameterValues, $bindingType);
     }
     $this->containingPackage = $containingPackage;
     $this->typeDescriptor = $typeDescriptor;
     $this->refreshState();
 }
 /**
  * @dataProvider getValidNames
  */
 public function testValidName($name)
 {
     $descriptor = new BindingTypeDescriptor($name);
     $this->assertSame($name, $descriptor->getName());
 }
Beispiel #7
0
 private function typesEqual(BindingTypeDescriptor $type1, BindingTypeDescriptor $type2)
 {
     if ($type1->getName() !== $type2->getName()) {
         return false;
     }
     if ($type1->getDescription() !== $type2->getDescription()) {
         return false;
     }
     if ($type1->getParameters() != $type2->getParameters()) {
         return false;
     }
     return true;
 }
Beispiel #8
0
 /**
  * Adds a type descriptor.
  *
  * @param BindingTypeDescriptor $descriptor The type descriptor.
  */
 public function addTypeDescriptor(BindingTypeDescriptor $descriptor)
 {
     $this->typeDescriptors[$descriptor->getName()] = $descriptor;
 }
Beispiel #9
0
 /**
  * {@inheritdoc}
  */
 public function rollback()
 {
     $this->discovery->undefineType($this->typeDescriptor->getName());
 }