/** * @param DenormalizerInterface $denormalizer * @param array $data * @param string $format * @param array $context * @return array */ public function denormalize(DenormalizerInterface $denormalizer, $data, $format = null, array $context = null) { $keys = array_keys($data); $this->name = reset($keys); $data = reset($data); $contents = $data; if (is_array($data)) { $contents = array(); foreach ($data as $key => $value) { if ($key[0] == '@') { $this->setAttribute(ltrim($key, '@'), $value); } else { $contents[$key] = $value; } } $keys = array_keys($contents); if (reset($keys) == '#') { $contents = reset($contents); } } if (is_string($contents)) { $node = new Content(); } else { if (count($contents) > 1) { $node = new Composite(); } else { $node = new Tag(); } } $node->denormalize($denormalizer, $contents, $format, $context); $this->content = $node; }
/** * @param DenormalizerInterface $denormalizer * @param array $data * @param string $format * @param array $context */ public function denormalize(DenormalizerInterface $denormalizer, $data, $format = null, array $context = null) { foreach ($data as $key => $values) { if (!is_array($values) || $this->isAssociativeArray($values)) { $values = array($values); } foreach ($values as $value) { $tag = new Tag(); $tag->denormalize($denormalizer, array($key => $value), $format, $context); $this->add($tag); } } }