Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge PR #2141 branch '89-soap-header' of https://github.com/nineinch…

…nick/yii into nineinchnick-89-soap-header2

* '89-soap-header' of https://github.com/nineinchnick/yii:
  enh #89, support for SOAP headers in WSDL generator
  • Loading branch information...
commit 230d9f2acd953e2f91584af3c662dca9155030b6 2 parents 9a1eac1 + 0904589
@cebe cebe authored
Showing with 51 additions and 6 deletions.
  1. +1 −0  CHANGELOG
  2. +50 −6 framework/web/services/CWsdlGenerator.php
View
1  CHANGELOG
@@ -39,6 +39,7 @@ Version 1.1.15 under development
- Bug: Fixed URL parsing so it's now properly giving 404 for URLs like "http://example.com//////site/about/////" (samdark)
- Bug: Fixed an issue with CFilehelper and not accessable directories which resulted in endless loop (cebe)
- Enh: Public method CFileHelper::createDirectory() has been added (klimov-paul)
+- Enh #89: Support for SOAP headers in WSDL generator (nineinchnick)
- Enh #106: Added getters to CGridColumn to allow getting cell contents for extended use cases of CGridView (cebe)
- Enh #182: CSort: allow arrays in asc/desc keys of virtual attributes (nineinchnick)
- Enh #640: Introduce bigpk and bigint column types in each class extending CDbSchema (nineinchnick)
View
56 framework/web/services/CWsdlGenerator.php
@@ -245,6 +245,7 @@ protected function processMethod($method)
$comment=preg_replace('/^\s*\**(\s*?$|\s*)/m','',$comment);
$params=$method->getParameters();
$message=array();
+ $headers=array();
$n=preg_match_all('/^@param\s+([\w\.]+(\[\s*\])?)\s*?(.*)$/im',$comment,$matches);
if($n>count($params))
$n=count($params);
@@ -253,6 +254,22 @@ protected function processMethod($method)
$this->messages[$methodName.'Request']=$message;
+ $n=preg_match_all('/^@header\s+([\w\.]+(\[\s*\])?)\s*?(.*)$/im',$comment,$matches);
+ for($i=0;$i<$n;++$i)
+ $headers[$matches[1][$i]]=array($this->processType($matches[1][$i]),trim($matches[3][$i])); // name => type, doc
+
+ if ($headers !== array())
+ {
+ $this->messages[$methodName.'Headers']=$headers;
+ $headerKeys = array_keys($headers);
+ $firstHeaderKey = reset($headerKeys);
+ $firstHeader = $headers[$firstHeaderKey];
+ }
+ else
+ {
+ $firstHeader = null;
+ }
+
if(preg_match('/^@return\s+([\w\.]+(\[\s*\])?)\s*?(.*)$/im',$comment,$matches))
$return=array($this->processType($matches[1]),trim($matches[2])); // type, doc
else
@@ -263,7 +280,10 @@ protected function processMethod($method)
$doc=trim($matches[1]);
else
$doc='';
- $this->operations[$methodName]=$doc;
+ $this->operations[$methodName]=array(
+ 'doc'=>$doc,
+ 'headers'=>$firstHeader === null ? null : array('input'=>array($methodName.'Headers', $firstHeaderKey)),
+ );
}
/**
@@ -539,8 +559,8 @@ protected function addPortTypes($dom)
$portType=$dom->createElement('wsdl:portType');
$portType->setAttribute('name',$this->serviceName.'PortType');
$dom->documentElement->appendChild($portType);
- foreach($this->operations as $name=>$doc)
- $portType->appendChild($this->createPortElement($dom,$name,$doc));
+ foreach($this->operations as $name=>$operation)
+ $portType->appendChild($this->createPortElement($dom,$name,$operation['doc']));
}
/**
@@ -581,15 +601,16 @@ protected function addBindings($dom)
$dom->documentElement->appendChild($binding);
- foreach($this->operations as $name=>$doc)
- $binding->appendChild($this->createOperationElement($dom,$name));
+ foreach($this->operations as $name=>$operation)
+ $binding->appendChild($this->createOperationElement($dom,$name,$operation['headers']));
}
/**
* @param DOMDocument $dom Represents an entire HTML or XML document; serves as the root of the document tree
* @param string $name method name
+ * @param array $headers array like array('input'=>array(MESSAGE,PART),'output=>array(MESSAGE,PART))
*/
- protected function createOperationElement($dom,$name)
+ protected function createOperationElement($dom,$name,$headers=null)
{
$operation=$dom->createElement('wsdl:operation');
$operation->setAttribute('name', $name);
@@ -606,6 +627,29 @@ protected function createOperationElement($dom,$name)
$soapBody->setAttribute('encodingStyle', 'http://schemas.xmlsoap.org/soap/encoding/');
$input->appendChild($soapBody);
$output->appendChild(clone $soapBody);
+ if (is_array($headers))
+ {
+ if (isset($headers['input']) && is_array($headers['input']) && count($headers['input'])==2)
+ {
+ $soapHeader = $dom->createElement('soap:header');
+ $soapHeader->setAttribute('use', 'encoded');
+ $soapHeader->setAttribute('namespace', $this->namespace);
+ $soapHeader->setAttribute('encodingStyle', 'http://schemas.xmlsoap.org/soap/encoding/');
+ $soapHeader->setAttribute('message', $headers['input'][0]);
+ $soapHeader->setAttribute('part', $headers['input'][1]);
+ $input->appendChild($soapHeader);
+ }
+ if (isset($headers['output']) && is_array($headers['output']) && count($headers['output'])==2)
+ {
+ $soapHeader = $dom->createElement('soap:header');
+ $soapHeader->setAttribute('use', 'encoded');
+ $soapHeader->setAttribute('namespace', $this->namespace);
+ $soapHeader->setAttribute('encodingStyle', 'http://schemas.xmlsoap.org/soap/encoding/');
+ $soapHeader->setAttribute('message', $headers['output'][0]);
+ $soapHeader->setAttribute('part', $headers['output'][1]);
+ $output->appendChild($soapHeader);
+ }
+ }
$operation->appendChild($soapOperation);
$operation->appendChild($input);
Please sign in to comment.
Something went wrong with that request. Please try again.