/** * Cria a classe com base no Nó do XSD. * @param \DOMElement $node * @param string $namespace * @param string $dirTarget */ public function createClassFromNode(\DOMElement $node = null, $namespace = null, $dirTarget = null, $overwrite = false) { if ($node === null) { $node = $this->getLoadedSchema()->documentElement; } if ($namespace === NULL) { $namespace = $this->getDefaultNamespace(); } if ($dirTarget === NULL) { $dirTarget = $this->getDirTarget(); } $class = new \PhpClass(); if (!is_null($namespace)) { $class->setNamespace(new \PhpClass_Namespace(array('path' => $namespace))); } $class->setExtends('\\Sped\\Components\\Xml\\Element'); $class->setName($node->getAttribute('name')); $class->setDescription($this->getDocumentation($node)); $class->addCommentTag(new \PhpClass_DocBlock_Tag(array('name' => 'category', 'description' => 'Sped'))); $class->addCommentTag(new \PhpClass_DocBlock_Tag(array('name' => 'package', 'description' => 'Sped'))); $class->addCommentTag(new \PhpClass_DocBlock_Tag(array('name' => 'copyright', 'description' => 'Copyright (c) 2012 Antonio Spinelli'))); $class->addCommentTag(new \PhpClass_DocBlock_Tag(array('name' => 'license', 'description' => 'http://www.gnu.org/licenses/gpl.html GNU/GPL v.3'))); $nodeName = $node->getAttribute('name'); //verifica se o elemento está apenas no segundo nível do documento if ($node->localName == 'element' and $this->getNodeLevel($node) === 2) { $class->getConstants()->clear(); $class->getMethods()->clear(); $class->setExtends('\\Sped\\Components\\Xml\\Document'); $class->setDescription('Documento ' . $class->getDocBlock()->getDescription()); $class->setName('Document' . ucfirst($nodeName)); if ($node->hasAttribute('type')) { $prefix = $node->prefix; if ($prefix != 'xs') { $namespaceURI = $this->getLoadedSchema()->lookupNamespaceUri($prefix); } else { $namespaceURI = $this->getLoadedSchema()->getTargetNamespace(); } $methodName = $this->getSufixName($nodeName); $methodNamespace = $class->getNamespace()->getPath() . '\\' . $this->getSufixName($node->getAttribute('type')); } elseif ($node->hasAttribute('ref')) { $prefix = $this->getPrefixName($node->getAttribute('ref')); $namespaceURI = $this->getLoadedSchema()->lookupNamespaceUri($prefix); $methodName = $this->getSufixName($node->getAttribute('ref')); $methodNamespace = $class->getNamespace()->getPath() . '\\' . $methodName; } $class->addConstant(new \PhpClass_Constant(array('name' => $nodeName, 'value' => $nodeName))); $class->addMethod($this->createElementGetMethod(array('name' => $methodName, 'description' => $this->getDocumentation($node), 'type' => $methodNamespace, 'hasIndex' => false, 'isElement' => false))); $class->addMethod($this->createElementAddMethod(array('name' => $methodName, 'description' => $this->getDocumentation($node), 'type' => $methodNamespace, 'namespaceURI' => $namespaceURI))); $class->addMethod($this->createElementSetMethod(array('name' => $methodName, 'description' => $this->getDocumentation($node), 'type' => $methodNamespace))); } if (!preg_match('/^Document/', $class->getName())) { $this->createClassMethodsFromNode($class, $node); } $class->save($dirTarget, null, $this->isOverwrite()); var_dump($class->getFullName() . ' is generated.'); }