/** * Returns generated WSDL file for the webservice * * @param string $wsdlPath Path of WSDL file * * @return SimpleXMLElement */ public function generateWsdl($wsdlPath) { $wsdlFullPath = JUri::root() . $wsdlPath; $client = RApiHalHelper::attributeToString($this->webserviceXml, 'client', 'site'); $version = !empty($this->webserviceXml->config->version) ? $this->webserviceXml->config->version : '1.0.0'; $this->webserviceFullName = $client . '.' . $this->webserviceXml->config->name . '.' . $version; $this->webserviceUrl = RApiHalHelper::buildWebserviceFullUrl($client, $this->webserviceXml->config->name, $version, 'soap'); // Root of the document $this->wsdl = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8" ?><wsdl:definitions' . ' xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"' . ' xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"' . ' xmlns:tns="' . $wsdlFullPath . '"' . ' xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap12/"' . ' xmlns:s="http://www.w3.org/2001/XMLSchema"' . ' xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"' . ' targetNamespace="' . $wsdlFullPath . '"' . ' xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"' . ' ></wsdl:definitions>', 0, false, 'wsdl', true); $types = $this->wsdl->addChild('types'); $this->typeSchema = $types->addChild('schema', null, 'http://www.w3.org/2001/XMLSchema'); $this->typeSchema->addAttribute('targetNamespace', $wsdlFullPath); $this->typeSchema->addAttribute('elementFormDefault', 'unqualified'); $this->addGlobalTypes($this->typeSchema); // Adding service $this->wsdlServices = $this->wsdl->addChild('service'); $this->wsdlServices->addAttribute('name', $this->webserviceFullName); $this->wsdlServices->addChild('documentation', $this->webserviceXml->description); // Add new port binding $port = $this->wsdlServices->addChild('port'); $port->addAttribute('name', $this->webserviceFullName . '_Soap'); $port->addAttribute('binding', 'tns:' . $this->webserviceFullName); // Add soap addresses $soapAddress = $port->addChild('soap:address', null, 'http://schemas.xmlsoap.org/wsdl/soap12/'); $soapAddress->addAttribute('location', $this->webserviceUrl); // Add webservice operations if (isset($this->webserviceXml->operations)) { // Read list if (isset($this->webserviceXml->operations->read->list)) { $filters = RApiHalHelper::getFilterFields($this->webserviceXml->operations->read->list, true, true); if (empty($filters)) { $filtersDef = array('name' => 'filters', 'transform' => 'array'); } else { $filtersDef = array('name' => 'filters', 'transform' => 'arraydefined', 'fields' => $filters); } // Add read list messages $inputFields = array(array('name' => 'limitStart', 'transform' => 'int'), array('name' => 'limit', 'transform' => 'int'), array('name' => 'filterSearch', 'transform' => 'string'), $filtersDef, array('name' => 'ordering', 'transform' => 'string'), array('name' => 'orderingDirection', 'transform' => 'string'), array('name' => 'language', 'transform' => 'string')); // Add read list response messages $outputFields = array(array('name' => 'list', 'transform' => 'arrayrequired', 'fields' => array(array('name' => 'item', 'maxOccurs' => 'unbounded', 'transform' => 'arrayrequired', 'fields' => RApiSoapHelper::getOutputResources($this->webserviceXml->operations->read->list, 'listItem'))))); $this->addOperation($this->wsdl, 'readList', $inputFields, $outputFields, true, true); } // Read item if (isset($this->webserviceXml->operations->read->item)) { // Add read item messages $inputFields = array_merge(RApiHalHelper::getFieldsArray($this->webserviceXml->operations->read->item, true), array(array('name' => 'language', 'transform' => 'string'))); // Add read item response messages $outputFields = array(array('name' => 'item', 'typeName' => 'item', 'transform' => 'arrayrequired', 'fields' => RApiSoapHelper::getOutputResources($this->webserviceXml->operations->read->item))); $this->addOperation($this->wsdl, 'readItem', $inputFields, $outputFields, false, true); } // Create operation if (isset($this->webserviceXml->operations->create)) { // Add create messages $inputFields = RApiHalHelper::getFieldsArray($this->webserviceXml->operations->create); // Add create response messages $outputFields = array(RApiSoapHelper::getResultResource($this->webserviceXml->operations->create)); $this->addOperation($this->wsdl, 'create', $inputFields, $outputFields, true); } // Update operation if (isset($this->webserviceXml->operations->update)) { // Add update messages $inputFields = RApiHalHelper::getFieldsArray($this->webserviceXml->operations->update); // Add update response messages $outputFields = array(RApiSoapHelper::getResultResource($this->webserviceXml->operations->update)); $this->addOperation($this->wsdl, 'update', $inputFields, $outputFields, true); } // Delete operation if (isset($this->webserviceXml->operations->delete)) { // Add delete messages $inputFields = RApiHalHelper::getFieldsArray($this->webserviceXml->operations->delete, true); // Add delete response messages $outputFields = array(RApiSoapHelper::getResultResource($this->webserviceXml->operations->delete)); $this->addOperation($this->wsdl, 'delete', $inputFields, $outputFields); } // Task operation if (isset($this->webserviceXml->operations->task)) { foreach ($this->webserviceXml->operations->task->children() as $taskName => $task) { // Add task messages $inputFields = RApiHalHelper::getFieldsArray($task); // Add task response messages $outputFields = array(RApiSoapHelper::getResultResource($task)); $this->addOperation($this->wsdl, 'task_' . $taskName, $inputFields, $outputFields, true); } } } return $this->wsdl; }
/** * Read item * * @param object $data Primary keys and $language * * @return array */ public function readItem($data) { // We are setting the operation of the webservice to Read $this->setOperation('read'); $dataGet = $this->webservice->options->get('dataGet', array()); $primaryKeysFromFields = RApiHalHelper::getFieldsArray($this->webservice->configuration->operations->read->item, true); // If there are no primary keys defined we will use id field as default if (empty($primaryKeysFromFields)) { $primaryKeysFromFields['id'] = array('transform' => 'int'); } foreach ($primaryKeysFromFields as $primaryKey => $primaryKeyField) { $keyData = ''; if (isset($data->{$primaryKey}) && $data->{$primaryKey} != '') { $keyData = $data->{$primaryKey}; } $dataGet->{$primaryKey} = $this->webservice->transformField($primaryKeyField['transform'], $keyData, false); } // Handle different language switch $this->setLanguage((string) (isset($data->language) ? $data->language : '')); $this->webservice->options->set('dataGet', $dataGet); $this->webservice->options->set('task', ''); $this->webservice->options->set('filterOutResourcesGroups', array('_links', '_messages')); $this->webservice->execute(); $arr = $this->webservice->hal->toArray(); $outputResources = RApiSoapHelper::getOutputResources($this->webservice->configuration->operations->read->item, '', true); $response = RApiSoapHelper::selectListResources($outputResources, array($arr)); $final = new stdClass(); $final->item = empty($response) ? array() : $response[0]; $match = true; if (RApiHalHelper::isAttributeTrue($this->webservice->configuration->operations->read->item, 'enforcePKs', true)) { foreach ($primaryKeysFromFields as $primaryKey => $primaryKeyField) { if ($dataGet->{$primaryKey} != $final->item->{$primaryKey}) { $match = false; } } } if (!$match) { $final = array(); } if (!count((array) $final->item)) { $final = array(); } return $final; }