Cleaned files
This commit is contained in:
@ -14,18 +14,18 @@ class Method
|
||||
{
|
||||
private $name;
|
||||
private $service;
|
||||
|
||||
|
||||
public function __construct($values)
|
||||
{
|
||||
$this->name = isset($values['value']) ? $values['value'] : null;
|
||||
$this->service = isset($values['service']) ? $values['service'] : null;
|
||||
}
|
||||
|
||||
|
||||
public function getName($default = null)
|
||||
{
|
||||
return $this->name !== null ? $this->name : $default;
|
||||
}
|
||||
|
||||
|
||||
public function getService()
|
||||
{
|
||||
return $this->service;
|
||||
|
@ -13,14 +13,14 @@ namespace Bundle\WebServiceBundle\ServiceDefinition\Annotation;
|
||||
class Param extends TypedElement
|
||||
{
|
||||
private $name;
|
||||
|
||||
|
||||
public function __construct($values)
|
||||
{
|
||||
parent::__construct($values);
|
||||
|
||||
|
||||
$this->name = $values['value'];
|
||||
}
|
||||
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
|
@ -11,7 +11,7 @@
|
||||
namespace Bundle\WebServiceBundle\ServiceDefinition\Annotation;
|
||||
|
||||
class Result extends TypedElement
|
||||
{
|
||||
{
|
||||
public function __construct($values)
|
||||
{
|
||||
parent::__construct($values);
|
||||
|
@ -14,7 +14,7 @@ abstract class TypedElement
|
||||
{
|
||||
private $phpType;
|
||||
private $xmlType;
|
||||
|
||||
|
||||
public function __construct($values)
|
||||
{
|
||||
foreach(array('type', 'phpType') as $key)
|
||||
@ -24,15 +24,15 @@ abstract class TypedElement
|
||||
$this->phpType = $values[$key];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->xmlType = isset($values['xmlType']) ? $values['xmlType'] : null;
|
||||
}
|
||||
|
||||
|
||||
public function getPhpType()
|
||||
{
|
||||
return $this->phpType;
|
||||
}
|
||||
|
||||
|
||||
public function getXmlType()
|
||||
{
|
||||
return $this->xmlType;
|
||||
|
@ -25,35 +25,32 @@ use Zend\Soap\Wsdl;
|
||||
class WsdlDumper implements DumperInterface
|
||||
{
|
||||
private $definition;
|
||||
|
||||
|
||||
public function dumpServiceDefinition(ServiceDefinition $definition, array $options = array())
|
||||
{
|
||||
Assert::thatArgumentNotNull('definition', $definition);
|
||||
|
||||
$options = array_merge(array('endpoint' => ''), $options);
|
||||
|
||||
|
||||
$this->definition = $definition;
|
||||
|
||||
$wsdl = new Wsdl($definition->getName(), $definition->getNamespace());
|
||||
|
||||
$port = $wsdl->addPortType($this->getPortTypeName());
|
||||
$binding = $wsdl->addBinding($this->getBindingName(), 'tns:' . $this->getPortTypeName());
|
||||
|
||||
|
||||
$wsdl->addSoapBinding($binding, 'rpc');
|
||||
$wsdl->addService($this->getServiceName(), $this->getPortName(), 'tns:' . $this->getBindingName(), $options['endpoint']);
|
||||
|
||||
foreach($definition->getMethods() as $method)
|
||||
{
|
||||
foreach($definition->getMethods() as $method) {
|
||||
$requestParts = array();
|
||||
$responseParts = array();
|
||||
|
||||
foreach($method->getArguments() as $argument)
|
||||
{
|
||||
foreach($method->getArguments() as $argument) {
|
||||
$requestParts[$argument->getName()] = $wsdl->getType($argument->getType()->getPhpType());
|
||||
}
|
||||
|
||||
if($method->getReturn() !== null)
|
||||
{
|
||||
if($method->getReturn() !== null) {
|
||||
$responseParts['return'] = $wsdl->getType($method->getReturn()->getPhpType());
|
||||
}
|
||||
|
||||
@ -83,7 +80,7 @@ class WsdlDumper implements DumperInterface
|
||||
$this->definition = null;
|
||||
|
||||
$wsdl->toDomDocument()->formatOutput = true;
|
||||
|
||||
|
||||
return $wsdl->toXml();
|
||||
}
|
||||
|
||||
@ -91,7 +88,7 @@ class WsdlDumper implements DumperInterface
|
||||
{
|
||||
return $this->definition->getName() . 'Port';
|
||||
}
|
||||
|
||||
|
||||
protected function getPortTypeName()
|
||||
{
|
||||
return $this->definition->getName() . 'PortType';
|
||||
@ -121,4 +118,4 @@ class WsdlDumper implements DumperInterface
|
||||
{
|
||||
return $this->definition->getNamespace() . $method->getName();
|
||||
}
|
||||
}
|
||||
}
|
@ -35,9 +35,9 @@ class AnnotationClassLoader implements LoaderInterface
|
||||
private $wsMethodAnnotationClass = 'Bundle\\WebServiceBundle\\ServiceDefinition\\Annotation\\Method';
|
||||
private $wsParamAnnotationClass = 'Bundle\\WebServiceBundle\\ServiceDefinition\\Annotation\\Param';
|
||||
private $wsResultAnnotationClass = 'Bundle\\WebServiceBundle\\ServiceDefinition\\Annotation\\Result';
|
||||
|
||||
|
||||
protected $reader;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@ -60,42 +60,37 @@ class AnnotationClassLoader implements LoaderInterface
|
||||
*/
|
||||
public function load($class, $type = null)
|
||||
{
|
||||
if (!class_exists($class))
|
||||
{
|
||||
if (!class_exists($class)) {
|
||||
throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
|
||||
}
|
||||
|
||||
$class = new \ReflectionClass($class);
|
||||
|
||||
$definition = new ServiceDefinition();
|
||||
|
||||
foreach ($class->getMethods() as $method)
|
||||
{
|
||||
|
||||
foreach ($class->getMethods() as $method) {
|
||||
$wsMethodAnnot = $this->reader->getMethodAnnotation($method, $this->wsMethodAnnotationClass);
|
||||
|
||||
if($wsMethodAnnot !== null)
|
||||
{
|
||||
|
||||
if($wsMethodAnnot !== null) {
|
||||
$wsParamAnnots = $this->reader->getMethodAnnotations($method, $this->wsParamAnnotationClass);
|
||||
$wsResultAnnot = $this->reader->getMethodAnnotation($method, $this->wsResultAnnotationClass);
|
||||
|
||||
|
||||
$serviceMethod = new Method();
|
||||
$serviceMethod->setName($wsMethodAnnot->getName($method->getName()));
|
||||
$serviceMethod->setController($this->getController($method, $wsMethodAnnot));
|
||||
|
||||
foreach($wsParamAnnots as $wsParamAnnot)
|
||||
{
|
||||
|
||||
foreach($wsParamAnnots as $wsParamAnnot) {
|
||||
$serviceArgument = new Argument();
|
||||
$serviceArgument->setName($wsParamAnnot->getName());
|
||||
$serviceArgument->setType(new Type($wsParamAnnot->getPhpType(), $wsParamAnnot->getXmlType()));
|
||||
|
||||
|
||||
$serviceMethod->getArguments()->add($serviceArgument);
|
||||
}
|
||||
|
||||
if($wsResultAnnot !== null)
|
||||
{
|
||||
|
||||
if($wsResultAnnot !== null) {
|
||||
$serviceMethod->setReturn(new Type($wsResultAnnot->getPhpType(), $wsResultAnnot->getXmlType()));
|
||||
}
|
||||
|
||||
|
||||
$definition->getMethods()->add($serviceMethod);
|
||||
}
|
||||
}
|
||||
@ -105,16 +100,13 @@ class AnnotationClassLoader implements LoaderInterface
|
||||
|
||||
private function getController(\ReflectionMethod $method, MethodAnnotation $annotation)
|
||||
{
|
||||
if($annotation->getService() !== null)
|
||||
{
|
||||
if($annotation->getService() !== null) {
|
||||
return $annotation->getService() . ':' . $method->name;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return $method->class . '::' . $method->name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if this class supports the given resource.
|
||||
*
|
||||
@ -145,4 +137,4 @@ class AnnotationClassLoader implements LoaderInterface
|
||||
public function getResolver()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -61,11 +61,11 @@ class AnnotationFileLoader extends FileLoader
|
||||
$path = $this->locator->locate($file);
|
||||
|
||||
$definition = new ServiceDefinition();
|
||||
|
||||
|
||||
if ($class = $this->findClass($path)) {
|
||||
$definition = $this->loader->load($class, $type);
|
||||
}
|
||||
|
||||
|
||||
return $definition;
|
||||
}
|
||||
|
||||
@ -87,7 +87,7 @@ class AnnotationFileLoader extends FileLoader
|
||||
*
|
||||
* @param string $file A PHP file path
|
||||
*
|
||||
* @return string|false Full class name if found, false otherwise
|
||||
* @return string|false Full class name if found, false otherwise
|
||||
*/
|
||||
protected function findClass($file)
|
||||
{
|
||||
|
@ -15,7 +15,7 @@ use Doctrine\Common\Annotations\Parser;
|
||||
|
||||
/**
|
||||
* AnnotationParser allows multiple annotations of the same class to be present.
|
||||
*
|
||||
*
|
||||
* @author Christian Kerl <christian-kerl@web.de>
|
||||
*/
|
||||
class AnnotationParser extends Parser
|
||||
|
@ -22,19 +22,18 @@ class AnnotationReader extends BaseAnnotationReader
|
||||
public function getMethodAnnotation(\ReflectionMethod $method, $type)
|
||||
{
|
||||
$annotation = parent::getMethodAnnotation($method, $type);
|
||||
|
||||
if($annotation !== null && count($annotation) > 1)
|
||||
{
|
||||
|
||||
if($annotation !== null && count($annotation) > 1) {
|
||||
throw new \LogicException(sprintf("There is more than one annotation of type '%s'!", $type));
|
||||
}
|
||||
|
||||
|
||||
return $annotation !== null ? $annotation[0] : null;
|
||||
}
|
||||
|
||||
|
||||
public function getMethodAnnotations(\ReflectionMethod $method, $type = null)
|
||||
{
|
||||
$annotations = parent::getMethodAnnotations($method);
|
||||
|
||||
|
||||
return $type !== null && isset($annotations[$type]) ? $annotations[$type] : $annotations;
|
||||
}
|
||||
}
|
@ -24,27 +24,25 @@ class XmlFileLoader extends FileLoader
|
||||
{
|
||||
return is_string($resource) && 'xml' === pathinfo($resource, PATHINFO_EXTENSION);
|
||||
}
|
||||
|
||||
|
||||
public function load($file, $type = null)
|
||||
{
|
||||
$path = $this->locator->locate($file);
|
||||
|
||||
|
||||
$xml = $this->parseFile($path);
|
||||
|
||||
$definition = new ServiceDefinition();
|
||||
$definition->setName((string) $xml['name']);
|
||||
$definition->setNamespace((string) $xml['namespace']);
|
||||
|
||||
foreach($xml->header as $header)
|
||||
{
|
||||
foreach($xml->header as $header) {
|
||||
$definition->getHeaders()->add($this->parseHeader($header));
|
||||
}
|
||||
|
||||
foreach($xml->method as $method)
|
||||
{
|
||||
foreach($xml->method as $method) {
|
||||
$definition->getMethods()->add($this->parseMethod($method));
|
||||
}
|
||||
|
||||
|
||||
return $definition;
|
||||
}
|
||||
|
||||
@ -69,8 +67,7 @@ class XmlFileLoader extends FileLoader
|
||||
{
|
||||
$method = new Method((string)$node['name'], (string)$node['controller']);
|
||||
|
||||
foreach($node->argument as $argument)
|
||||
{
|
||||
foreach($node->argument as $argument) {
|
||||
$method->getArguments()->add($this->parseArgument($argument));
|
||||
}
|
||||
|
||||
|
@ -1,81 +1,81 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://christiankerl.github.com/WebServiceBundle/servicedefinition/1.0/" xmlns:tns="http://christiankerl.github.com/WebServiceBundle/servicedefinition/1.0/" elementFormDefault="qualified">
|
||||
<element name="webservice" type="tns:WebserviceType" />
|
||||
<complexType name="WebserviceType">
|
||||
<sequence>
|
||||
<element name="header" type="tns:HeaderType" minOccurs="0" maxOccurs="unbounded" />
|
||||
<element name="method" type="tns:MethodType" maxOccurs="unbounded" />
|
||||
</sequence>
|
||||
<attribute name="name" type="string" use="required" />
|
||||
</complexType>
|
||||
|
||||
<complexType name="HeaderType">
|
||||
<complexContent>
|
||||
<extension base="tns:TransferObjectType">
|
||||
<sequence>
|
||||
<element name="exception" type="tns:ExceptionType" minOccurs="0" maxOccurs="unbounded" />
|
||||
</sequence>
|
||||
<attribute name="name" type="ID" use="required" />
|
||||
</extension>
|
||||
</complexContent>
|
||||
</complexType>
|
||||
|
||||
<complexType name="HeaderRefType">
|
||||
<attribute name="name" type="IDREF" />
|
||||
<attribute name="direction">
|
||||
<simpleType>
|
||||
<restriction base="string">
|
||||
<enumeration value="in" />
|
||||
<enumeration value="out" />
|
||||
<enumeration value="inout" />
|
||||
</restriction>
|
||||
</simpleType>
|
||||
</attribute>
|
||||
</complexType>
|
||||
|
||||
<complexType name="MethodType">
|
||||
<sequence>
|
||||
<element name="exception" type="tns:ExceptionType" minOccurs="0" maxOccurs="unbounded" />
|
||||
<element name="header" type="tns:HeaderRefType" minOccurs="0" maxOccurs="unbounded" />
|
||||
|
||||
<element name="argument" type="tns:ArgumentType" minOccurs="0" maxOccurs="unbounded" />
|
||||
<element name="return" type="tns:ReturnType" minOccurs="0" maxOccurs="1" />
|
||||
</sequence>
|
||||
<attribute name="name" type="string" use="required" />
|
||||
<attribute name="controller" type="string" use="required" />
|
||||
</complexType>
|
||||
|
||||
<complexType name="TransferObjectType" abstract="true">
|
||||
<sequence>
|
||||
<element name="type" type="tns:TypeConversionType" />
|
||||
</sequence>
|
||||
</complexType>
|
||||
|
||||
<complexType name="ExceptionType">
|
||||
<complexContent>
|
||||
<extension base="tns:TransferObjectType">
|
||||
<attribute name="name" type="string" use="required" />
|
||||
</extension>
|
||||
</complexContent>
|
||||
</complexType>
|
||||
|
||||
<complexType name="ArgumentType">
|
||||
<complexContent>
|
||||
<extension base="tns:TransferObjectType">
|
||||
<attribute name="name" type="string" use="required" />
|
||||
</extension>
|
||||
</complexContent>
|
||||
</complexType>
|
||||
|
||||
<complexType name="ReturnType">
|
||||
<complexContent>
|
||||
<extension base="tns:TransferObjectType" />
|
||||
</complexContent>
|
||||
</complexType>
|
||||
|
||||
<complexType name="TypeConversionType">
|
||||
<attribute name="php-type" type="string" use="required" />
|
||||
<attribute name="xml-type" type="QName" use="required" />
|
||||
<attribute name="converter" type="string" use="optional" />
|
||||
</complexType>
|
||||
<element name="webservice" type="tns:WebserviceType" />
|
||||
<complexType name="WebserviceType">
|
||||
<sequence>
|
||||
<element name="header" type="tns:HeaderType" minOccurs="0" maxOccurs="unbounded" />
|
||||
<element name="method" type="tns:MethodType" maxOccurs="unbounded" />
|
||||
</sequence>
|
||||
<attribute name="name" type="string" use="required" />
|
||||
</complexType>
|
||||
|
||||
<complexType name="HeaderType">
|
||||
<complexContent>
|
||||
<extension base="tns:TransferObjectType">
|
||||
<sequence>
|
||||
<element name="exception" type="tns:ExceptionType" minOccurs="0" maxOccurs="unbounded" />
|
||||
</sequence>
|
||||
<attribute name="name" type="ID" use="required" />
|
||||
</extension>
|
||||
</complexContent>
|
||||
</complexType>
|
||||
|
||||
<complexType name="HeaderRefType">
|
||||
<attribute name="name" type="IDREF" />
|
||||
<attribute name="direction">
|
||||
<simpleType>
|
||||
<restriction base="string">
|
||||
<enumeration value="in" />
|
||||
<enumeration value="out" />
|
||||
<enumeration value="inout" />
|
||||
</restriction>
|
||||
</simpleType>
|
||||
</attribute>
|
||||
</complexType>
|
||||
|
||||
<complexType name="MethodType">
|
||||
<sequence>
|
||||
<element name="exception" type="tns:ExceptionType" minOccurs="0" maxOccurs="unbounded" />
|
||||
<element name="header" type="tns:HeaderRefType" minOccurs="0" maxOccurs="unbounded" />
|
||||
|
||||
<element name="argument" type="tns:ArgumentType" minOccurs="0" maxOccurs="unbounded" />
|
||||
<element name="return" type="tns:ReturnType" minOccurs="0" maxOccurs="1" />
|
||||
</sequence>
|
||||
<attribute name="name" type="string" use="required" />
|
||||
<attribute name="controller" type="string" use="required" />
|
||||
</complexType>
|
||||
|
||||
<complexType name="TransferObjectType" abstract="true">
|
||||
<sequence>
|
||||
<element name="type" type="tns:TypeConversionType" />
|
||||
</sequence>
|
||||
</complexType>
|
||||
|
||||
<complexType name="ExceptionType">
|
||||
<complexContent>
|
||||
<extension base="tns:TransferObjectType">
|
||||
<attribute name="name" type="string" use="required" />
|
||||
</extension>
|
||||
</complexContent>
|
||||
</complexType>
|
||||
|
||||
<complexType name="ArgumentType">
|
||||
<complexContent>
|
||||
<extension base="tns:TransferObjectType">
|
||||
<attribute name="name" type="string" use="required" />
|
||||
</extension>
|
||||
</complexContent>
|
||||
</complexType>
|
||||
|
||||
<complexType name="ReturnType">
|
||||
<complexContent>
|
||||
<extension base="tns:TransferObjectType" />
|
||||
</complexContent>
|
||||
</complexType>
|
||||
|
||||
<complexType name="TypeConversionType">
|
||||
<attribute name="php-type" type="string" use="required" />
|
||||
<attribute name="xml-type" type="QName" use="required" />
|
||||
<attribute name="converter" type="string" use="optional" />
|
||||
</complexType>
|
||||
</schema>
|
Reference in New Issue
Block a user