/**
  * @inheritdoc
  */
 public function filter(Service $service)
 {
     $types = array();
     $operations = array();
     foreach ($this->methods as $method) {
         $operation = $service->getOperation($method);
         if (!$operation) {
             continue;
         }
         // Discover types used in params
         foreach ($operation->getParams() as $param => $hint) {
             $arr = $operation->getPhpDocParams($param, $service->getTypes());
             $type = $service->getType($arr['type']);
             if (!empty($type)) {
                 $types[] = $type;
             }
         }
         // Discover types used in returns
         $returns = $operation->getReturns();
         $types[] = $service->getType($returns);
         foreach ($types as $type) {
             $types = array_merge($types, $this->findUsedTypes($service, $type));
         }
         // Remove duplicated using standard equality checks. Default string
         // comparison does not work here.
         $types = array_unique($types, SORT_REGULAR);
         $operations[] = $operation;
     }
     $filteredService = new Service($this->config, $service->getIdentifier(), $types, $service->getDescription());
     // Pull created service with operations
     foreach ($operations as $operation) {
         $filteredService->addOperation($operation);
     }
     return $filteredService;
 }
Ejemplo n.º 2
0
 /**
  * Loads the service class
  */
 protected function loadService()
 {
     $service = $this->wsdl->getService();
     $this->log('Starting to load service ' . $service->getName());
     $this->service = new Service($this->config, $service->getName(), $this->types, $service->getDocumentation());
     foreach ($this->wsdl->getOperations() as $function) {
         $this->log('Loading function ' . $function->getName());
         $this->service->addOperation(new Operation($function->getName(), $function->getParams(), $function->getDocumentation(), $function->getReturns()));
     }
     $this->log('Done loading service ' . $service->getName());
 }
Ejemplo n.º 3
0
 /**
  * Save all the loaded classes to the configured output dir
  *
  * @throws Exception If no service is loaded
  */
 private function savePhp()
 {
     $service = $this->service->getClass();
     if ($service == null) {
         throw new Exception('No service loaded');
     }
     $output = new OutputManager($this->config);
     // Generate all type classes
     $types = array();
     foreach ($this->types as $type) {
         $class = $type->getClass();
         if ($class != null) {
             $types[] = $class;
             if (!$this->config->getOneFile() && !$this->config->getNoIncludes()) {
                 $service->addDependency($class->getIdentifier() . '.php');
             }
         }
     }
     $output->save($service, $types);
 }
 /**
  * Setup and return a service with operations and types.
  *
  * @return Service
  */
 private function givenServiceWithOperations()
 {
     // Response GetBook types
     $responseBookName = new ComplexType($this->config, 'Method_Get_Book_Response_BOOK_BOOK_NAME');
     $responseBookName->addMember('string', 'bookName', false);
     $responseBook = new ComplexType($this->config, 'Method_Get_Book_Response_BOOK');
     $responseBook->addMember('int', 'bookId', false);
     // Base type example
     $responseBook->setBaseType($responseBookName);
     $returnGetBookType = new ComplexType($this->config, 'Get_Book_Type_Response');
     $returnGetBookType->addMember('Method_Get_Book_Response_BOOK', 'book_response', false);
     // Request GetBook types
     $bookType = new Enum($this->config, 'Book_Type_Enumeration', 'string');
     $bookType->addValue('fiction');
     $bookType->addValue('comedy');
     $requestBook = new ComplexType($this->config, 'Method_Get_Book_Request_BOOK');
     $requestBook->addMember('int', 'bookId', false);
     $requestBook->addMember('Book_Type_Enumeration', 'genre', false);
     $requestGetBook = new ComplexType($this->config, 'Get_Book_Type_Request');
     $requestGetBook->addMember('Method_Get_Book_Request_BOOK', 'book_request', false);
     // Operation GetBook
     $getBookOperation = new Operation('GetBook', 'Get_Book_Type_Request $request', 'Get Book', 'Get_Book_Type_Response');
     // Response GetAuthors type
     $responseAuthor = new ComplexType($this->config, 'Get_Authors_Response_Author');
     $responseAuthor->addMember('int', 'authorId', false);
     $responseAuthor->addMember('string', 'authorName', false);
     $returnGetAuthors = new ComplexType($this->config, 'Method_Get_Authors_Response');
     $returnGetAuthors->addMember('Get_Authors_Response_Author[]', 'Get_Authors_Response_Author', false);
     // Request GetAuthors type
     $requestGetAuthor = new ComplexType($this->config, 'Method_Get_Authors_Request');
     $requestGetAuthor->addMember('Method_Get_Book_Request_BOOK', 'book_request', false);
     // Operation GetAuthors
     $getAuthorsOperator = new Operation('GetAuthor', 'Method_Get_Authors_Request $request', 'Get Authors', 'Method_Get_Authors_Response');
     // Service creation
     $types = array($responseBookName, $responseBook, $returnGetBookType, $requestBook, $requestGetBook, $responseAuthor, $returnGetAuthors, $requestGetAuthor, $bookType);
     $service = new Service($this->config, 'Book_Shell', $types, 'Book shells');
     $service->addOperation($getBookOperation);
     $service->addOperation($getAuthorsOperator);
     return $service;
 }