added support to retrieve parameter php type form type hint

Conflicts:

	ServiceDefinition/Loader/AnnotationClassLoader.php
This commit is contained in:
Christian Kerl 2011-07-17 15:03:05 +02:00 committed by Francis Besset
parent 0126cd4221
commit 62e07ba43c
1 changed files with 27 additions and 2 deletions

View File

@ -66,6 +66,7 @@ class AnnotationClassLoader implements LoaderInterface
$class = new \ReflectionClass($class); $class = new \ReflectionClass($class);
$definition = new ServiceDefinition(); $definition = new ServiceDefinition();
foreach ($class->getMethods() as $method) { foreach ($class->getMethods() as $method) {
$serviceArguments = array(); $serviceArguments = array();
$serviceMethod = $serviceMethod =
@ -75,7 +76,7 @@ class AnnotationClassLoader implements LoaderInterface
if ($annotation instanceof ParamAnnotation) { if ($annotation instanceof ParamAnnotation) {
$serviceArguments[] = new Argument( $serviceArguments[] = new Argument(
$annotation->getValue(), $annotation->getValue(),
new Type($annotation->getPhpType(), $annotation->getXmlType()) $this->getArgumentType($method, $annotation)
); );
} elseif ($annotation instanceof MethodAnnotation) { } elseif ($annotation instanceof MethodAnnotation) {
if ($serviceMethod) { if ($serviceMethod) {
@ -122,6 +123,30 @@ class AnnotationClassLoader implements LoaderInterface
} }
} }
/**
* @param \ReflectionMethod $method
* @param ParamAnnotation $annotation
*
* @return \Bundle\WebServiceBundle\ServiceDefinition\Type
*/
private function getArgumentType(\ReflectionMethod $method, ParamAnnotation $annotation)
{
$phpType = $annotation->getPhpType();
$xmlType = $annotation->getXmlType();
if (null === $phpType) {
foreach ($method->getParameters() as $param) {
if ($param->name === $annotation->getName()) {
$phpType = $param->getClass()->name;
break;
}
}
}
return new Type($phpType, $xmlType);
}
/** /**
* Returns true if this class supports the given resource. * Returns true if this class supports the given resource.
* *
@ -152,4 +177,4 @@ class AnnotationClassLoader implements LoaderInterface
public function getResolver() public function getResolver()
{ {
} }
} }