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

Commit

Permalink
Merged Source/Master
Browse files Browse the repository at this point in the history
  • Loading branch information
francisdaigle committed Mar 13, 2013
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 49 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.4-dev",
"dev-develop": "2.5-dev"
"dev-master": "2.1-dev",
"dev-develop": "2.2-dev"
}
},
"autoload-dev": {
Expand Down
74 changes: 48 additions & 26 deletions src/AutoDiscover.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace Zend\Soap;

use Zend\Server\Reflection;
use Zend\Server\Reflection\AbstractFunction;
use Zend\Soap\AutoDiscover\DiscoveryStrategy\DiscoveryStrategyInterface as DiscoveryStrategy;
use Zend\Soap\AutoDiscover\DiscoveryStrategy\ReflectionDiscovery;
use Zend\Soap\Wsdl;
Expand Down Expand Up @@ -96,27 +95,26 @@ class AutoDiscover
/**
* Constructor
*
* @param ComplexTypeStrategy $strategy
* @param string|Uri\Uri $endpointUri
* @param string $wsdlClass
* @param array $classMap
* @param null|ComplexTypeStrategy $strategy
* @param null|string|Uri\Uri $endpointUri
* @param null|string $wsdlClass
* @param null|array $classMap
*/
public function __construct(ComplexTypeStrategy $strategy = null, $endpointUri=null, $wsdlClass=null, array $classMap = array())
public function __construct(ComplexTypeStrategy $strategy = null, $endpointUri = null, $wsdlClass = null, array $classMap = array())
{
$this->reflection = new Reflection();
$this->discoveryStrategy = new ReflectionDiscovery();

if ($strategy !== null) {
if (null !== $strategy) {
$this->setComplexTypeStrategy($strategy);
}

if ($endpointUri !== null) {
if (null !== $endpointUri) {
$this->setUri($endpointUri);
}

if ($wsdlClass !== null) {
if (null !== $wsdlClass) {
$this->setWsdlClass($wsdlClass);
}
$this->setClassMap($classMap);
}

/**
Expand Down Expand Up @@ -151,9 +149,19 @@ public function getClassMap()

/**
* Set the class map of php to wsdl qname types.
*
* @param array $classmap
* @return AutoDiscover
*/
public function setClassMap($classMap)
{
if (!is_array($classMap)) {
throw new Exception\InvalidArgumentException(sprintf(
'%s expects an array; received "%s"',
__METHOD__,
(is_object($classMap) ? get_class($classMap) : gettype($classMap))
));
}
$this->classMap = $classMap;
return $this;
}
Expand Down Expand Up @@ -183,9 +191,10 @@ public function getServiceName()
return $this->reflection->reflectClass($this->class)
->getShortName();
} else {
throw new Exception\RuntimeException(
"No service name given. Call Autodiscover::setServiceName()."
);
throw new Exception\RuntimeException(sprintf(
"No service name given. Call %s::setServiceName().",
__CLASS__
));
}
}

Expand All @@ -203,9 +212,10 @@ public function getServiceName()
public function setUri($uri)
{
if (!is_string($uri) && !($uri instanceof Uri\Uri)) {
throw new Exception\InvalidArgumentException(
'No uri given to \Zend\Soap\AutoDiscover::setUri as string or \Zend\Uri\Uri instance.'
);
throw new Exception\InvalidArgumentException(sprintf(
'No uri given to %s() as string or \Zend\Uri\Uri instance.',
__METHOD__
));
}
$this->uri = $uri;

Expand All @@ -221,7 +231,10 @@ public function setUri($uri)
public function getUri()
{
if ($this->uri === null) {
throw new Exception\RuntimeException("Missing uri. You have to explicitly configure the Endpoint Uri by calling AutoDiscover::setUri().");
throw new Exception\RuntimeException(sprintf(
"Missing uri. You have to explicitly configure the Endpoint Uri by calling %s::setUri().",
__CLASS__
));
}
if (is_string($this->uri)) {
$this->uri = Uri\UriFactory::factory($this->uri);
Expand All @@ -240,9 +253,11 @@ public function getUri()
public function setWsdlClass($wsdlClass)
{
if (!is_string($wsdlClass) && !is_subclass_of($wsdlClass, 'Zend\Soap\Wsdl')) {
throw new Exception\InvalidArgumentException(
'No \Zend\Soap\Wsdl subclass given to Zend\Soap\AutoDiscover::setWsdlClass as string.'
);
throw new Exception\InvalidArgumentException(sprintf(
'No %s\Wsdl subclass given to %s() as string.',
__NAMESPACE__,
__METHOD__
));
}
$this->wsdlClass = $wsdlClass;

Expand All @@ -269,7 +284,7 @@ public function getWsdlClass()
* @return AutoDiscover
* @throws Exception\InvalidArgumentException
*/
public function setOperationBodyStyle(array $operationStyle=array())
public function setOperationBodyStyle(array $operationStyle = array())
{
if (!isset($operationStyle['use'])) {
throw new Exception\InvalidArgumentException("Key 'use' is required in Operation soap:body style.");
Expand All @@ -286,7 +301,7 @@ public function setOperationBodyStyle(array $operationStyle=array())
* @param array $bindingStyle
* @return AutoDiscover
*/
public function setBindingStyle(array $bindingStyle=array())
public function setBindingStyle(array $bindingStyle = array())
{
if (isset($bindingStyle['style'])) {
$this->bindingStyle['style'] = $bindingStyle['style'];
Expand Down Expand Up @@ -414,7 +429,10 @@ protected function _addFunctionToWsdl($function, $wsdl, $port, $binding)
}
}
if ($prototype === null) {
throw new Exception\InvalidArgumentException("No prototypes could be found for the '" . $function->getName() . "' function");
throw new Exception\InvalidArgumentException(sprintf(
'No prototypes could be found for the "%s" function',
$function->getName()
));
}

$functionName = $wsdl->translateType($function->getName());
Expand Down Expand Up @@ -443,7 +461,9 @@ protected function _addFunctionToWsdl($function, $wsdl, $port, $binding)
} else {
// RPC style: add each parameter as a typed part
foreach ($prototype->getParameters() as $param) {
$args[$param->getName()] = array('type' => $wsdl->getType($this->discoveryStrategy->getFunctionParameterType($param)));
$args[$param->getName()] = array(
'type' => $wsdl->getType($this->discoveryStrategy->getFunctionParameterType($param))
);
}
}
$wsdl->addMessage($functionName . 'In', $args);
Expand All @@ -470,7 +490,9 @@ protected function _addFunctionToWsdl($function, $wsdl, $port, $binding)
$args['parameters'] = array('element' => $wsdl->addElement($element));
} elseif ($prototype->getReturnType() != "void") {
// RPC style: add the return value as a typed part
$args['return'] = array('type' => $wsdl->getType($this->discoveryStrategy->getFunctionReturnType($function, $prototype)));
$args['return'] = array(
'type' => $wsdl->getType($this->discoveryStrategy->getFunctionReturnType($function, $prototype))
);
}
$wsdl->addMessage($functionName . 'Out', $args);
}
Expand Down
12 changes: 9 additions & 3 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ public function getLastSoapOutputHeaderObjects()
*/
public function __call($name, $arguments)
{
if(!is_array($arguments)) {
if (!is_array($arguments)) {
$arguments = array($arguments);
}
$soapClient = $this->getSoapClient();
Expand Down Expand Up @@ -1109,7 +1109,10 @@ public function call($method, $params = array())
public function getFunctions()
{
if ($this->getWSDL() == null) {
throw new Exception\UnexpectedValueException(__METHOD__ . ' is available only in WSDL mode.');
throw new Exception\UnexpectedValueException(sprintf(
'%s method is available only in WSDL mode.',
__METHOD__
));
}

$soapClient = $this->getSoapClient();
Expand All @@ -1132,7 +1135,10 @@ public function getFunctions()
public function getTypes()
{
if ($this->getWSDL() == null) {
throw new Exception\UnexpectedValueException(__METHOD__ . ' method is available only in WSDL mode.');
throw new Exception\UnexpectedValueException(sprintf(
'%s method is available only in WSDL mode.',
__METHOD__
));
}

$soapClient = $this->getSoapClient();
Expand Down
19 changes: 15 additions & 4 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,11 +529,17 @@ public function setClass($class, $namespace = '', $argv = null)
}

if (!is_string($class)) {
throw new Exception\InvalidArgumentException('Invalid class argument (' . gettype($class) . ')');
throw new Exception\InvalidArgumentException(sprintf(
'Invalid class argument (%s)',
gettype($class)
));
}

if (!class_exists($class)) {
throw new Exception\InvalidArgumentException('Class "' . $class . '" does not exist');
throw new Exception\InvalidArgumentException(sprintf(
'Class "%s" does not exist',
$class
));
}

$this->class = $class;
Expand All @@ -557,11 +563,16 @@ public function setClass($class, $namespace = '', $argv = null)
public function setObject($object)
{
if (!is_object($object)) {
throw new Exception\InvalidArgumentException('Invalid object argument ('.gettype($object).')');
throw new Exception\InvalidArgumentException(sprintf(
'Invalid object argument (%s)',
gettype($object)
));
}

if (isset($this->object)) {
throw new Exception\InvalidArgumentException('An object has already been registered with this soap server instance');
throw new Exception\InvalidArgumentException(
'An object has already been registered with this soap server instance'
);
}

$this->object = $object;
Expand Down
12 changes: 8 additions & 4 deletions src/Server/DocumentLiteralWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ protected function _parseArguments($method, $document)
foreach (get_object_vars($document) as $argName => $argValue) {
if (!isset($params[$argName])) {
throw new UnexpectedValueException(sprintf(
"Received unknown argument %s which is not an argument to %s::%s",
$argName, get_class($this->object), $method
"Received unknown argument %s which is not an argument to %s::%s()",
$argName,
get_class($this->object),
$method
));
}
$delegateArgs[$params[$argName]->getPosition()] = $argValue;
Expand All @@ -147,7 +149,8 @@ protected function _assertServiceDelegateHasMethod($method)
if (!$this->reflection->hasMethod($method)) {
throw new BadMethodCallException(sprintf(
"Method %s does not exist on delegate object %s",
$method, get_class($this->object)
$method,
get_class($this->object)
));
}
}
Expand All @@ -157,7 +160,8 @@ protected function _assertOnlyOneArgument($args)
if (count($args) != 1) {
throw new UnexpectedValueException(sprintf(
"Expecting exactly one argument that is the document/literal wrapper, got %d",
count($args)));
count($args)
));
}
}
}
2 changes: 1 addition & 1 deletion src/Wsdl.php
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ public function addComplexType($type)
private function _parseElement($element)
{
if (!is_array($element)) {
throw new Exception\RuntimeException("The 'element' parameter needs to be an associative array.");
throw new Exception\RuntimeException('The "element" parameter needs to be an associative array.');
}

$elementXml = $this->dom->createElement(self::XSD_NS . ':element');
Expand Down
14 changes: 8 additions & 6 deletions src/Wsdl/ComplexTypeStrategy/Composite.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ public function getStrategyOfType($type)
}

if ( !($strategy instanceof ComplexTypeStrategy) ) {
throw new Exception\InvalidArgumentException(
"Strategy for Complex Type '$type' is not a valid strategy object."
);
throw new Exception\InvalidArgumentException(sprintf(
'Strategy for Complex Type "%s" is not a valid strategy object.',
$type
));
}
$this->typeMap[$type] = $strategy;
} else {
Expand Down Expand Up @@ -141,9 +142,10 @@ public function setContext(Wsdl $context)
public function addComplexType($type)
{
if (!($this->context instanceof Wsdl) ) {
throw new Exception\InvalidArgumentException(
"Cannot add complex type '$type', no context is set for this composite strategy."
);
throw new Exception\InvalidArgumentException(sprintf(
'Cannot add complex type "%s", no context is set for this composite strategy.',
$type
));
}

$strategy = $this->getStrategyOfType($type);
Expand Down
3 changes: 2 additions & 1 deletion src/Wsdl/ComplexTypeStrategy/DefaultComplexType.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public function addComplexType($type)
if (!class_exists($type)) {
throw new Exception\InvalidArgumentException(sprintf(
'Cannot add a complex type %s that is not an object or where '
. 'class could not be found in \'DefaultComplexType\' strategy.', $type
. 'class could not be found in "DefaultComplexType" strategy.',
$type
));
}

Expand Down
4 changes: 2 additions & 2 deletions test/Wsdl/CompositeStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function testCompositeThrowsExceptionOnInvalidStrategy()
$strategy = new ComplexTypeStrategy\Composite(array(), 'invalid');
$strategy->connectTypeToStrategy('Book', 'strategy');

$this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Strategy for Complex Type \'Book\' is not a valid strategy');
$this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Strategy for Complex Type "Book" is not a valid strategy');
$book = $strategy->getStrategyOfType('Book');
}

Expand Down Expand Up @@ -105,7 +105,7 @@ public function testCompositeRequiresContextForAddingComplexTypesOtherwiseThrows
{
$strategy = new ComplexTypeStrategy\Composite();

$this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Cannot add complex type \'Test\'');
$this->setExpectedException('Zend\Soap\Exception\InvalidArgumentException', 'Cannot add complex type "Test"');
$strategy->addComplexType('Test');
}
}
Expand Down

0 comments on commit e0c31db

Please sign in to comment.