/** * @dataProvider providerPublicMethodException * @expectedException \Kcs\Serializer\Exception\RuntimeException */ public function testAccessorTypePublicMethodException($getter, $setter) { $object = new PropertyMetadataPublicMethod(); $metadata = new PropertyMetadata(get_class($object), 'e'); $metadata->setAccessor(PropertyMetadata::ACCESS_TYPE_PUBLIC_METHOD, $getter, $setter); if (null === $getter) { $metadata->getValue($object, new SerializationContext()); } if (null === $setter) { $metadata->setValue($object, null); } }
protected function visitProperty(PropertyMetadata $metadata, $data, Context $context) { $v = $metadata->getValue($data); $v = $this->navigator->accept($v, $metadata->type, $context); if (null === $v && !$context->shouldSerializeNull()) { return; } $k = $this->namingStrategy->translateName($metadata); if ($metadata->inline) { if (is_array($v)) { $this->data = array_merge($this->data, $v); } } else { $this->data[$k] = $v; } }
protected function visitProperty(PropertyMetadata $metadata, $data, Context $context) { $v = $metadata->getValue($data); if ($metadata->xmlAttribute) { $attributeName = $this->namingStrategy->translateName($metadata); $this->currentNodes = $this->document->createElement('tmp'); $context->accept($v, $metadata->type); $node = $this->createAttributeNode($metadata, $attributeName); $node->appendChild($this->createTextNode((string) $this->currentNodes->nodeValue)); return $this->currentNodes = $node; } if ($metadata->xmlValue) { $this->currentNodes = $this->document->createElement('tmp'); $context->accept($v, $metadata->type); $node = $this->currentNodes->childNodes->item(0); $this->currentNodes->removeChild($node); return $this->currentNodes = $node; } if ($metadata->xmlAttributeMap) { $attributes = []; foreach ($v as $key => $value) { $node = $this->createAttributeNode($metadata, $key); $node->appendChild($this->createTextNode((string) $value)); $attributes[] = $node; } return $this->currentNodes = $attributes; } if (null === $v && !$context->shouldSerializeNull()) { return $this->currentNodes = null; } $elementName = $this->namingStrategy->translateName($metadata); $this->currentNodes = $this->createElement($metadata->xmlNamespace, $elementName); $context->accept($v, $metadata->type); if (is_object($v) && null !== $v && !$metadata instanceof AdditionalPropertyMetadata && $context->isVisiting($v)) { return $this->currentNodes = null; } if ($metadata->xmlCollectionInline || $metadata->inline) { $children = iterator_to_array($this->currentNodes->childNodes); foreach ($children as $childNode) { $this->currentNodes->removeChild($childNode); } $this->currentNodes = $children; } return $this->currentNodes; }