Ejemplo n.º 1
0
 public function testCreateWithParameters()
 {
     $descriptor = new InstallerDescriptor('symlink', self::SYMLINK_CLASS, null, array($param1 = new InstallerParameter('param1'), $param2 = new InstallerParameter('param2')));
     $this->assertSame('symlink', $descriptor->getName());
     $this->assertSame(self::SYMLINK_CLASS, $descriptor->getClassName());
     $this->assertNull($descriptor->getDescription());
     $this->assertSame(array('param1' => $param1, 'param2' => $param2), $descriptor->getParameters());
 }
 /**
  * Returns whether the given parameter values are valid.
  *
  * @param array $parameterValues          The parameter values to
  *                                        validate.
  * @param InstallerDescriptor $descriptor The installer descriptor to
  *                                        validate the values for.
  *
  * @return ConstraintViolation[] The found violations. If no violations were
  *                               found, an empty array is returned.
  */
 public function validate(array $parameterValues, InstallerDescriptor $descriptor)
 {
     $violations = array();
     foreach ($parameterValues as $name => $value) {
         if (!$descriptor->hasParameter($name)) {
             $violations[] = new ConstraintViolation(ConstraintViolation::NO_SUCH_PARAMETER, $value, $descriptor->getName(), $name);
         }
     }
     foreach ($descriptor->getParameters() as $parameter) {
         if (!isset($parameterValues[$parameter->getName()])) {
             if ($parameter->isRequired()) {
                 $violations[] = new ConstraintViolation(ConstraintViolation::MISSING_PARAMETER, $parameterValues, $descriptor->getName(), $parameter->getName());
             }
         }
     }
     return $violations;
 }
 /**
  * {@inheritdoc}
  */
 public function addRootInstallerDescriptor(InstallerDescriptor $descriptor)
 {
     $this->assertInstallersLoaded();
     $name = $descriptor->getName();
     $previouslySetInRoot = isset($this->rootInstallerDescriptors[$name]);
     $previousInstaller = $previouslySetInRoot ? $this->rootInstallerDescriptors[$name] : null;
     if (isset($this->installerDescriptors[$name]) && !$previouslySetInRoot) {
         throw new RuntimeException(sprintf('An installer with the name "%s" exists already.', $name));
     }
     try {
         $this->installerDescriptors[$name] = $descriptor;
         $this->rootInstallerDescriptors[$name] = $descriptor;
         $this->persistInstallersData();
     } catch (Exception $e) {
         if ($previouslySetInRoot) {
             $this->installerDescriptors[$name] = $previousInstaller;
             $this->rootInstallerDescriptors[$name] = $previousInstaller;
         } else {
             unset($this->installerDescriptors[$name]);
             unset($this->rootInstallerDescriptors[$name]);
         }
         throw $e;
     }
 }
Ejemplo n.º 4
0
 private function loadInstaller(InstallerDescriptor $descriptor)
 {
     $installerName = $descriptor->getName();
     if (!isset($this->installers[$installerName])) {
         $installerClass = $descriptor->getClassName();
         $this->validateInstallerClass($installerClass);
         $this->installers[$installerName] = new $installerClass();
     }
     return $this->installers[$installerName];
 }