/** * @test */ public function shouldGenerateCorrectXML() { //given $tokenizer = new Tokenizer(); $parameters1 = [Parameter::fromTokens($tokenizer->lex('string $userName'))]; $return1 = Parameter::fromTokens($tokenizer->lex('string $uppercasedUserName')); $parameters2 = [Parameter::fromTokens($tokenizer->lex('int[] $numbers')), Parameter::fromTokens($tokenizer->lex('string $prefix'))]; $return2 = Parameter::fromTokens($tokenizer->lex('string[] $numbersWithPrefix')); $parameters3 = [Parameter::fromTokens($tokenizer->lex('object $user { string $name int $age }'))]; $return3 = Parameter::fromTokens($tokenizer->lex('object $userContext { int $id object $userInfo { string $name int $age } }')); $parameters4 = [Parameter::fromTokens($tokenizer->lex('object[] $companies { string $name int $postcode }'))]; $return4 = Parameter::fromTokens($tokenizer->lex('string[] $companiesNames')); $parameters5 = [Parameter::fromTokens($tokenizer->lex('string[] $errors'))]; $return5 = Parameter::fromTokens($tokenizer->lex('object $result { boolean $result string[] $errors }')); $parameters6 = [Parameter::fromTokens($tokenizer->lex('object $serviceAuth { string $token int $id }'), true), Parameter::fromTokens($tokenizer->lex('string $name')), Parameter::fromTokens($tokenizer->lex('string $surname'))]; $return6 = Parameter::fromTokens($tokenizer->lex('string $nameWithSurname')); $parameters7 = [Parameter::fromTokens($tokenizer->lex('string $userToken'))]; $return8 = Parameter::fromTokens($tokenizer->lex('string $responseForMethodWithoutParameters')); $builder = WSDLBuilder::instance()->setName('RpcLiteralService')->setTargetNamespace('http://foo.bar/rpcliteralservice')->setNs('http://foo.bar/rpcliteralservice/types')->setLocation('http://localhost:7777/wsdl-creator/examples/rpc_literal/service.php')->setStyle(SoapBinding::RPC)->setUse(SoapBinding::LITERAL)->setSoapVersion(BindingType::SOAP_11)->setMethod(new Method('uppercaseUserName', $parameters1, $return1))->setMethod(new Method('appendPrefixToNumbers', $parameters2, $return2))->setMethod(new Method('getUserContext', $parameters3, $return3))->setMethod(new Method('extractCompaniesNames', $parameters4, $return4))->setMethod(new Method('wrapErrors', $parameters5, $return5))->setMethod(new Method('authorizedMethod', $parameters6, $return6))->setMethod(new Method('methodWithoutReturn', $parameters7, null))->setMethod(new Method('methodWithoutParameters', [], $return8)); $XMLProvider = new XMLProvider($builder); $XMLProvider->generate(); //when $xml = $XMLProvider->getXml(); //then $this->assertXmlStringEqualsXmlFile(Path::join(__DIR__, 'xml_file_asserts', 'correct_xml.wsdl'), $xml); }
/** * @return $this */ private function types() { $ns = $this->builder->getNs(); $typesElement = $this->createElement('types'); $schemaElement = $this->createElementWithAttributes('xsd:schema', ['targetNamespace' => $ns, 'xmlns' => $ns]); foreach ($this->builder->getMethods() as $method) { $typesForParameters = $this->XMLStyle->generateTypes($this->DOMDocument, $method->getParameters(), $this->XMLSoapVersion); $typesForReturn = $this->XMLStyle->generateTypes($this->DOMDocument, Arrays::toArray($method->getReturn()), $this->XMLSoapVersion); $types = array_merge($typesForParameters, $typesForReturn); foreach ($types as $type) { $schemaElement->appendChild($type); } } $typesElement->appendChild($schemaElement); $this->definitionsRootNode->appendChild($typesElement); return $this; }
/** * @return void */ private function buildForMethods() { $classMethods = $this->reflectionClass()->getMethods(); $methods = []; foreach ($classMethods as $classMethod) { $webMethodAnnotation = $this->annotationReader->getMethodAnnotation($classMethod, '\\WSDL\\Annotation\\WebMethod'); if ($webMethodAnnotation === null) { continue; } $methodBuilder = MethodBuilder::instance(); /** @var MethodAnnotation[] $methodAnnotations */ $methodAnnotations = $this->annotationReader->getMethodAnnotations($classMethod); foreach ($methodAnnotations as $methodAnnotation) { $methodAnnotation->build($methodBuilder, $classMethod); } $methods[] = $methodBuilder->build(); } $this->builder->setMethods($methods); }
* furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ use WSDL\Annotation\BindingType; use WSDL\Annotation\SoapBinding; use WSDL\Builder\WSDLBuilder; use WSDL\WSDL; require_once '../../vendor/autoload.php'; require_once '../ExampleService.php'; require_once '../MethodsProvider.php'; ini_set("soap.wsdl_cache_enabled", 0); $builder = WSDLBuilder::instance()->setName('RpcLiteralService')->setTargetNamespace('http://foo.bar/rpcliteralservice')->setNs('http://foo.bar/rpcliteralservice/types')->setLocation('http://localhost:7777/wsdl-creator/examples/rpc_literal/service.php')->setStyle(SoapBinding::RPC)->setUse(SoapBinding::LITERAL)->setSoapVersion(BindingType::SOAP_11)->setMethods(MethodsProvider::get()); $wsdl = WSDL::fromBuilder($builder); if (isset($_GET['wsdl'])) { header("Content-Type: text/xml"); echo $wsdl->create(); exit; } $server = new SoapServer('http://localhost:7777/wsdl-creator/examples/rpc_literal/service.php?wsdl', ['uri' => $builder->getTargetNamespace(), 'location' => $builder->getLocation(), 'style' => SOAP_RPC, 'use' => SOAP_LITERAL]); $server->setClass('ExampleService'); $server->handle();
/** * @inheritdoc */ public function build(WSDLBuilder $builder, ReflectionClass $class) { $builder->setSoapVersion($this->value); }
* furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ use WSDL\Annotation\BindingType; use WSDL\Annotation\SoapBinding; use WSDL\Builder\WSDLBuilder; use WSDL\WSDL; require_once '../../vendor/autoload.php'; require_once '../ExampleService.php'; require_once '../MethodsProvider.php'; ini_set("soap.wsdl_cache_enabled", 0); $builder = WSDLBuilder::instance()->setName('DocumentLiteralWrappedService')->setTargetNamespace('http://foo.bar/documentliteralwrappedservice')->setNs('http://foo.bar/documentliteralwrappedservice/types')->setLocation('http://localhost:7777/wsdl-creator/examples/document_literal_wrapped/service.php')->setStyle(SoapBinding::DOCUMENT)->setUse(SoapBinding::LITERAL)->setSoapVersion(BindingType::SOAP_11)->setMethods(MethodsProvider::get()); $wsdl = WSDL::fromBuilder($builder); if (isset($_GET['wsdl'])) { header("Content-Type: text/xml"); echo $wsdl->create(); exit; } $server = new SoapServer('http://localhost:7777/wsdl-creator/examples/document_literal_wrapped/service.php?wsdl', ['uri' => $builder->getTargetNamespace(), 'location' => $builder->getLocation(), 'style' => SOAP_DOCUMENT, 'use' => SOAP_LITERAL]); $server->setClass('ExampleService'); $server->handle();
/** * @inheritdoc */ public function build(WSDLBuilder $builder, ReflectionClass $class) { $builder->setStyle($this->style)->setUse($this->use)->setParameterStyle($this->parameterStyle); }
/** * @inheritdoc */ public function build(WSDLBuilder $builder, ReflectionClass $class) { $name = $this->name ?: $class->getShortName(); $builder->setName($name)->setTargetNamespace($this->targetNamespace)->setNs($this->ns)->setLocation($this->location); }
/** * @test */ public function shouldThrowExceptionWhenParameterStyleIsInValid() { //given $WSDLBuilder = WSDLBuilder::instance(); //when CatchException::when($WSDLBuilder)->setParameterStyle('INVALID'); //then CatchException::assertThat()->hasMessage('Invalid parameter style [INVALID] available parameter styles: [BARE, WRAPPED]'); }