コード例 #1
0
 public function getXmlNamespace()
 {
     $namespace = $this->_parseAnnotation($this->property->getDocComment(), 'xmlNamespace');
     if (!$namespace && $this->configuration) {
         $value = $this->getValue();
         if (is_object($this->getValue())) {
             $classMeta = new ClassMetadata($this->getValue(), $this->configuration);
             $namespace = $classMeta->getXmlNamespace();
         } elseif (is_array($value) && count($value) > 0) {
             $classMeta = new ClassMetadata($this->getValue()[0], $this->configuration);
             $namespace = $classMeta->getXmlNamespace();
         } else {
             $classNamespace = $this->property->getDeclaringClass()->getNamespaceName();
             $namespace = $this->configuration->getXmlNamespace($classNamespace);
         }
     }
     return $namespace;
 }
コード例 #2
0
 /**
  * @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;
 }
コード例 #3
0
 public function testNamespace()
 {
     $node = new TextNode();
     $meta = new ClassMetadata($node);
     $this->assertEquals('com.example.testcase', $meta->getXmlNamespace());
 }