From 62e07ba43c5bb1fc2cfaa63f1e6e8411a21e1012 Mon Sep 17 00:00:00 2001 From: Christian Kerl Date: Sun, 17 Jul 2011 15:03:05 +0200 Subject: [PATCH] added support to retrieve parameter php type form type hint Conflicts: ServiceDefinition/Loader/AnnotationClassLoader.php --- .../Loader/AnnotationClassLoader.php | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/ServiceDefinition/Loader/AnnotationClassLoader.php b/ServiceDefinition/Loader/AnnotationClassLoader.php index bbbada0..fc0517d 100644 --- a/ServiceDefinition/Loader/AnnotationClassLoader.php +++ b/ServiceDefinition/Loader/AnnotationClassLoader.php @@ -66,6 +66,7 @@ class AnnotationClassLoader implements LoaderInterface $class = new \ReflectionClass($class); $definition = new ServiceDefinition(); + foreach ($class->getMethods() as $method) { $serviceArguments = array(); $serviceMethod = @@ -75,7 +76,7 @@ class AnnotationClassLoader implements LoaderInterface if ($annotation instanceof ParamAnnotation) { $serviceArguments[] = new Argument( $annotation->getValue(), - new Type($annotation->getPhpType(), $annotation->getXmlType()) + $this->getArgumentType($method, $annotation) ); } elseif ($annotation instanceof MethodAnnotation) { 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. * @@ -152,4 +177,4 @@ class AnnotationClassLoader implements LoaderInterface public function getResolver() { } -} \ No newline at end of file +}