[SoapBundle] Moved configuration of ComplexType aliases from config to PHP objects with annotations

Before:
``` yaml
be_simple_soap:
    services_classmap:
        Cutomer: My\Bundle\Entity\Customer
        Cart:    My\Bundle\Entity\Cart

After:
``` php
<?php

namespace My\Bundle\Entity;

use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap;

/**
 * @Soap\Alias("Customer")
 */
class Customer
{
    // ... your PHP code
}

/**
 * @Soap\Alias("Cart")
 */
class Cart
{
    // ... your PHP code
}
This commit is contained in:
Francis Besset
2013-07-23 14:44:32 +02:00
parent 6de878de7d
commit e765ea746e
5 changed files with 71 additions and 42 deletions

View File

@ -22,6 +22,7 @@ use BeSimple\SoapBundle\Util\Collection;
*/
class AnnotationComplexTypeLoader extends AnnotationClassLoader
{
private $aliasClass = 'BeSimple\SoapBundle\ServiceDefinition\Annotation\Alias';
private $complexTypeClass = 'BeSimple\SoapBundle\ServiceDefinition\Annotation\ComplexType';
/**
@ -40,9 +41,14 @@ class AnnotationComplexTypeLoader extends AnnotationClassLoader
throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
}
$class = new \ReflectionClass($class);
$collection = new Collection('getName', 'BeSimple\SoapBundle\ServiceDefinition\ComplexType');
$annotations = array();
$class = new \ReflectionClass($class);
if ($alias = $this->reader->getClassAnnotation($class, $this->aliasClass)) {
$annotations['alias'] = $alias->getValue();
}
$annotations['properties'] = new Collection('getName', 'BeSimple\SoapBundle\ServiceDefinition\ComplexType');
foreach ($class->getProperties() as $property) {
$complexType = $this->reader->getPropertyAnnotation($property, $this->complexTypeClass);
@ -51,10 +57,10 @@ class AnnotationComplexTypeLoader extends AnnotationClassLoader
$propertyComplexType->setValue($complexType->getValue());
$propertyComplexType->setNillable($complexType->isNillable());
$propertyComplexType->setName($property->getName());
$collection->add($propertyComplexType);
$annotations['properties']->add($propertyComplexType);
}
}
return $collection;
return $annotations;
}
}
}