Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'ZendSoap' of https://github.com/beberlei/zf2 into featu…
Browse files Browse the repository at this point in the history
…re/soap-autodiscover-refactor
  • Loading branch information
Show file tree
Hide file tree
Showing 20 changed files with 652 additions and 681 deletions.
414 changes: 194 additions & 220 deletions src/AutoDiscover.php

Large diffs are not rendered by default.

83 changes: 83 additions & 0 deletions src/AutoDiscover/DiscoveryStrategy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Soap
* @subpackage WSDL
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* @namespace
*/
namespace Zend\Soap\AutoDiscover;

use Zend\Server\Reflection\AbstractFunction,
Zend\Server\Reflection\Prototype,
Zend\Server\Reflection\ReflectionParameter;

/**
* Describes how types, return values and method details are detected during AutoDiscovery of a WSDL.
*
* @category Zend
* @package Zend_Soap
* @subpackage WSDL
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface DiscoveryStrategy
{
/**
* Get the function parameters php type.
*
* Default implementation assumes the default param doc-block tag.
*
* @param ReflectionParameter $param
* @return string
*/
public function getFunctionParameterType(ReflectionParameter $param);

/**
* Get the functions return php type.
*
* Default implementation assumes the value of the return doc-block tag.
*
* @param AbstractFunction $function
* @param Prototype $prototype
* @return string
*/
public function getFunctionReturnType(AbstractFunction $function, Prototype $prototype);

/**
* Detect if the function is a one-way or two-way operation.
*
* Default implementation assumes one-way, when return value is "void".
*
* @param AbstractFunction $function
* @param Prototype $prototype
* @return bool
*/
public function isFunctionOneWay(AbstractFunction $function, Prototype $prototype);

/**
* Detect the functions documentation.
*
* Default implementation uses docblock description.
*
* @param AbstractFunction $function
* @return string
*/
public function getFunctionDocumentation(AbstractFunction $function);
}
63 changes: 63 additions & 0 deletions src/AutoDiscover/DiscoveryStrategy/ReflectionDiscovery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Soap
* @subpackage WSDL
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* @namespace
*/
namespace Zend\Soap\AutoDiscover\DiscoveryStrategy;

use Zend\Soap\AutoDiscover\DiscoveryStrategy,
Zend\Server\Reflection\AbstractFunction,
Zend\Server\Reflection\Prototype,
Zend\Server\Reflection\ReflectionParameter;

/**
* Describes how types, return values and method details are detected during AutoDiscovery of a WSDL.
*
* @category Zend
* @package Zend_Soap
* @subpackage WSDL
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

class ReflectionDiscovery implements DiscoveryStrategy
{
public function getFunctionDocumentation(AbstractFunction $function)
{
return $function->getDescription();
}

public function getFunctionParameterType(ReflectionParameter $param)
{
return $param->getType();
}

public function getFunctionReturnType(AbstractFunction $function, Prototype $prototype)
{
return $prototype->getReturnType();
}

public function isFunctionOneWay(AbstractFunction $function, Prototype $prototype)
{
return $prototype->getReturnType() == 'void';
}
}
68 changes: 42 additions & 26 deletions src/Wsdl.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
namespace Zend\Soap;

use DOMDocument,
Zend\Uri\Uri;
Zend\Uri\Uri,
Zend\Soap\Wsdl\ComplexTypeStrategy;

/**
* \Zend\Soap\Wsdl
Expand Down Expand Up @@ -68,20 +69,27 @@ class Wsdl
*/
protected $_strategy = null;

/**
* Map of PHP Class names to WSDL QNames.
*
* @var array
*/
protected $_classMap = array();

/**
* Constructor
*
* @param string $name Name of the Web Service being Described
* @param string|Uri $uri URI where the WSDL will be available
* @param boolean|string|\Zend\Soap\Wsdl\Strategy $strategy
* @param \Zend\Soap\Wsdl\ComplexTypeStrategy $strategy
*/
public function __construct($name, $uri, $strategy = true)
public function __construct($name, $uri, ComplexTypeStrategy $strategy = null, array $classMap = array())
{
if ($uri instanceof Uri) {
$uri = $uri->toString();
}
$this->_uri = $uri;
$this->_classMap = $classMap;

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

$this->setComplexTypeStrategy($strategy);
$this->setComplexTypeStrategy($strategy ?: new Wsdl\ComplexTypeStrategy\DefaultComplexType);
}

/**
* Get the class map of php to wsdl qname types.
*
* @return array
*/
public function getClassMap()
{
return $this->_classMap;
}

/**
* Set the class map of php to wsdl qname types.
*/
public function setClassMap($classMap)
{
$this->_classMap = $classMap;
}

