/** * Loads a ServiceDefinition from annotations from a class. * * @param string $class A class name * @param string $type The resource type * * @return ServiceDefinition A ServiceDefinition instance * * @throws \InvalidArgumentException When route can't be parsed */ public function load($class, $type = null) { 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) { $wsMethodAnnot = $this->reader->getMethodAnnotation($method, $this->wsMethodAnnotationClass); 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) { $serviceArgument = new Argument(); $serviceArgument->setName($wsParamAnnot->getName()); $serviceArgument->setType(new Type($wsParamAnnot->getPhpType(), $wsParamAnnot->getXmlType())); $serviceMethod->getArguments()->add($serviceArgument); } if ($wsResultAnnot !== null) { $serviceMethod->setReturn(new Type($wsResultAnnot->getPhpType(), $wsResultAnnot->getXmlType())); } $definition->getMethods()->add($serviceMethod); } } return $definition; }
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) { $definition->getHeaders()->add($this->parseHeader($header)); } foreach ($xml->method as $method) { $definition->getMethods()->add($this->parseMethod($method)); } return $definition; }
public function processServiceMethodReturnValue($name, $return) { $methodDefinition = $this->definition->getMethods()->get($name); return $this->responseMessageBinder->processMessage($methodDefinition, $return); }