public function testNamespacedNodeName() { $configuration = new Configuration(); $configuration->addNamespace('com.example.property', 'XmlSerializer\\Fixtures\\Metadata'); $classMeta = new ClassMetadata(new PropertyMeta(), $configuration); $this->assertEquals('com.example.property', $classMeta->getProperty('basicNode')->getXmlNamespace()); $this->assertEquals('ns1:basicNode', $classMeta->getProperty('basicNode')->getXmlNodeName()); }
public function multiNsSerializerProvider() { $config = new Config\Configuration(); $config->setDefaultNamespace('com.example.first'); $config->addNamespace('com.example.first', 'XmlSerializer\\Fixtures\\Serialize\\First'); $config->addNamespace('com.example.second', 'XmlSerializer\\Fixtures\\Serialize\\Second'); return [[new OldSerializer($config)]]; }
public function multiNsDeserializerProvider() { $config = new Configuration(); $config->addNamespace('urn:com.example.first', '\\XmlSerializer\\Fixtures\\Deserialize\\First'); $config->addNamespace('urn:com.example.second', '\\XmlSerializer\\Fixtures\\Deserialize\\Second'); $config->setDefaultNamespace('urn:com.example.first'); $deserializer = new OldDeserializer($config); return [[$deserializer]]; }
public function getXmlNodeName() { $xmlName = $this->_parseAnnotation($this->property->getDocComment(), self::XML_NAME_ANNOTATION); if (!$xmlName) { $xmlName = $this->property->getName(); } if ($this->configuration && $this->getXmlNamespace() !== $this->configuration->getDefaultXmlNamespace()) { $alias = $this->configuration->getShortXmlNamespace($this->getXmlNamespace()); if ($alias) { $xmlName = $alias . ':' . $xmlName; } } return $xmlName; }
public function getXmlNodeName() { if ($this->getXmlNamespace() !== $this->configuration->getDefaultXmlNamespace()) { $alias = $this->configuration->getShortXmlNamespace($this->getXmlNamespace()); return $alias . ':' . $this->reflection->getShortName(); } else { return $this->reflection->getShortName(); } }
public function getClassName(Configuration $configuration = null) { if (!$configuration) { return '\\stdClass'; } if ($this->getNamespaces()) { $className = $configuration->getClassNamespace($this->getXmlNamespace()) . '\\' . $this->getName(); if (class_exists($className)) { return $className; } } if ($configuration->getDefaultXmlNamespace()) { $className = $configuration->getClassNamespace($configuration->getDefaultXmlNamespace()) . '\\' . $this->getName(); if (class_exists($className)) { return $className; } } return '\\stdClass'; }
/** * @param ClassMetadata $class * * @return \SimpleXMLElement */ public function createRootNode(ClassMetadata $class) { $longNs = $class->getXmlNamespace(); $ns = $this->configuration->getShortXmlNamespace($longNs); $rootNodeName = $class->getXmlNodeName(); $xml = new \SimpleXMLElement('<' . $rootNodeName . '/>', LIBXML_NOERROR, false, $ns); if ($this->configuration->getDefaultXmlNamespace()) { $xml->addAttribute('xmlns:xmlns', $this->configuration->getDefaultXmlNamespace()); } $xmlNamespaces = $this->configuration->getAllShortXmlNamespaces(); if (count($xmlNamespaces) > 1 || count($xmlNamespaces) == 1 && key($xmlNamespaces) !== $this->configuration->getDefaultXmlNamespace()) { foreach ($xmlNamespaces as $longNs => $shortNs) { if ($longNs === $this->configuration->getDefaultXmlNamespace()) { continue; } $attrNs = $shortNs ? 'xmlns:xmlns:' . $shortNs : 'xmlns:xmlns'; if (!$xml->attributes()->{'xmlns:' . $shortNs}) { $xml->addAttribute($attrNs, $longNs); } } } return $xml; }