/**
Expand Down Expand Up @@ -133,37 +159,19 @@ public function setUri($uri)
/**
* Set a strategy for complex type detection and handling
*
* @todo Boolean is for backwards compability with extractComplexType object var. Remove it in later versions.
* @param boolean|string|\Zend\Soap\Wsdl\Strategy $strategy
* @param \Zend\Soap\Wsdl\ComplexTypeStrategy $strategy
* @return \Zend\Soap\Wsdl
*/
public function setComplexTypeStrategy($strategy)
public function setComplexTypeStrategy(ComplexTypeStrategy $strategy)
{
if($strategy === true) {
$strategy = new Wsdl\Strategy\DefaultComplexType();
} else if($strategy === false) {
$strategy = new Wsdl\Strategy\AnyType();
} else if(is_string($strategy)) {
if(class_exists($strategy)) {
$strategy = new $strategy();
} else {
throw new Exception\InvalidArgumentException(
sprintf("Strategy with name '%s does not exist.", $strategy
));
}
}

if(!($strategy instanceof Wsdl\Strategy)) {
throw new Exception\InvalidArgumentException('Set a strategy that is not of type \'Zend\Soap\Wsdl\Strategy\'');
}
$this->_strategy = $strategy;
return $this;
}

/**
* Get the current complex type strategy
*
* @return \Zend\Soap\Wsdl\Strategy
* @return \Zend\Soap\Wsdl\ComplexTypeStrategy
*/
public function getComplexTypeStrategy()
{
Expand Down Expand Up @@ -585,12 +593,20 @@ public function addSchemaTypeSection()
* @param string $type
* @return string QName
*/
public static function translateType($type)
public function translateType($type)
{
if (isset($this->_classMap[$type])) {
return $this->_classMap[$type];
}

if ($type[0] == '\\') {
$type = substr($type, 1);
}

if ($pos = strrpos($type, '\\')) {
$type = substr($type, $pos+1);
}

return str_replace('\\', '.', $type);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Wsdl/Strategy.php → src/Wsdl/ComplexTypeStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
namespace Zend\Soap\Wsdl;

/**
* Interface for Zend_Soap_Wsdl_Strategy.
* Interface strategies that generate an XSD-Schema for complex data types in WSDL files.
*
* @category Zend
* @package Zend_Soap
* @subpackage WSDL
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Strategy
interface ComplexTypeStrategy
{
/**
* Method accepts the current WSDL context file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
/**
* @namespace
*/
namespace Zend\Soap\Wsdl\Strategy;
namespace Zend\Soap\Wsdl\ComplexTypeStrategy;

use Zend\Soap\Wsdl\Strategy;
use Zend\Soap\Wsdl\ComplexTypeStrategy;

/**
* Abstract class for Zend_Soap_Wsdl_Strategy.
Expand All @@ -36,7 +36,7 @@
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class AbstractStrategy implements Strategy
abstract class AbstractComplexTypeStrategy implements ComplexTypeStrategy
{
/**
* Context object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
/**
* @namespace
*/
namespace Zend\Soap\Wsdl\Strategy;
namespace Zend\Soap\Wsdl\ComplexTypeStrategy;

use Zend\Soap\Wsdl\Strategy;
use Zend\Soap\Wsdl\ComplexTypeStrategy;

/**
* Zend_Soap_Wsdl_Strategy_AnyType
Expand All @@ -36,7 +36,7 @@
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class AnyType implements Strategy
class AnyType implements ComplexTypeStrategy
{
/**
* Not needed in this strategy.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/**
* @namespace
*/
namespace Zend\Soap\Wsdl\Strategy;
namespace Zend\Soap\Wsdl\ComplexTypeStrategy;

use Zend\Soap;

Expand Down Expand Up @@ -83,7 +83,7 @@ protected function _addArrayOfComplexType($singularType, $type)
return $soapType;
}

$xsdComplexTypeName = 'ArrayOf' . Wsdl::translateType($singularType);
$xsdComplexTypeName = 'ArrayOf' . $this->getContext()->translateType($singularType);
$xsdComplexType = 'tns:' . $xsdComplexTypeName;

// Register type here to avoid recursion
Expand All @@ -109,7 +109,7 @@ protected function _addArrayOfComplexType($singularType, $type)
$xsdAttribute = $dom->createElement('xsd:attribute');
$xsdAttribute->setAttribute('ref', 'soap-enc:arrayType');
$xsdAttribute->setAttribute('wsdl:arrayType',
'tns:' . Wsdl::translateType($singularType) . '[]');
'tns:' . $this->getContext()->translateType($singularType) . '[]');
$xsdRestriction->appendChild($xsdAttribute);

$this->getContext()->getSchema()->appendChild($complexType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* @namespace
*/
namespace Zend\Soap\Wsdl\Strategy;
namespace Zend\Soap\Wsdl\ComplexTypeStrategy;

use Zend\Soap\Wsdl;

Expand Down Expand Up @@ -81,7 +81,7 @@ protected function _getTypeBasedOnNestingLevel($singularType, $level)
// This is not an Array anymore, return the xsd simple type
return $this->getContext()->getType($singularType);
} else {
return 'tns:' . str_repeat('ArrayOf', $level) . ucfirst(Wsdl::translateType($singularType));
return 'tns:' . str_repeat('ArrayOf', $level) . ucfirst($this->getContext()->translateType($singularType));
}
}

Expand Down
Loading

0 comments on commit b636e56

Please sign in to comment.