Esempio n. 1
0
 /**
  * @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 string $name
  * @param Node $content
  * @return Tag
  */
 public static function build($name, Node $content)
 {
     $node = new Tag();
     $node->setName($name);
     $node->setContent($content);
     return $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);
         }
     }
 }