Cleaned files
This commit is contained in:
@ -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