Skip to content

Commit

Permalink
Fix generating DocumentLiteralWrapper.
Browse files Browse the repository at this point in the history
Passing style object to the setter.
Add methodName parameter to the ParameterFactory.
  • Loading branch information
piotrooo committed Mar 31, 2014
1 parent 12adac0 commit 1e84c9c
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 145 deletions.
21 changes: 6 additions & 15 deletions src/WSDL/WSDLCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
*/
namespace WSDL;

use Exception;
use WSDL\Parser\ClassParser;
use WSDL\Service\Service;
use WSDL\XML\Styles\DocumentLiteralWrapped;
use WSDL\XML\Styles\RpcEncoded;
use WSDL\XML\Styles\RpcLiteral;
use WSDL\XML\Styles\Style;
use WSDL\XML\XMLGenerator;
Expand Down Expand Up @@ -65,20 +64,12 @@ private function _addSlashAtEndIfNotExists($namespace)
return rtrim($namespace, '/') . '/';
}

public function setBindingStyle($style)
public function setBindingStyle(Style $style = null)
{
$style = strtolower($style);
switch ($style) {
case Style::RPC_LITERAL:
$this->_bindingStyle = new RpcLiteral();
break;
case Style::RPC_ENCODED;
$this->_bindingStyle = new RpcEncoded();
break;
case Style::DOCUMENT_LITERAL_WRAPPED;
$this->_bindingStyle = new DocumentLiteralWrapped();
break;
};
if (!$style) {
throw new Exception('Incorrect binding style.');
}
$this->_bindingStyle = $style;
return $this;
}

Expand Down
82 changes: 16 additions & 66 deletions src/WSDL/XML/Styles/DocumentLiteralWrapped.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function methodOutput(MethodParser $method)
private function _createPart(MethodParser $method, $type = '')
{
$name = 'parameters';
$elementName = $method->getName() . $type . 'Parameters';
$elementName = 'ns:' . $method->getName() . $type . 'Parameters';
$element = array(
'name' => $name,
'element' => $elementName
Expand All @@ -45,80 +45,30 @@ private function _createPart(MethodParser $method, $type = '')

public function typeParameters(MethodParser $method)
{
$elements = array();
$element = new TypesElement();
$element->setName($method->getName() . 'RequestParameters');
foreach ($method->parameters() as $parameter) {
$elements[] = $this->_generateTypeToDocumentWrapper($parameter, $method, 'Request');
$this->_generateElements($parameter, $element);
}
return $elements;
return array($element);
}

public function typeReturning(MethodParser $method)
{
return $this->_generateTypeToDocumentWrapper($method->returning(), $method, 'Response');
}

public function _generateTypeToDocumentWrapper($parameter, MethodParser $method, $type)
{
if (TypeHelper::isSimple($parameter)) {
$generateComplexType = $this->_generateDocumentSimpleType($method, $type);
if ($generateComplexType) {
return $generateComplexType;
}
} else {
$generateComplexType = $this->_generateDocumentComplexType($parameter, $methodName, $type);
if ($generateComplexType) {
return $generateComplexType;
}
}
return null;
}

private function _generateDocumentSimpleType(MethodParser $method, $type)
{
$typeElement = new TypesElement();
$typeElement->setName($method->getName() . $type . 'Parameters');

if ($type == 'Request') {
foreach ($method->parameters() as $parameter) {
$parameterType = TypeHelper::getXsdType($parameter->getType());
$typeElement->setElementAttributes('type', $parameterType, $parameter->getName());
}
} else {
$returning = $method->returning();
$returningType = TypeHelper::getXsdType($returning->getType());
$typeElement->setElementAttributes('type', $returningType, $returning->getName());
}
return $typeElement;
}

private function _generateDocumentComplexType(Type $parameter, $methodName, $type)
{
if (TypeHelper::isArray($parameter)) {
return $this->_generateDocumentArray($parameter, $methodName, $type);
}
if (TypeHelper::isObject($parameter)) {
return $this->_generateObject($parameter, $methodName, $type);
}
return null;
$element = new TypesElement();
$element->setName($method->getName() . 'ResponseParameters');
$returning = $method->returning();
$this->_generateElements($returning, $element);
return $element;
}

private function _generateDocumentArray(Type $parameter, $methodName, $typeName)
private function _generateElements(Type $parameter, TypesElement $element)
{
$typesElement = new TypesElement();
$typesElement->setName($methodName . $typeName . 'Parameters');

$type = $parameter->getComplexType() ? 'ns:' : 'xsd:';

$typesComplex = new TypesComplex();
$typesComplex
->setName('ArrayOf' . ucfirst($parameter->getName()))
->setArrayType($type . $this->_getObjectName($parameter) . '[]');

if ($parameter->getComplexType()) {
$typesComplex->setComplex($this->_generateObject($parameter->getComplexType()));
list($type, $value) = $this->_prepareTypeAndValue($parameter);
$element->setElementAttributes($type, $value, $parameter->getName());
if (!TypeHelper::isSimple($parameter)) {
$complexType = $this->_generateComplexType($parameter);
$element->setComplex($complexType);
}

$typesElement->setComplex($typesComplex);
return $typesElement;
}
}
4 changes: 0 additions & 4 deletions src/WSDL/XML/Styles/Style.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@

abstract class Style
{
const RPC_LITERAL = 'rpc/literal';
const RPC_ENCODED = 'rpc/encoded';
const DOCUMENT_LITERAL_WRAPPED = 'document/literal wrapped';

abstract public function bindingStyle();

abstract public function bindingUse();
Expand Down
24 changes: 12 additions & 12 deletions tests/Factory/ParameterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,39 @@

class ParameterFactory
{
public static function createParameterForSimpleArray()
public static function createParameterForSimpleArray($methodName = '')
{
$doc = '/**@param string[] $names*/';
return new MethodParser('', $doc);
return new MethodParser($methodName, $doc);
}

public static function createParameterForSimpleObject()
public static function createParameterForSimpleObject($methodName = '')
{
$doc = '/**@param object $info @string=$name @int=$age*/';
return new MethodParser('', $doc);
return new MethodParser($methodName, $doc);
}

public static function createParameterForObjectWithWrapper()
public static function createParameterForObjectWithWrapper($methodName = '')
{
$doc = '/**@param object $agentNameWithId @(wrapper $agent @className=\Mocks\MockUserWrapper) @int=$id*/';
return new MethodParser('', $doc);
return new MethodParser($methodName, $doc);
}

public static function createParameterForObjectWithArrayOfSimpleType()
public static function createParameterForObjectWithArrayOfSimpleType($methodName = '')
{
$doc = '/**@param object $namesInfo @string[]=$names @int=$id*/';
return new MethodParser('', $doc);
return new MethodParser($methodName, $doc);
}

public static function createParameterForArrayOfObjects()
public static function createParameterForArrayOfObjects($methodName = '')
{
$doc = '/**@param object[] $companies @string=$name @int=$id*/';
return new MethodParser('', $doc);
return new MethodParser($methodName, $doc);
}

public static function createParameterObjectWithArrayOfWrapper()
public static function createParameterObjectWithArrayOfWrapper($methodName = '')
{
$doc = '/**@param object $listOfAgents @(wrapper[] $agents @className=\Mocks\MockUserWrapper) @int=$id*/';
return new MethodParser('', $doc);
return new MethodParser($methodName, $doc);
}
}

0 comments on commit 1e84c9c

Please sign in to comment.