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; }
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; }