/** * Checks and ensures that a static WSDL file exist and is in place * * @return string WSDL path * * @since 1.4 */ public function checkWSDL() { try { // Wet wsdl from webservice location $this->wsdlPath = RApiSoapHelper::getWebserviceFilePath($this->webservice->client, strtolower($this->webservice->webserviceName), $this->webservice->webserviceVersion, 'wsdl', $this->webservice->webservicePath); if (is_readable(JPATH_SITE . '/' . $this->wsdlPath)) { return $this->wsdlPath; } } catch (Exception $e) { } // WSDL file is not present, we are going to generate it on the fly $this->wsdl = RApiSoapHelper::generateWsdl($this->webservice->configuration, $this->wsdlPath); RApiSoapHelper::saveWsdlContentToPath($this->wsdl, JPATH_SITE . '/' . $this->wsdlPath); return $this->wsdlPath; }
/** * Method to save the form data to XML file. * * @param array $data The form data. * * @return boolean True on success, False on error. * * @throws RuntimeException * * @since 1.4 */ public function saveXml($data) { $dataRegistry = new JRegistry($data); $item = null; if (empty($data['main']['name'])) { $this->setError(JText::_('COM_REDCORE_WEBSERVICE_NAME_FIELD_CANNOT_BE_EMPTY')); return false; } if (!empty($data['main']['id'])) { $item = $this->getItem($data['main']['id']); } $client = $dataRegistry->get('main.client', 'site'); $name = $dataRegistry->get('main.name', ''); $version = $dataRegistry->get('main.version', '1.0.0'); $folder = $dataRegistry->get('main.path', ''); $folder = !empty($folder) ? JPath::clean('/' . $folder) : ''; if (!JFolder::exists(RApiHalHelper::getWebservicesPath() . $folder)) { JFolder::create(RApiHalHelper::getWebservicesPath() . $folder); } $fullPath = JPath::clean(RApiHalHelper::getWebservicesPath() . $folder . '/' . $client . '.' . $name . '.' . $version . '.xml'); $xml = new SimpleXMLElement('<?xml version="1.0"?><apiservice client="' . $client . '"></apiservice>'); $xml->addChild('name', $dataRegistry->get('main.title', $name)); $xml->addChild('author', $dataRegistry->get('main.author', '')); $xml->addChild('copyright', $dataRegistry->get('main.copyright', '')); $xml->addChild('description', $dataRegistry->get('main.description', '')); $configXml = $xml->addChild('config'); $configXml->addChild('name', $dataRegistry->get('main.name', '')); $configXml->addChild('version', $version); $configXml->addChild('authorizationAssetName', $dataRegistry->get('main.authorizationAssetName', '')); $operationsXml = $xml->addChild('operations'); $readXml = null; $taskXml = null; foreach ($data as $operationName => $operation) { if ($operationName != 'main') { if (empty($operation['isEnabled'])) { continue; } $operationNameSplit = explode('-', $operationName); if ($operationNameSplit[0] == 'read' && count($operationNameSplit) > 1) { if (is_null($readXml)) { $readXml = $operationsXml->addChild('read'); } $operationXml = $readXml->addChild($operationNameSplit[1]); } elseif ($operationNameSplit[0] == 'task' && count($operationNameSplit) > 1) { if (is_null($taskXml)) { $taskXml = $operationsXml->addChild('task'); } $operationXml = $taskXml->addChild($operationNameSplit[1]); } else { $operationXml = $operationsXml->addChild($operationNameSplit[0]); } $this->getOperationAttributesFromPost($operationXml, $data, $operationName); $this->getFieldsFromPost($operationXml, $data, $operationName); $this->getResourcesFromPost($operationXml, $data, $operationName); } } // Needed for formatting $dom = dom_import_simplexml($xml)->ownerDocument; $dom->preserveWhiteSpace = false; $dom->formatOutput = true; if ($dom->save($fullPath)) { if (!empty($item->id)) { $folder = !empty($item->path) ? '/' . $item->path : ''; $oldPath = JPath::clean(RApiHalHelper::getWebservicesPath() . $folder . '/' . $item->xmlFile); if ($oldPath != $fullPath) { if (JFile::exists($oldPath)) { JFile::delete($oldPath); } } } $wsdl = RApiSoapHelper::generateWsdl($xml); $fullWsdlPath = substr($fullPath, 0, -4) . '.wsdl'; return RApiSoapHelper::saveWsdlContentToPath($wsdl, $fullWsdlPath); } return false; }