public function validateConfiguration(Extension $extension, $configuration) { if (!$configuration) { throw new \LogicException(sprintf('The extension with alias "%s" does not have its getConfiguration() method setup', $extension->getAlias())); } if (!$configuration instanceof ConfigurationInterface) { throw new \LogicException(sprintf('Configuration class "%s" should implement ConfigurationInterface in order to be dumpable', get_class($configuration))); } }
protected function normalizeValue($value) { foreach ($this->normalizeTransformations as $transformation) { list($singular, $plural) = $transformation; if (!isset($value[$singular])) { continue; } $value[$plural] = Extension::normalizeConfig($value, $singular, $plural); } if (null !== $this->prototype) { $normalized = array(); foreach ($value as $k => $v) { if (null !== $this->keyAttribute && is_array($v) && isset($v[$this->keyAttribute])) { $k = $v[$this->keyAttribute]; } $this->prototype->setName($k); if (null !== $this->keyAttribute) { $normalized[$k] = $this->prototype->normalize($v); } else { $normalized[] = $this->prototype->normalize($v); } } return $normalized; } $normalized = array(); foreach ($this->children as $name => $child) { if (!array_key_exists($name, $value)) { continue; } $normalized[$name] = $child->normalize($value[$name]); } return $normalized; }
public function process(NodeInterface $configTree, array $configs) { $configs = Extension::normalizeKeys($configs); $currentConfig = array(); foreach ($configs as $config) { $config = $configTree->normalize($config); $currentConfig = $configTree->merge($currentConfig, $config); } return $configTree->finalize($currentConfig); }
/** * {@inheritDoc} */ public function getAlias() { try { return parent::getAlias(); } catch (BadMethodCallException $e) { $className = get_class($this); if (substr($className, -16) != '\\BundleExtension') { throw $e; } $aliasBaseName = str_replace(array('FancyGuy', '\\Bundle\\', '\\BundleExtension'), array('Fancyguy', '', ''), $className); return Container::underscore($aliasBaseName); } }
protected function normalizeValue($value) { if (false === $value) { return $value; } foreach ($this->xmlRemappings as $transformation) { list($singular, $plural) = $transformation; if (!isset($value[$singular])) { continue; } $value[$plural] = Extension::normalizeConfig($value, $singular, $plural); } if (null !== $this->prototype) { $normalized = array(); foreach ($value as $k => $v) { if (null !== $this->keyAttribute && is_array($v)) { if (!isset($v[$this->keyAttribute]) && is_int($k)) { throw new InvalidConfigurationException(sprintf('You must set a "%s" attribute for path "%s".', $this->keyAttribute, $this->getPath())); } else { if (isset($v[$this->keyAttribute])) { $k = $v[$this->keyAttribute]; } } if (array_key_exists($k, $normalized)) { throw new DuplicateKeyException(sprintf('Duplicate key "%s" for path "%s".', $k, $this->getPath())); } } $this->prototype->setName($k); if (null !== $this->keyAttribute) { $normalized[$k] = $this->prototype->normalize($v); } else { $normalized[] = $this->prototype->normalize($v); } } return $normalized; } $normalized = array(); foreach ($this->children as $name => $child) { if (!array_key_exists($name, $value)) { continue; } $normalized[$name] = $child->normalize($value[$name]); } return $normalized; }
/** * Normalises the value. * * @param mixed $value The value to normalise * @return mixed The normalised value */ protected function normalizeValue($value) { if (false === $value) { return $value; } foreach ($this->xmlRemappings as $transformation) { list($singular, $plural) = $transformation; if (!isset($value[$singular])) { continue; } $value[$plural] = Extension::normalizeConfig($value, $singular, $plural); unset($value[$singular]); } if (null !== $this->prototype) { $normalized = array(); foreach ($value as $k => $v) { if (null !== $this->keyAttribute && is_array($v)) { if (!isset($v[$this->keyAttribute]) && is_int($k)) { throw new InvalidConfigurationException(sprintf('You must set a "%s" attribute for path "%s".', $this->keyAttribute, $this->getPath())); } else { if (isset($v[$this->keyAttribute])) { $k = $v[$this->keyAttribute]; // remove the key attribute if configured to if ($this->removeKeyAttribute) { unset($v[$this->keyAttribute]); } } } if (array_key_exists($k, $normalized)) { throw new DuplicateKeyException(sprintf('Duplicate key "%s" for path "%s".', $k, $this->getPath())); } } $this->prototype->setName($k); if (null !== $this->keyAttribute) { $normalized[$k] = $this->prototype->normalize($v); } else { $normalized[] = $this->prototype->normalize($v); } } return $normalized; } $normalized = array(); foreach ($this->children as $name => $child) { if (!array_key_exists($name, $value)) { continue; } $normalized[$name] = $child->normalize($value[$name]); unset($value[$name]); } // if extra fields are present, throw exception if (count($value) && !$this->ignoreExtraKeys) { $msg = sprintf('Unrecognized options "%s" under "%s"', implode(', ', array_keys($value)), $this->getPath()); throw new InvalidConfigurationException($msg); } return $normalized; }
protected function load($config) { $this->extension->load($config, $this->container); }
/** * Get configuration class and set the extension * * @return Configuration */ public function getConfiguration(array $config, ContainerBuilder $container) { $configuration = parent::getConfiguration($config, $container); $configuration->setExtension($this); return $configuration; }
/** * @dataProvider getKeyNormalizationTests */ public function testNormalizeKeys($denormalized, $normalized) { $this->assertSame($normalized, Extension::normalizeKeys($denormalized)); }