/** * Determine the namespace of a type from the XMLSchema * * @param \Goetas\XML\XSDReader\Schema\Type\Type|\Sapone\Util\SimpleXMLElement $type * @return string */ public function inflectNamespace($type) { if ($type instanceof Type) { if ($type->getSchema()->getTargetNamespace() === SchemaReader::XSD_NS) { // XMLSchema primitive types do not have a namespace $namespace = null; } else { $namespace = array(); // prepend the base namespace if ($this->config->getNamespace()) { $namespace[] = $this->config->getNamespace(); } if ($this->config->isAxisNamespaces()) { // append the XMLSchema namespace, formatted in Apache Axis style $url = Url::createFromUrl($type->getSchema()->getTargetNamespace()); // the namespace is an url $namespace = array_merge($namespace, array_reverse(explode('.', $url->getHost()->get()))); if (!empty($url->getPath()->get())) { $namespace = array_merge($namespace, explode('/', $url->getPath()->get())); } } $namespace = implode('\\', $namespace); } return $namespace; } elseif ($type instanceof SimpleXMLElement) { if ($type->getNamespace() === SchemaReader::XSD_NS) { // XMLSchema primitive types do not have a namespace $namespace = null; } else { $namespace = array(); // prepend the base namespace if ($this->config->getNamespace()) { $namespace[] = $this->config->getNamespace(); } if ($this->config->isAxisNamespaces()) { // append the XMLSchema namespace, formatted in Apache Axis style $url = Url::createFromUrl($type->getNamespace()); // the namespace is an url $namespace = array_merge($namespace, array_reverse(explode('.', $url->getHost()->get()))); if (!empty($url->getPath()->get())) { $namespace = array_merge($namespace, explode('/', $url->getPath()->get())); } } $namespace = implode('\\', $namespace); } return $namespace; } else { throw new \InvalidArgumentException('Expected an instance of Goetas\\XML\\XSDReader\\Schema\\Type\\Type or Sapone\\Util\\SimpleXMLElement'); } }
/** * {@inheritdoc} */ public function createClassmap() { /* * INI FILE GENERATION */ $outputPath = array($this->config->getOutputPath()); // if the psr0 autoloader has been selected, transform the class namespace into a filesystem path if ($this->config->getAutoloader() === Config::AUTOLOADER_PSR0) { $outputPath[] = str_ireplace('\\', DIRECTORY_SEPARATOR, $this->config->getNamespace()); } // append the file name $outputPath[] = 'classmap.ini'; // finalize the output path $outputPath = implode(DIRECTORY_SEPARATOR, $outputPath); // remove the file if exists $fs = new Filesystem(); $fs->remove($outputPath); foreach ($this->classmap as $wsdlType => $phpType) { file_put_contents($outputPath, "{$wsdlType} = {$phpType}" . AbstractGenerator::LINE_FEED, FILE_APPEND); } /* * CLASS GENERATION */ // create the class $class = ClassGenerator::fromReflection(new ClassReflection('\\Sapone\\Template\\ClassmapTemplate')); $class->setName('Classmap'); $class->setExtendedClass('\\ArrayObject'); $class->setNamespaceName($this->config->getNamespace()); $doc = new DocBlockGenerator(); $doc->setTag(new GenericTag('@service', $this->config->getWsdlDocumentPath())); $class->setDocBlock($doc); $this->serializeClass($class); return $class->getName(); }