/** * 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; }
/** * Test that enum values with similar names are resolved correctly. */ public function testSimilarNames() { $config = new Config(array('inputFile' => '', 'outputDir' => '', 'namespaceName' => $this->namespace)); $enum = new Enum($config, 'Enum', 'string'); // Some of these names contain characters which cannot appear in class constant names. // They will be stripped resulting in name clashes. Test to see that the valid names // have appended numbering avoiding these clashes. $valueNames = array('foo' => 'foo', 'foo!' => 'foo2', 'foo!!' => 'foo3'); foreach (array_keys($valueNames) as $value) { $enum->addValue($value); } $this->generateClass($enum, $this->namespace); foreach (array_values($valueNames) as $name) { $this->assertClassHasConst($name, '\\EnumTest\\Enum'); } }
/** * Loads all type classes */ protected function loadTypes() { $this->log('Loading types'); $types = $this->wsdl->getTypes(); foreach ($types as $typeNode) { $type = null; if ($typeNode->isComplex()) { $type = new ComplexType($this->config, $typeNode->getName()); $this->log('Loading type ' . $type->getPhpIdentifier()); $type->setAbstract($typeNode->isAbstract()); foreach ($typeNode->getParts() as $name => $typeName) { // There are 2 ways a wsdl can indicate that a field accepts the null value - // by setting the "nillable" attribute to "true" or by setting the "minOccurs" attribute to "0". // See http://www.ibm.com/developerworks/webservices/library/ws-tip-null/index.html $nullable = $typeNode->isElementNillable($name) || $typeNode->getElementMinOccurs($name) === 0; $type->addMember($typeName, $name, $nullable); } } elseif ($enumValues = $typeNode->getEnumerations()) { $type = new Enum($this->config, $typeNode->getName(), $typeNode->getRestriction()); array_walk($enumValues, function ($value) use($type) { $type->addValue($value); }); } elseif ($pattern = $typeNode->getPattern()) { $type = new Pattern($this->config, $typeNode->getName(), $typeNode->getRestriction()); $type->setValue($pattern); } if ($type != null) { $already_registered = false; if ($this->config->get('sharedTypes')) { foreach ($this->types as $registered_types) { if ($registered_types->getIdentifier() == $type->getIdentifier()) { $already_registered = true; break; } } } if (!$already_registered) { $this->types[$typeNode->getName()] = $type; } } } // Loop through all types again to setup class inheritance. // We can only do this once all types have been loaded. Otherwise we risk referencing types which have not been // loaded yet. foreach ($types as $type) { if (($baseType = $type->getBase()) && isset($this->types[$baseType]) && $this->types[$baseType] instanceof ComplexType) { $this->types[$type->getName()]->setBaseType($this->types[$baseType]); } } $this->log('Done loading types'); }
/** * Loads all type classes */ private function loadTypes() { $this->log('Loading types'); $types = $this->wsdl->getTypes(); foreach ($types as $typeNode) { if ($typeNode->isArray()) { // skip arrays continue; } $type = null; if ($typeNode->isComplex()) { $type = new ComplexType($this->config, $typeNode->getName()); $this->log('Loading type ' . $type->getPhpIdentifier()); foreach ($typeNode->getParts() as $name => $typeName) { $type->addMember($typeName, $name, $typeNode->isElementNillable($name)); } } elseif ($enumValues = $typeNode->getEnumerations()) { $type = new Enum($this->config, $typeNode->getName(), $typeNode->getRestriction()); array_walk($enumValues, function ($value) use($type) { $type->addValue($value); }); } elseif ($pattern = $typeNode->getPattern()) { $type = new Pattern($this->config, $typeNode->getName(), $typeNode->getRestriction()); $type->setValue($pattern); } if ($type != null) { $already_registered = false; if ($this->config->getSharedTypes()) { foreach ($this->types as $registered_types) { if ($registered_types->getIdentifier() == $type->getIdentifier()) { $already_registered = true; break; } } } if (!$already_registered) { $this->types[$typeNode->getName()] = $type; } } } // Loop through all types again to setup class inheritance. // We can only do this once all types have been loaded. Otherwise we risk referencing types which have not been // loaded yet. foreach ($types as $type) { if (($baseType = $type->getBase()) && isset($this->types[$baseType])) { $this->types[$type->getName()]->setBaseType($this->types[$baseType]); } } $this->log('Done loading types'); }