Skip to content

Commit 41b2cf7

Browse files
author
craigmarvelley
committed
Updated to latest version of Zend\Soap
1 parent d075e5e commit 41b2cf7

14 files changed

+1188
-259
lines changed

AutoDiscover.php

Lines changed: 207 additions & 214 deletions
Large diffs are not rendered by default.

AutoDiscover/DiscoveryStrategy.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/**
3+
* Zend Framework
4+
*
5+
* LICENSE
6+
*
7+
* This source file is subject to the new BSD license that is bundled
8+
* with this package in the file LICENSE.txt.
9+
* It is also available through the world-wide-web at this URL:
10+
* http://framework.zend.com/license/new-bsd
11+
* If you did not receive a copy of the license and are unable to
12+
* obtain it through the world-wide-web, please send an email
13+
* to [email protected] so we can send you a copy immediately.
14+
*
15+
* @category Zend
16+
* @package Zend_Soap
17+
* @subpackage WSDL
18+
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
19+
* @license http://framework.zend.com/license/new-bsd New BSD License
20+
*/
21+
22+
/**
23+
* @namespace
24+
*/
25+
namespace Zend\Soap\AutoDiscover;
26+
27+
use Zend\Server\Reflection\AbstractFunction,
28+
Zend\Server\Reflection\Prototype,
29+
Zend\Server\Reflection\ReflectionParameter;
30+
31+
/**
32+
* Describes how types, return values and method details are detected during AutoDiscovery of a WSDL.
33+
*
34+
* @category Zend
35+
* @package Zend_Soap
36+
* @subpackage WSDL
37+
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
38+
* @license http://framework.zend.com/license/new-bsd New BSD License
39+
*/
40+
interface DiscoveryStrategy
41+
{
42+
/**
43+
* Get the function parameters php type.
44+
*
45+
* Default implementation assumes the default param doc-block tag.
46+
*
47+
* @param ReflectionParameter $param
48+
* @return string
49+
*/
50+
public function getFunctionParameterType(ReflectionParameter $param);
51+
52+
/**
53+
* Get the functions return php type.
54+
*
55+
* Default implementation assumes the value of the return doc-block tag.
56+
*
57+
* @param AbstractFunction $function
58+
* @param Prototype $prototype
59+
* @return string
60+
*/
61+
public function getFunctionReturnType(AbstractFunction $function, Prototype $prototype);
62+
63+
/**
64+
* Detect if the function is a one-way or two-way operation.
65+
*
66+
* Default implementation assumes one-way, when return value is "void".
67+
*
68+
* @param AbstractFunction $function
69+
* @param Prototype $prototype
70+
* @return bool
71+
*/
72+
public function isFunctionOneWay(AbstractFunction $function, Prototype $prototype);
73+
74+
/**
75+
* Detect the functions documentation.
76+
*
77+
* Default implementation uses docblock description.
78+
*
79+
* @param AbstractFunction $function
80+
* @return string
81+
*/
82+
public function getFunctionDocumentation(AbstractFunction $function);
83+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* Zend Framework
4+
*
5+
* LICENSE
6+
*
7+
* This source file is subject to the new BSD license that is bundled
8+
* with this package in the file LICENSE.txt.
9+
* It is also available through the world-wide-web at this URL:
10+
* http://framework.zend.com/license/new-bsd
11+
* If you did not receive a copy of the license and are unable to
12+
* obtain it through the world-wide-web, please send an email
13+
* to [email protected] so we can send you a copy immediately.
14+
*
15+
* @category Zend
16+
* @package Zend_Soap
17+
* @subpackage WSDL
18+
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
19+
* @license http://framework.zend.com/license/new-bsd New BSD License
20+
*/
21+
22+
/**
23+
* @namespace
24+
*/
25+
namespace Zend\Soap\AutoDiscover\DiscoveryStrategy;
26+
27+
use Zend\Soap\AutoDiscover\DiscoveryStrategy,
28+
Zend\Server\Reflection\AbstractFunction,
29+
Zend\Server\Reflection\Prototype,
30+
Zend\Server\Reflection\ReflectionParameter;
31+
32+
/**
33+
* Describes how types, return values and method details are detected during AutoDiscovery of a WSDL.
34+
*
35+
* @category Zend
36+
* @package Zend_Soap
37+
* @subpackage WSDL
38+
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
39+
* @license http://framework.zend.com/license/new-bsd New BSD License
40+
*/
41+
42+
class ReflectionDiscovery implements DiscoveryStrategy
43+
{
44+
public function getFunctionDocumentation(AbstractFunction $function)
45+
{
46+
return $function->getDescription();
47+
}
48+
49+
public function getFunctionParameterType(ReflectionParameter $param)
50+
{
51+
return $param->getType();
52+
}
53+
54+
public function getFunctionReturnType(AbstractFunction $function, Prototype $prototype)
55+
{
56+
return $prototype->getReturnType();
57+
}
58+
59+
public function isFunctionOneWay(AbstractFunction $function, Prototype $prototype)
60+
{
61+
return $prototype->getReturnType() == 'void';
62+
}
63+
}

Client.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ public function getOptions()
313313
* ugly hack as I don't know if checking for '=== null'
314314
* breaks some other option
315315
*/
316-
if ($key == 'user_agent') {
316+
if (in_array($key, array('user_agent', 'cache_wsdl', 'compression'))) {
317317
if ($value === null) {
318318
unset($options[$key]);
319319
}
@@ -752,13 +752,16 @@ public function getHttpsCertPassphrase()
752752
/**
753753
* Set compression options
754754
*
755-
* @param int $compressionOptions
755+
* @param int|null $compressionOptions
756756
* @return \Zend\Soap\Client\Client
757757
*/
758758
public function setCompressionOptions($compressionOptions)
759759
{
760-
$this->_compression = $compressionOptions;
761-
760+
if ($compressionOptions === null) {
761+
$this->_compression = null;
762+
} else {
763+
$this->_compression = (int)$compressionOptions;
764+
}
762765
$this->_soapClient = null;
763766

764767
return $this;
@@ -836,17 +839,23 @@ public function getSoapFeatures()
836839
/**
837840
* Set the SOAP WSDL Caching Options
838841
*
839-
* @param string|int|boolean $caching
842+
* @param string|int|boolean|null $caching
840843
* @return \Zend\Soap\Client\Client
841844
*/
842-
public function setWSDLCache($options)
845+
public function setWSDLCache($caching)
843846
{
844-
$this->_cache_wsdl = $options;
847+
if ($caching === null) {
848+
$this->_cache_wsdl = null;
849+
} else {
850+
$this->_cache_wsdl = (int)$caching;
851+
}
845852
return $this;
846853
}
847854

848855
/**
849856
* Get current SOAP WSDL Caching option
857+
*
858+
* @return int
850859
*/
851860
public function getWSDLCache()
852861
{

Client/Local.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ public function _doRequest(Common $client, $request, $location, $action, $versio
8484
// Perform request as is
8585
ob_start();
8686
$this->_server->handle($request);
87-
$response = ob_get_contents();
88-
ob_end_clean();
87+
$response = ob_get_clean();
8988

9089
return $response;
9190
}

Server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ public function handle($request = null)
809809
$soap->fault("Sender", $setRequestException->getMessage());
810810
} else {
811811
try {
812-
$soap->handle($request);
812+
$soap->handle($this->_request);
813813
} catch (\Exception $e) {
814814
$fault = $this->fault($e);
815815
$soap->fault($fault->faultcode, $fault->faultstring);

Wsdl.php

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
namespace Zend\Soap;
2525

2626
use DOMDocument,
27-
Zend\Uri\Uri;
27+
Zend\Uri\Uri,
28+
Zend\Soap\Wsdl\ComplexTypeStrategy;
2829

2930
/**
3031
* \Zend\Soap\Wsdl
@@ -68,20 +69,27 @@ class Wsdl
6869
*/
6970
protected $_strategy = null;
7071

72+
/**
73+
* Map of PHP Class names to WSDL QNames.
74+
*
75+
* @var array
76+
*/
77+
protected $_classMap = array();
7178

7279
/**
7380
* Constructor
7481
*
7582
* @param string $name Name of the Web Service being Described
7683
* @param string|Uri $uri URI where the WSDL will be available
77-
* @param boolean|string|\Zend\Soap\Wsdl\Strategy $strategy
84+
* @param \Zend\Soap\Wsdl\ComplexTypeStrategy $strategy
7885
*/
79-
public function __construct($name, $uri, $strategy = true)
86+
public function __construct($name, $uri, ComplexTypeStrategy $strategy = null, array $classMap = array())
8087
{
8188
if ($uri instanceof Uri) {
8289
$uri = $uri->toString();
8390
}
8491
$this->_uri = $uri;
92+
$this->_classMap = $classMap;
8593

8694
/**
8795
* @todo change DomDocument object creation from cparsing to constructing using API
@@ -102,7 +110,25 @@ public function __construct($name, $uri, $strategy = true)
102110
$this->_wsdl = $this->_dom->documentElement;
103111
}
104112

105-
$this->setComplexTypeStrategy($strategy);
113+
$this->setComplexTypeStrategy($strategy ?: new Wsdl\ComplexTypeStrategy\DefaultComplexType);
114+
}
115+
116+
/**
117+
* Get the class map of php to wsdl qname types.
118+
*
119+
* @return array
120+
*/
121+
public function getClassMap()
122+
{
123+
return $this->_classMap;
124+
}
125+
126+
/**
127+
* Set the class map of php to wsdl qname types.
128+
*/
129+
public function setClassMap($classMap)
130+
{
131+
$this->_classMap = $classMap;
106132
}
107133

108134
/**
@@ -133,37 +159,19 @@ public function setUri($uri)
133159
/**
134160
* Set a strategy for complex type detection and handling
135161
*
136-
* @todo Boolean is for backwards compability with extractComplexType object var. Remove it in later versions.
137-
* @param boolean|string|\Zend\Soap\Wsdl\Strategy $strategy
162+
* @param \Zend\Soap\Wsdl\ComplexTypeStrategy $strategy
138163
* @return \Zend\Soap\Wsdl
139164
*/
140-
public function setComplexTypeStrategy($strategy)
165+
public function setComplexTypeStrategy(ComplexTypeStrategy $strategy)
141166
{
142-
if($strategy === true) {
143-
$strategy = new Wsdl\Strategy\DefaultComplexType();
144-
} else if($strategy === false) {
145-
$strategy = new Wsdl\Strategy\AnyType();
146-
} else if(is_string($strategy)) {
147-
if(class_exists($strategy)) {
148-
$strategy = new $strategy();
149-
} else {
150-
throw new Exception\InvalidArgumentException(
151-
sprintf("Strategy with name '%s does not exist.", $strategy
152-
));
153-
}
154-
}
155-
156-
if(!($strategy instanceof Wsdl\Strategy)) {
157-
throw new Exception\InvalidArgumentException('Set a strategy that is not of type \'Zend\Soap\Wsdl\Strategy\'');
158-
}
159167
$this->_strategy = $strategy;
160168
return $this;
161169
}
162170

163171
/**
164172
* Get the current complex type strategy
165173
*
166-
* @return \Zend\Soap\Wsdl\Strategy
174+
* @return \Zend\Soap\Wsdl\ComplexTypeStrategy
167175
*/
168176
public function getComplexTypeStrategy()
169177
{
@@ -314,8 +322,8 @@ public function addBindingOperation($binding, $name, $input = false, $output = f
314322
if (isset($fault['name'])) {
315323
$node->setAttribute('name', $fault['name']);
316324
}
317-
$soap_node = $this->_dom->createElement('soap:body');
318-
foreach ($output as $name => $value) {
325+
$soap_node = $this->_dom->createElement('soap:fault');
326+
foreach ($fault as $name => $value) {
319327
$soap_node->setAttribute($name, $value);
320328
}
321329
$node->appendChild($soap_node);
@@ -532,28 +540,23 @@ public function getType($type)
532540
case 'string':
533541
case 'str':
534542
return 'xsd:string';
535-
break;
543+
case 'long':
544+
return 'xsd:long';
536545
case 'int':
537546
case 'integer':
538547
return 'xsd:int';
539-
break;
540548
case 'float':
541549
case 'double':
542550
return 'xsd:float';
543-
break;
544551
case 'boolean':
545552
case 'bool':
546553
return 'xsd:boolean';
547-
break;
548554
case 'array':
549555
return 'soap-enc:Array';
550-
break;
551556
case 'object':
552557
return 'xsd:struct';
553-
break;
554558
case 'mixed':
555559
return 'xsd:anyType';
556-
break;
557560
case 'void':
558561
return '';
559562
default:
@@ -585,12 +588,20 @@ public function addSchemaTypeSection()
585588
* @param string $type
586589
* @return string QName
587590
*/
588-
public static function translateType($type)
591+
public function translateType($type)
589592
{
593+
if (isset($this->_classMap[$type])) {
594+
return $this->_classMap[$type];
595+
}
596+
590597
if ($type[0] == '\\') {
591598
$type = substr($type, 1);
592599
}
593600

601+
if ($pos = strrpos($type, '\\')) {
602+
$type = substr($type, $pos+1);
603+
}
604+
594605
return str_replace('\\', '.', $type);
595606
}
596607

0 commit comments

Comments
 (0)