Ejemplo n.º 1
0
Archivo: base.php Proyecto: 810/redCORE
 /**
  * Method to transform a type to publish it in the WSDL file
  *
  * @param   array             $field             Field definition.
  * @param   SimpleXMLElement  &$sequence         XML with the fields sequence
  * @param   SimpleXMLElement  &$typeSchema       XML of the typeSchema in case new derived types need to be added
  * @param   string            $elementName       Parent element name to add the new derived types with unique names
  * @param   boolean           $validateOptional  Optional parameter to validate if the field is optional.  Otherwise it's always set as required
  * @param   array             $extraFields       Array of extra fields to process - in case of array types
  *
  * @return void
  */
 public function wsdlField($field, &$sequence, &$typeSchema, $elementName, $validateOptional = false, $extraFields = array())
 {
     if (!isset($this->element)) {
         $this->element = $sequence->addChild('element', null, 'http://www.w3.org/2001/XMLSchema');
     }
     if (!isset($this->element['minOccurs'])) {
         $this->element->addAttribute('minOccurs', $validateOptional && RApiHalHelper::isAttributeTrue($field, 'isRequiredField') || !$validateOptional ? '1' : '0');
     }
     if (!isset($this->element['maxOccurs'])) {
         $this->element->addAttribute('maxOccurs', RApiHalHelper::attributeToString($field, 'maxOccurs', 1));
     }
     if (!isset($this->element['name']) && isset($field['name'])) {
         $this->element->addAttribute('name', $field['name']);
     }
     if ($this->type != '') {
         $this->element->addAttribute('type', $this->type);
     }
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 3
0
 /**
  * Assign value to Resource
  *
  * @param   array   $resource   Resource list with options
  * @param   mixed   $value      Data values to set to resource format
  * @param   string  $attribute  Attribute from array to replace the data
  *
  * @return  string
  *
  * @since   1.2
  */
 public function assignValueToResource($resource, $value, $attribute = 'fieldFormat')
 {
     $format = $resource[$attribute];
     $transform = RApiHalHelper::attributeToString($resource, 'transform', '');
     // Filters out the complex SOAP arrays, to treat them as regular arrays
     if (preg_match('/^array\\[(.+)\\]$/im', $transform)) {
         $transform = 'array';
     }
     $stringsToReplace = array();
     preg_match_all('/\\{([^}]+)\\}/', $format, $stringsToReplace);
     if (!empty($stringsToReplace[1])) {
         foreach ($stringsToReplace[1] as $replacementKey) {
             if (is_object($value)) {
                 if (property_exists($value, $replacementKey)) {
                     // We are transforming only value
                     if ($format == '{' . $replacementKey . '}') {
                         $format = $this->transformField($transform, $value->{$replacementKey});
                     } else {
                         $format = str_replace('{' . $replacementKey . '}', $this->transformField($transform, $value->{$replacementKey}), $format);
                     }
                 }
             } elseif (is_array($value)) {
                 if (isset($value[$replacementKey])) {
                     // We are transforming only value
                     if ($format == '{' . $replacementKey . '}') {
                         $format = $this->transformField($transform, $value[$replacementKey]);
                     } else {
                         $format = str_replace('{' . $replacementKey . '}', $this->transformField($transform, $value[$replacementKey]), $format);
                     }
                 }
             } else {
                 // We are transforming only value
                 if ($format == '{' . $replacementKey . '}') {
                     $format = $this->transformField($transform, $value);
                 } else {
                     $format = str_replace('{' . $replacementKey . '}', $this->transformField($transform, $value), $format);
                 }
             }
         }
     }
     // We replace global data as well
     $format = $this->assignGlobalValueToResource($format);
     if (!empty($stringsToReplace[1])) {
         // If we did not found data with that resource we will set it to 0, except for linkRel which is a documentation template
         if ($format === $resource[$attribute] && $resource['linkRel'] != 'curies') {
             $format = null;
         }
     }
     return $format;
 }
Ejemplo n.º 4
0
 /**
  * Gets an array of fields ready for SOAP documentation purposes
  *
  * @param   array    $fields       Array of fields using their xml properties (using 'name' for the field name itself)
  * @param   boolean  $allRequired  Mark all the fields as required
  * @param   string   $assignation  Assignation operation
  *
  * @return  array
  *
  * @since   1.4
  */
 public static function documentationFields($fields, $allRequired = false, $assignation = '=')
 {
     $fieldsArray = array();
     if ($fields && is_array($fields)) {
         foreach ($fields as $field) {
             $transform = RApiHalHelper::attributeToString($field, 'transform', 'string');
             $defaultValue = RApiHalHelper::attributeToString($field, 'defaultValue', 'null');
             if ($defaultValue == 'null' && ($allRequired || RApiHalHelper::isAttributeTrue($field, 'isRequiredField'))) {
                 $transformClass = 'RApiSoapTransform' . ucfirst($transform);
                 if (!class_exists($transformClass)) {
                     $transformClass = 'RApiSoapTransformBase';
                 }
                 $transformObject = new $transformClass();
                 $defaultValue = $transformObject->defaultValue;
             }
             $fieldsArray[] = '$' . RApiHalHelper::attributeToString($field, 'name') . ' ' . $assignation . ' (' . $transform . ') ' . $defaultValue;
         }
     }
     return $fieldsArray;
 }