namespace Symfony\Component\Config\Definition;
-use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\Config\Definition\Exception\DuplicateKeyException;
-use Symfony\Component\Config\Definition\Exception\UnsetKeyException;
use Symfony\Component\Config\Definition\Exception\Exception;
+use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
+use Symfony\Component\Config\Definition\Exception\UnsetKeyException;
/**
* Represents a prototyped Array node in the config tree.
*/
public function setDefaultValue($value)
{
- if (!is_array($value)) {
+ if (!\is_array($value)) {
throw new \InvalidArgumentException($this->getPath().': the default value of an array node has to be an array.');
}
if (null === $children) {
$this->defaultChildren = array('defaults');
} else {
- $this->defaultChildren = is_int($children) && $children > 0 ? range(1, $children) : (array) $children;
+ $this->defaultChildren = \is_int($children) && $children > 0 ? range(1, $children) : (array) $children;
}
}
protected function finalizeValue($value)
{
if (false === $value) {
- $msg = sprintf('Unsetting key for path "%s", value: %s', $this->getPath(), json_encode($value));
- throw new UnsetKeyException($msg);
+ throw new UnsetKeyException(sprintf('Unsetting key for path "%s", value: %s', $this->getPath(), json_encode($value)));
}
foreach ($value as $k => $v) {
}
}
- if (count($value) < $this->minNumberOfElements) {
- $msg = sprintf('The path "%s" should have at least %d element(s) defined.', $this->getPath(), $this->minNumberOfElements);
- $ex = new InvalidConfigurationException($msg);
+ if (\count($value) < $this->minNumberOfElements) {
+ $ex = new InvalidConfigurationException(sprintf('The path "%s" should have at least %d element(s) defined.', $this->getPath(), $this->minNumberOfElements));
$ex->setPath($this->getPath());
throw $ex;
$value = $this->remapXml($value);
- $isAssoc = array_keys($value) !== range(0, count($value) - 1);
+ $isAssoc = array_keys($value) !== range(0, \count($value) - 1);
$normalized = array();
foreach ($value as $k => $v) {
- if (null !== $this->keyAttribute && is_array($v)) {
- if (!isset($v[$this->keyAttribute]) && is_int($k) && !$isAssoc) {
- $msg = sprintf('The attribute "%s" must be set for path "%s".', $this->keyAttribute, $this->getPath());
- $ex = new InvalidConfigurationException($msg);
+ if (null !== $this->keyAttribute && \is_array($v)) {
+ if (!isset($v[$this->keyAttribute]) && \is_int($k) && !$isAssoc) {
+ $ex = new InvalidConfigurationException(sprintf('The attribute "%s" must be set for path "%s".', $this->keyAttribute, $this->getPath()));
$ex->setPath($this->getPath());
throw $ex;
$valuePrototype = current($this->valuePrototypes) ?: clone $children['value'];
$valuePrototype->parent = $this;
$originalClosures = $this->prototype->normalizationClosures;
- if (is_array($originalClosures)) {
+ if (\is_array($originalClosures)) {
$valuePrototypeClosures = $valuePrototype->normalizationClosures;
- $valuePrototype->normalizationClosures = is_array($valuePrototypeClosures) ? array_merge($originalClosures, $valuePrototypeClosures) : $originalClosures;
+ $valuePrototype->normalizationClosures = \is_array($valuePrototypeClosures) ? array_merge($originalClosures, $valuePrototypeClosures) : $originalClosures;
}
$this->valuePrototypes[$k] = $valuePrototype;
}
}
if (array_key_exists($k, $normalized)) {
- $msg = sprintf('Duplicate key "%s" for path "%s".', $k, $this->getPath());
- $ex = new DuplicateKeyException($msg);
+ $ex = new DuplicateKeyException(sprintf('Duplicate key "%s" for path "%s".', $k, $this->getPath()));
$ex->setPath($this->getPath());
throw $ex;
// no conflict
if (!array_key_exists($k, $leftSide)) {
if (!$this->allowNewKeys) {
- $ex = new InvalidConfigurationException(sprintf(
- 'You are not allowed to define new elements for path "%s". '.
- 'Please define all elements for this path in one config file.',
- $this->getPath()
- ));
+ $ex = new InvalidConfigurationException(sprintf('You are not allowed to define new elements for path "%s". Please define all elements for this path in one config file.', $this->getPath()));
$ex->setPath($this->getPath());
throw $ex;
* one is same as this->keyAttribute and the other is 'value', then the prototype will be different.
*
* For example, assume $this->keyAttribute is 'name' and the value array is as follows:
- * array(
+ *
* array(
- * 'name' => 'name001',
- * 'value' => 'value001'
+ * array(
+ * 'name' => 'name001',
+ * 'value' => 'value001'
+ * )
* )
- * )
*
* Now, the key is 0 and the child node is:
- * array(
- * 'name' => 'name001',
- * 'value' => 'value001'
- * )
+ *
+ * array(
+ * 'name' => 'name001',
+ * 'value' => 'value001'
+ * )
*
* When normalizing the value array, the 'name' element will removed from the child node
* and its value becomes the new key of the child node:
- * array(
- * 'name001' => array('value' => 'value001')
- * )
+ *
+ * array(
+ * 'name001' => array('value' => 'value001')
+ * )
*
* Now only 'value' element is left in the child node which can be further simplified into a string:
- * array('name001' => 'value001')
+ *
+ * array('name001' => 'value001')
*
* Now, the key becomes 'name001' and the child node becomes 'value001' and
* the prototype of child node 'name001' should be a ScalarNode instead of an ArrayNode instance.