Пример #1
0
 /**
  * Generate a REST client based on an interface
  *
  * @param ClassMetaDataProvider $classMetaDataProvider
  * @param GeneratedClassMetaDataProvider $generatedClassMetaDataProvider
  * @return string
  */
 public function generate(ClassMetaDataProvider $classMetaDataProvider, GeneratedClassMetaDataProvider $generatedClassMetaDataProvider)
 {
     // get interface methods
     $parsedMethods = $classMetaDataProvider->getInterfaceMethods();
     // loop through class annotations
     $class = new ClassModel();
     foreach ($classMetaDataProvider->getClassAnnotations() as $classAnnotation) {
         if ($classAnnotation instanceof Headers) {
             $class->addHeaders($classAnnotation->getHeaders());
         }
     }
     // loop over class methods
     foreach ($classMetaDataProvider->getReflectionMethods() as $index => $classMethod) {
         $parsedMethod = array_shift($parsedMethods);
         $parameters = $classMethod->getParameters();
         $method = new Method();
         $method->setName($classMetaDataProvider->getMethodName($parsedMethod));
         $method->setDeclaration($classMetaDataProvider->getMethodDeclaration($parsedMethod));
         // loop through method annotations
         foreach ($classMetaDataProvider->getMethodAnnotations($classMethod) as $methodAnnotation) {
             if ($methodAnnotation instanceof HttpRequest) {
                 foreach ($methodAnnotation->getParameters() as $parameter) {
                     $this->assertParameter($parameters, $parameter);
                 }
             }
             if ($methodAnnotation instanceof AnnotationToVariableMap) {
                 $this->assertParameter($parameters, $methodAnnotation->getName());
             }
             $handler = $this->annotationHandlerFactory->make($methodAnnotation);
             $handler->handle($method, $methodAnnotation);
         }
         $methodOptions = $method->getOptions();
         $methodParts = $method->getParts();
         Tebru\assert(null !== $method->getType(), new GenerationException('During Generation, the http method annotation was not found.'));
         Tebru\assert(empty($methodOptions['body']) || empty($methodParts), new GenerationException(sprintf('During Generation, both a @Body and @Part annotation were found on method "%s"', $method->getName())));
         $class->addMethod($method);
     }
     // render class as string
     $template = $this->twig->loadTemplate('service.php.twig');
     return $template->render(['uses' => $classMetaDataProvider->getUseStatements(), 'namespace' => $generatedClassMetaDataProvider->getNamespaceFull(), 'className' => $classMetaDataProvider->getInterfaceNameShort(), 'interfaceName' => $classMetaDataProvider->getInterfaceNameFull(), 'methods' => $class->getMethods()]);
 }
Пример #2
0
 /**
  * @param Method $method
  * @param QueryMap $annotation
  * @return null
  */
 public function handle(Method $method, $annotation)
 {
     $method->addQueryMap($annotation->getValue());
 }
Пример #3
0
 /**
  * @param Method $method
  * @param JsonBody $annotation
  * @return null
  */
 public function handle(Method $method, $annotation)
 {
     $method->setJsonBody(true);
 }
Пример #4
0
 /**
  * @param Method $method
  * @param Query $annotation
  * @return null
  */
 public function handle(Method $method, $annotation)
 {
     $method->addQueries([$annotation->getKey() => $annotation->getValue()]);
 }
 /**
  * Will set annotation data to $method
  *
  * @param Method                 $method
  * @param DeserializationContext $annotation
  *
  * @return null
  */
 public function handle(Method $method, $annotation)
 {
     $method->setDeserializationContext(['depth' => $annotation->getDepth(), 'groups' => $annotation->getGroups(), 'serializeNull' => $annotation->getSerializeNull(), 'version' => $annotation->getVersion(), 'attributes' => $annotation->getAttributes()]);
 }
Пример #6
0
 /**
  * @param Method $method
  * @param Headers $annotation
  * @return null
  */
 public function handle(Method $method, $annotation)
 {
     $method->addHeaders($annotation->getHeaders());
 }
Пример #7
0
 /**
  * @param Method $method
  * @param HttpRequest $annotation
  * @return null
  */
 public function handle(Method $method, $annotation)
 {
     $method->setType($annotation->getType());
     $method->setPath($annotation->getPath());
     $method->addQueries($annotation->getQueries());
 }
Пример #8
0
 /**
  * @param Method $method
  * @param Returns $annotation
  * @return null
  */
 public function handle(Method $method, $annotation)
 {
     $method->setReturn($annotation->getReturn());
 }
Пример #9
0
 /**
  * @param Method $method
  * @param Url $annotation
  * @return null
  */
 public function handle(Method $method, $annotation)
 {
     $method->setUrl($annotation->getValue());
 }