diff --git a/.gitignore b/.gitignore index d23f2c0..0a52e3e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea /vendor -composer.lock \ No newline at end of file +composer.lock +tmp diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index 0a45e73..0000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,10 +0,0 @@ -tools: - external_code_coverage: - timeout: 1500 #15 min -checks: - php: - code_rating: true - duplication: true -filter: - paths: - - src/* diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a4a127a..0000000 --- a/.travis.yml +++ /dev/null @@ -1,30 +0,0 @@ -language: php -sudo: false -cache: - directories: - - vendor - - $HOME/.composer/cache -php: - - 5.5 - - 5.6 - - 7.0 - -matrix: - include: - - php: 5.5 - env: COMPOSER_FLAGS='--prefer-lowest --prefer-stable' - -before_script: - - echo "xdebug.max_nesting_level=1000" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - - if [[ $TRAVIS_PHP_VERSION = '5.6' ]]; then PHPUNIT_FLAGS="--coverage-clover=coverage.clover"; else PHPUNIT_FLAGS=""; fi - - if [[ $TRAVIS_PHP_VERSION != '5.6' ]]; then phpenv config-rm xdebug.ini; fi - - composer self-update - - composer update $COMPOSER_FLAGS - -script: - - vendor/phpunit/phpunit/phpunit $PHPUNIT_FLAGS - -after_script: - - wget https://scrutinizer-ci.com/ocular.phar - - if [[ $TRAVIS_PHP_VERSION = '5.6' ]] ; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi - diff --git a/LICENSE b/LICENSE deleted file mode 100644 index bfe99ed..0000000 --- a/LICENSE +++ /dev/null @@ -1,19 +0,0 @@ -Copyright (C) 2016 Asmir Mustafic - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is 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. diff --git a/README.md b/README.md deleted file mode 100644 index c542570..0000000 --- a/README.md +++ /dev/null @@ -1,9 +0,0 @@ -goetas-webservices / soap-common -================================ - -[![Build Status](https://travis-ci.org/goetas-webservices/soap-common.svg?branch=master)](https://travis-ci.org/goetas-webservices/soap-common) -[![Code Coverage](https://scrutinizer-ci.com/g/goetas-webservices/soap-common/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/goetas-webservices/soap-common/?branch=master) -[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/goetas-webservices/soap-common/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/goetas-webservices/soap-common/?branch=master) - - -Pure PHP implementation of SOAP 1.1 common diff --git a/composer.json b/composer.json index a04bffb..794e712 100644 --- a/composer.json +++ b/composer.json @@ -6,31 +6,21 @@ "email": "goetas@gmail.com" } ], - "license": "MIT", "require": { - "php": "^5.5|^7.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.8|^5.0", - "symfony/dependency-injection": "^2.3|^3.0", - "goetas-webservices/soap-reader": "^0.3", - "goetas-webservices/wsdl-reader": "^0.3", - "goetas-webservices/xsd2php-runtime": "^0.2", - "goetas-webservices/xsd2php": "^0.2@dev" + "php": "^7.2", + "rybakit/arguments-resolver": "^0.5.0", + "doctrine/instantiator": "^1.0.3", + "goetas-webservices/xsd2php-runtime": "^0.2.11", + "jms/serializer": "^3.0" }, "autoload": { "psr-4": { - "GoetasWebservices\\SoapServices\\SoapCommon\\": "src" - } - }, - "autoload-dev": { - "psr-4": { - "GoetasWebservices\\SoapServices\\SoapCommon\\Tests\\": "tests" + "GoetasWebservices\\SoapServices\\Metadata\\": "src" } }, "extra": { "branch-alias": { - "dev-master": "0.1-dev" + "dev-master": "0.2-dev" } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist deleted file mode 100644 index 2379ff6..0000000 --- a/phpunit.xml.dist +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - ./tests - - - - - - src - - - - - - diff --git a/src/Arguments/ArgumentsReader.php b/src/Arguments/ArgumentsReader.php new file mode 100644 index 0000000..48c4eeb --- /dev/null +++ b/src/Arguments/ArgumentsReader.php @@ -0,0 +1,148 @@ +serializer = $serializer; + } + + /** + * @param array $args + * @param array $message + */ + public function readArguments(array $args, array $message): object + { + $envelope = array_filter($args, static function ($item) use ($message) { + return $item instanceof $message['message_fqcn']; + }); + if ($envelope) { + return reset($envelope); + } + + $instantiator = new Instantiator(); + $envelope = $instantiator->instantiate($message['message_fqcn']); + + if (!count($message['parts'])) { + return $envelope; + } + + $args = $this->handleHeaders($args, $message, $envelope); + if ($args[0] instanceof $message['part_fqcn']) { + $envelope->setBody($args[0]); + + return $envelope; + } + + $body = $instantiator->instantiate($message['part_fqcn']); + $envelope->setBody($body); + + $factory = SerializerUtils::getMetadataFactory($this->serializer); + + $classMetadata = $factory->getMetadataForClass($message['part_fqcn']); + + if (count($message['parts']) > 1) { + if (count($message['parts']) !== count($args)) { + throw new \Exception('Expected to have exactly ' . count($message['parts']) . ' arguments, supplied ' . count($args)); + } + + foreach ($message['parts'] as $paramName => $elementName) { + $propertyMetadata = $classMetadata->propertyMetadata[$paramName]; + $this->setValue($body, array_shift($args), $propertyMetadata); + } + + return $envelope; + } + + $propertyName = key($message['parts']); + $propertyMetadata = $classMetadata->propertyMetadata[$propertyName]; + + if ($args[0] instanceof $propertyMetadata->type['name']) { + $this->setValue($body, reset($args), $propertyMetadata); + + return $envelope; + } + + $instance2 = $instantiator->instantiate($propertyMetadata->type['name']); + $classMetadata2 = $factory->getMetadataForClass($propertyMetadata->type['name']); + $this->setValue($body, $instance2, $propertyMetadata); + + foreach ($classMetadata2->propertyMetadata as $propertyMetadata2) { + if (!count($args)) { + throw new \Exception("Not enough arguments provided. Can't find a parameter to set " . $propertyMetadata2->name); + } + + $value = array_shift($args); + $this->setValue($instance2, $value, $propertyMetadata2); + } + + return $envelope; + } + + /** + * @param array $args + * @param array $message + * + * @return array + */ + private function handleHeaders(array $args, array $message, object $envelope): array + { + $headers = array_filter($args, static function ($item) use ($message) { + return $item instanceof $message['headers_fqcn']; + }); + if ($headers) { + $envelope->setHeader(reset($headers)); + } else { + $headers = array_filter($args, static function ($item) { + return $item instanceof Header; + }); + if (count($headers)) { + $factory = SerializerUtils::getMetadataFactory($this->serializer); + $classMetadata = $factory->getMetadataForClass($message['message_fqcn']); + $propertyMetadata = $classMetadata->propertyMetadata['header']; + + $instantiator = new Instantiator(); + $header = $instantiator->instantiate($propertyMetadata->type['name']); + foreach ($headers as $headerInfo) { + $header->addHeader($headerInfo); + } + + $envelope->setHeader($header); + } + } + + $args = array_filter($args, static function ($item) use ($message) { + return !($item instanceof Header) && !($item instanceof $message['headers_fqcn']); + }); + + return $args; + } + + /** + * @param mixed $value + */ + private function setValue(object $target, $value, PropertyMetadata $propertyMetadata): void + { + $context = DeserializationContext::create(); + $accessor = new DefaultAccessorStrategy(); + + $accessor->setValue($target, $value, $propertyMetadata, $context); + } +} diff --git a/src/Arguments/ArgumentsReaderInterface.php b/src/Arguments/ArgumentsReaderInterface.php new file mode 100644 index 0000000..1b1e99a --- /dev/null +++ b/src/Arguments/ArgumentsReaderInterface.php @@ -0,0 +1,14 @@ + GraphNavigator::DIRECTION_DESERIALIZATION, + 'format' => 'xml', + 'type' => 'GoetasWebservices\SoapServices\Metadata\Arguments\Headers\Handler\RawFaultDetail', + 'method' => 'deserializeFaultDetail', + ], + ]; + } + + public function deserializeFaultDetail(XmlDeserializationVisitor $visitor, \SimpleXMLElement $data, array $type, DeserializationContext $context): \SimpleXMLElement + { + return $data->children(); + } +} diff --git a/src/Arguments/Headers/Handler/HeaderHandler.php b/src/Arguments/Headers/Handler/HeaderHandler.php new file mode 100644 index 0000000..6082687 --- /dev/null +++ b/src/Arguments/Headers/Handler/HeaderHandler.php @@ -0,0 +1,139 @@ + GraphNavigator::DIRECTION_SERIALIZATION, + 'format' => 'xml', + 'type' => HeaderPlaceholder::class, + 'method' => 'serializeHeaderPlaceholder', + ], + [ + 'direction' => GraphNavigator::DIRECTION_DESERIALIZATION, + 'format' => 'xml', + 'type' => HeaderPlaceholder::class, + 'method' => 'deserializeHeaderPlaceholder', + ], + [ + 'direction' => GraphNavigator::DIRECTION_DESERIALIZATION, + 'format' => 'xml', + 'type' => 'GoetasWebservices\SoapServices\SoapEnvelope\Header', + 'method' => 'deserializeHeader', + ], + [ + 'direction' => GraphNavigator::DIRECTION_SERIALIZATION, + 'format' => 'xml', + 'type' => Header::class, + 'method' => 'serializeHeader', + ], + ]; + } + + /** + * @return mixed + */ + public function deserializeHeaderPlaceholder(XmlDeserializationVisitor $visitor, \SimpleXMLElement $data, array $type, DeserializationContext $context) + { + $type = ['name' => $type['params'][0], 'params' => []]; + + return $context->getNavigator()->accept($data, $type, $context); + } + + /** + * @return mixed + */ + public function deserializeHeader(XmlDeserializationVisitor $visitor, \SimpleXMLElement $data, array $type, DeserializationContext $context) + { + $type = ['name' => $type['params'][0], 'params' => []]; + + $return = $context->getNavigator()->accept($data, $type, $context); + + $mustUnderstandAttr = $data->attributes(self::SOAP_12)->mustUnderstand ?: $data->attributes(self::SOAP)->mustUnderstand; + $mustUnderstand = null !== $mustUnderstandAttr && $visitor->visitBoolean($mustUnderstandAttr, [], $context); + $headerBag = $context->getAttribute('headers_bag'); + \assert($headerBag instanceof HeaderBag); + + if ($mustUnderstand) { + $headerBag->addMustUnderstandHeader($return); + } else { + $headerBag->addHeader($return); + } + + return $return; + } + + public function serializeHeader(XmlSerializationVisitor $visitor, Header $header, array $type, SerializationContext $context): void + { + $factory = $context->getMetadataFactory(); + + /** + * @var $classMetadata \JMS\Serializer\Metadata\ClassMetadata + */ + $classMetadata = $factory->getMetadataForClass(get_class($header->getData())); + + $name = false !== ($pos = strpos($classMetadata->xmlRootName, ':')) ? substr($classMetadata->xmlRootName, $pos + 1) : $classMetadata->xmlRootName; + + $metadata = new StaticPropertyMetadata($classMetadata->name, $name, $header->getData()); + $metadata->xmlNamespace = $classMetadata->xmlRootNamespace; + $metadata->serializedName = $name; + + $visitor->visitProperty($metadata, $header->getData(), $context); + + $this->handleOptions($visitor, $header->getOptions()); + } + + private function handleOptions(XmlSerializationVisitor $visitor, array $options): void + { + if (!count($options)) { + return; + } + + /** + * @var $currentNode \DOMNode + */ + $currentNode = $visitor->getCurrentNode(); + foreach ($options as $option => $value) { + if (in_array($option, ['mustUnderstand', 'required', 'role', 'actor'])) { + if (self::SOAP_12 === $currentNode->ownerDocument->documentElement->namespaceURI) { + $envelopeNS = self::SOAP_12; + } else { + $envelopeNS = self::SOAP; + } + + $this->setAttributeOnNode($currentNode->lastChild, $option, $value, $envelopeNS); + } + } + } + + /** + * @param mixed $value + */ + private function setAttributeOnNode(\DOMElement $node, string $name, $value, string $namespace): void + { + if (!($prefix = $node->lookupPrefix($namespace)) && !($prefix = $node->ownerDocument->lookupPrefix($namespace))) { + $prefix = 'ns-' . substr(sha1($namespace), 0, 8); + } + + $node->setAttributeNS($namespace, $prefix . ':' . $name, is_bool($value) || null === $value ? ($value ? 'true' : 'false') : $value); + } +} diff --git a/src/Arguments/Headers/Handler/HeaderPlaceholder.php b/src/Arguments/Headers/Handler/HeaderPlaceholder.php new file mode 100644 index 0000000..c347bb9 --- /dev/null +++ b/src/Arguments/Headers/Handler/HeaderPlaceholder.php @@ -0,0 +1,20 @@ +__headers[] = $header; + } +} diff --git a/src/Arguments/Headers/Header.php b/src/Arguments/Headers/Header.php new file mode 100644 index 0000000..c04913b --- /dev/null +++ b/src/Arguments/Headers/Header.php @@ -0,0 +1,40 @@ +data = $data; + $this->options = $options; + } + + public function getData(): object + { + return $this->data; + } + + public function getOptions(): array + { + return $this->options; + } + + public function mustUnderstand(): Header + { + $this->options['mustUnderstand'] = true; + + return $this; + } +} diff --git a/src/Arguments/Headers/HeaderBag.php b/src/Arguments/Headers/HeaderBag.php new file mode 100644 index 0000000..7f7a393 --- /dev/null +++ b/src/Arguments/Headers/HeaderBag.php @@ -0,0 +1,60 @@ +headers[spl_object_id($header)]); + } + + public function addHeader(object $header): void + { + $this->headers[spl_object_id($header)] = $header; + } + + public function getHeaders(): array + { + return $this->headers; + } + + public function addMustUnderstandHeader(object $header): void + { + $this->mustUnderstandHeaders[spl_object_id($header)] = $header; + $this->headers[spl_object_id($header)] = $header; + } + + public function isMustUnderstandHeader(object $header): bool + { + return $this->hasHeader($header) && isset($this->mustUnderstandHeaders[spl_object_id($header)]); + } + + public function removeMustUnderstandHeader(object $header): void + { + unset($this->mustUnderstandHeaders[spl_object_id($header)]); + } + + /** + * @return object[] + */ + public function getMustUnderstandHeader(): array + { + return $this->mustUnderstandHeaders; + } +} diff --git a/src/Builder/SoapContainerBuilder.php b/src/Builder/SoapContainerBuilder.php deleted file mode 100644 index e47c3f7..0000000 --- a/src/Builder/SoapContainerBuilder.php +++ /dev/null @@ -1,193 +0,0 @@ -extensions = [ - new Wsdl2PhpExtension(), - new Xsd2PhpExtension(), - new SoapCommonExtension() - ]; - } - - public function setConfigFile($configFile) - { - $this->configFile = $configFile; - } - - protected function addExtension(ExtensionInterface $extension) - { - $this->extensions[] = $extension; - } - - protected function addCompilerPass(CompilerPassInterface $pass) - { - $this->compilerPasses[] = $pass; - } - - public function setContainerClassName($fqcn) - { - $fqcn = strtr($fqcn, ['.' => '\\', '/' => '\\',]); - $pos = strrpos($fqcn, '\\'); - $this->className = substr($fqcn, $pos + 1); - $this->classNs = substr($fqcn, 0, $pos); - } - - /** - * @param array $metadata - * @return ContainerBuilder - */ - protected function getContainerBuilder(array $metadata = array()) - { - $container = new ContainerBuilder(); - - foreach ($this->extensions as $extension) { - $container->registerExtension($extension); - } - - foreach ($this->compilerPasses as $pass) { - $container->addCompilerPass($pass); - } - - $locator = new FileLocator('.'); - $loaders = array( - new YamlFileLoader($container, $locator), - new XmlFileLoader($container, $locator) - ); - $delegatingLoader = new DelegatingLoader(new LoaderResolver($loaders)); - $delegatingLoader->load($this->configFile); - - - // set the production soap metadata - $container->setParameter('goetas_webservices.soap_common.metadata', $metadata); - - $container->compile(); - - return $container; - } - - /** - * @param ContainerInterface $debugContainer - * @return array - */ - protected function fetchMetadata(ContainerInterface $debugContainer) - { - $metadataReader = $debugContainer->get('goetas_webservices.soap_common.metadata_loader.dev'); - $wsdlMetadata = $debugContainer->getParameter('goetas_webservices.wsdl2php.config')['metadata']; - $metadata = []; - foreach (array_keys($wsdlMetadata) as $uri) { - $metadata[$uri] = $metadataReader->load($uri); - } - - return $metadata; - } - - public function getDebugContainer() - { - return $this->getContainerBuilder(); - } - - /** - * @return ContainerInterface - */ - public function getProdContainer() - { - $ref = new \ReflectionClass("{$this->classNs}\\{$this->className}"); - return $ref->newInstance(); - } - - /** - * @param $dir - * @param ContainerInterface $debugContainer - */ - public function dumpContainerForProd($dir, ContainerInterface $debugContainer) - { - $metadata = $this->fetchMetadata($debugContainer); - - if (!$metadata) { - throw new \Exception("Empty metadata can not be used for production"); - } - $forProdContainer = $this->getContainerBuilder($metadata); - $this->dump($forProdContainer, $dir); - } - - private function dump(ContainerBuilder $container, $dir) - { - $dumper = new PhpDumper($container); - $options = [ - 'debug' => false, - 'class' => $this->className, - 'namespace' => $this->classNs - ]; - - if (!is_dir($dir)) { - mkdir($dir, 0777, true); - } - - file_put_contents($dir . '/' . $this->className . '.php', $dumper->dump($options)); - } - - /** - * @param ContainerInterface $container - * @param callable $callback - * @return SerializerBuilder - */ - public static function createSerializerBuilderFromContainer(ContainerInterface $container, callable $callback = null) - { - $destinations = $container->getParameter('goetas_webservices.xsd2php.config')['destinations_jms']; - return self::createSerializerBuilder($destinations, $callback); - } - - /** - * @param array $jmsMetadata - * @param callable $callback - * @return SerializerBuilder - */ - public static function createSerializerBuilder(array $jmsMetadata, callable $callback = null) - { - $serializerBuilder = SerializerBuilder::create(); - $serializerBuilder->configureHandlers(function (HandlerRegistryInterface $handler) use ($callback, $serializerBuilder) { - $serializerBuilder->addDefaultHandlers(); - $handler->registerSubscribingHandler(new BaseTypesHandler()); // XMLSchema List handling - $handler->registerSubscribingHandler(new XmlSchemaDateHandler()); // XMLSchema date handling - if ($callback) { - call_user_func($callback, $handler); - } - }); - - - foreach ($jmsMetadata as $php => $dir) { - $serializerBuilder->addMetadataDir($dir, $php); - } - // add SOAP Fault metadata info - $serializerBuilder->addMetadataDir(__DIR__. '/../Resources/metadata/jms', 'GoetasWebservices\SoapServices\SoapCommon\SoapEnvelope'); - return $serializerBuilder; - } -} diff --git a/src/Command/Generate.php b/src/Command/Generate.php deleted file mode 100644 index 4d2dd04..0000000 --- a/src/Command/Generate.php +++ /dev/null @@ -1,71 +0,0 @@ -setName('generate'); - $this->setDefinition([ - new InputArgument('config', InputArgument::REQUIRED, 'Config file location'), - new InputArgument('dest-dir', InputArgument::REQUIRED, 'Config file location'), - new InputOption('dest-class', null, InputOption::VALUE_REQUIRED, 'Config file location'), - ]); - } - - /** - * @return \GoetasWebservices\SoapServices\SoapCommon\Builder\SoapContainerBuilder - */ - protected abstract function getContainerBuilder(); - - /** - * @param InputInterface $input - * @param OutputInterface $output - * @return int - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $containerBuilder = $this->getContainerBuilder(); - - $containerBuilder->setConfigFile($input->getArgument('config')); - - if ($input->getOption('dest-class')) { - $containerBuilder->setContainerClassName($input->getOption('dest-class')); - } - - $this->debugContainer = $containerBuilder->getDebugContainer(); - - $wsdlMetadata = $this->debugContainer->getParameter('wsdl2php.config')['metadata']; - - $schemas = []; - $portTypes = []; - $wsdlReader = $this->debugContainer->get('goetas_webservices.wsdl2php.wsdl_reader'); - - foreach (array_keys($wsdlMetadata) as $src) { - $definitions = $wsdlReader->readFile($src); - $schemas[] = $definitions->getSchema(); - $portTypes = array_merge($portTypes, $definitions->getPortTypes()); - } - - $soapReader = $this->debugContainer->get('goetas_webservices.wsdl2php.soap_reader'); - - foreach (['php', 'jms'] as $type) { - $converter = $this->debugContainer->get('goetas_webservices.xsd2php.converter.' . $type); - $wsdlConverter = $this->debugContainer->get('goetas_webservices.wsdl2php.converter.' . $type); - $items = $wsdlConverter->visitServices($soapReader->getServices()); - $items = array_merge($items, $converter->convert($schemas)); - - $writer = $this->debugContainer->get('goetas_webservices.xsd2php.writer.' . $type); - $writer->write($items); - } - } -} diff --git a/src/DependencyInjection/SoapCommonExtension.php b/src/DependencyInjection/SoapCommonExtension.php deleted file mode 100644 index cf73cef..0000000 --- a/src/DependencyInjection/SoapCommonExtension.php +++ /dev/null @@ -1,21 +0,0 @@ -load('services.xml'); - } - - public function getAlias() - { - return 'goetas_soap_common'; - } -} diff --git a/src/Envelope/Fault.php b/src/Envelope/Fault.php new file mode 100644 index 0000000..55b5d10 --- /dev/null +++ b/src/Envelope/Fault.php @@ -0,0 +1,12 @@ +body; + } + + /** + * Sets a new body + */ + public function setBody(FaultBody $body): self + { + $this->body = $body; + + return $this; + } + + public static function fromException(\Throwable $e, bool $debug = false): self + { + $faultEnvelope = new self(); + $faultBody = new FaultBody(); + $faultEnvelope->setBody($faultBody); + + $fault = new FaultPart(); + if (!$e instanceof FaultException) { + $e = new ServerException($e->getMessage(), $e->getCode(), $e); + } + + if ($e instanceof ClientException) { + $fault->setCode('SOAP:Client'); + } elseif ($e instanceof VersionMismatchException) { + $fault->setCode('SOAP:VersionMismatch'); + } elseif ($e instanceof MustUnderstandException) { + $fault->setCode('SOAP:MustUnderstand'); + } else { + $fault->setCode('SOAP:Server'); + } + + if ($debug) { + $fault->setString(implode("\n", array_merge([$e->getMessage()], explode("\n", (string) $e)))); + } else { + $fault->setString($e->getMessage()); + } + + // @todo implement detail wrapping + $fault->setDetail($e->getDetail()); + + $faultBody->setFault($fault); + + return $faultEnvelope; + } + + public function createException(ResponseInterface $response, RequestInterface $request, ?\Throwable $e = null): Fault11Exception + { + return new Fault11Exception($this->getBody()->getFault(), $response, $request, $e); + } +} diff --git a/src/Envelope/SoapEnvelope/Messages/FaultBody.php b/src/Envelope/SoapEnvelope/Messages/FaultBody.php new file mode 100644 index 0000000..944316f --- /dev/null +++ b/src/Envelope/SoapEnvelope/Messages/FaultBody.php @@ -0,0 +1,36 @@ +fault; + } + + /** + * Sets a new fault + */ + public function setFault(Fault $fault): self + { + $this->fault = $fault; + + return $this; + } +} diff --git a/src/Envelope/SoapEnvelope/Parts/Fault.php b/src/Envelope/SoapEnvelope/Parts/Fault.php new file mode 100644 index 0000000..95c459d --- /dev/null +++ b/src/Envelope/SoapEnvelope/Parts/Fault.php @@ -0,0 +1,83 @@ +actor; + } + + public function setActor(string $actor): void + { + $this->actor = $actor; + } + + public function getCode(): ?string + { + return $this->code; + } + + public function setCode(string $code): void + { + $this->code = $code; + } + + public function getString(): ?string + { + return $this->string; + } + + public function setString(string $string): void + { + $this->string = $string; + } + + public function getDetail(): ?string + { + return $this->detail; + } + + public function setDetail(?string $detail): void + { + $this->detail = $detail; + } + + /** + * @var \SimpleXMLElement + */ + private $rawDetail; + + public function getRawDetail(): ?\SimpleXMLElement + { + return $this->rawDetail; + } + + public function setRawDetail(\SimpleXMLElement $rawDetail): void + { + $this->rawDetail = $rawDetail; + } +} diff --git a/src/Envelope/SoapEnvelope12/Messages/Fault.php b/src/Envelope/SoapEnvelope12/Messages/Fault.php new file mode 100644 index 0000000..d8fe83b --- /dev/null +++ b/src/Envelope/SoapEnvelope12/Messages/Fault.php @@ -0,0 +1,99 @@ +body; + } + + /** + * Sets a new body + */ + public function setBody(FaultBody $body): self + { + $this->body = $body; + + return $this; + } + + public static function fromException(\Throwable $e, bool $debug = false): self + { + $faultEnvelope = new self(); + $faultBody = new FaultBody(); + $faultEnvelope->setBody($faultBody); + + $fault = new FaultPart(); + if (!$e instanceof FaultException) { + $e = new ServerException($e->getMessage(), $e->getCode(), $e); + } + + $faultCode = new FaultCode(); + + if ($e instanceof VersionMismatchException) { + $faultCode->setValue('SOAP:VersionMismatch'); + } elseif ($e instanceof MustUnderstandException) { + $faultCode->setValue('SOAP:MustUnderstand'); + } elseif ($e instanceof ClientException) { + $faultCode->setValue('SOAP:Sender'); + } else { + $faultCode->setValue('SOAP:Receiver'); + } + + if (0 !== $e->getCode()) { + $subFaultCode = new FaultCode(); + $subFaultCode->setValue((string) $e->getCode()); + + $faultCode->setSubcode($subFaultCode); + } + + $fault->setCode($faultCode); + if ($debug) { + $fault->setReason(array_merge([$e->getMessage()], explode("\n", (string) $e))); + } else { + $fault->setReason(explode("\n", $e->getMessage())); + } + + // @todo implement detail wrapping + $fault->setDetail($e->getDetail()); + + $faultBody->setFault($fault); + + return $faultEnvelope; + } + + /** + * @param \Exception $e + */ + public function createException(ResponseInterface $response, RequestInterface $request, ?\Throwable $e = null): FaultExceptionMeta + { + return new Fault12Exception($this->getBody()->getFault(), $response, $request, $e); + } +} diff --git a/src/Envelope/SoapEnvelope12/Messages/FaultBody.php b/src/Envelope/SoapEnvelope12/Messages/FaultBody.php new file mode 100644 index 0000000..9c5d6b7 --- /dev/null +++ b/src/Envelope/SoapEnvelope12/Messages/FaultBody.php @@ -0,0 +1,36 @@ +fault; + } + + /** + * Sets a new fault + */ + public function setFault(Fault $fault): self + { + $this->fault = $fault; + + return $this; + } +} diff --git a/src/Envelope/SoapEnvelope12/Parts/Fault.php b/src/Envelope/SoapEnvelope12/Parts/Fault.php new file mode 100644 index 0000000..b2c23d8 --- /dev/null +++ b/src/Envelope/SoapEnvelope12/Parts/Fault.php @@ -0,0 +1,105 @@ +detail; + } + + public function setDetail(?object $detail): void + { + $this->detail = $detail; + } + + public function getRole(): ?string + { + return $this->role; + } + + public function setRole(string $role): void + { + $this->role = $role; + } + + public function getNode(): ?string + { + return $this->node; + } + + public function setNode(string $node): void + { + $this->node = $node; + } + + public function getCode(): ?FaultCode + { + return $this->code; + } + + public function setCode(FaultCode $code): void + { + $this->code = $code; + } + + /** + * @return string[] + */ + public function getReason(): array + { + return $this->reason; + } + + /** + * @param string[] $reason + */ + public function setReason(array $reason): void + { + $this->reason = $reason; + } + + /** + * @var \SimpleXMLElement + */ + private $rawDetail; + + public function getRawDetail(): ?\SimpleXMLElement + { + return $this->rawDetail; + } + + public function setRawDetail(\SimpleXMLElement $rawDetail): void + { + $this->rawDetail = $rawDetail; + } +} diff --git a/src/Envelope/SoapEnvelope12/Parts/FaultCode.php b/src/Envelope/SoapEnvelope12/Parts/FaultCode.php new file mode 100644 index 0000000..94f73f2 --- /dev/null +++ b/src/Envelope/SoapEnvelope12/Parts/FaultCode.php @@ -0,0 +1,43 @@ +value; + } + + public function setValue(string $value): void + { + $this->value = $value; + } + + public function getSubcode(): ?FaultCode + { + return $this->subcode; + } + + public function setSubcode(FaultCode $subcode): void + { + $this->subcode = $subcode; + } + + public function __toString() + { + return $this->value . ($this->subcode ? ':' . $this->subcode : ''); + } +} diff --git a/src/Exception/MetadataException.php b/src/Exception/MetadataException.php index 680c621..6111ae4 100644 --- a/src/Exception/MetadataException.php +++ b/src/Exception/MetadataException.php @@ -1,7 +1,9 @@ '\\SoapEnvelope\\Headers', - 'parts' => '\\SoapEnvelope\\Parts', - 'messages' => '\\SoapEnvelope\\Messages', + /** + * @var string[][] + */ + protected $baseNs = [ + '1.1' => [ + 'headers' => '\\SoapEnvelope\\Headers', + 'parts' => '\\SoapParts', + 'messages' => '\\SoapEnvelope\\Messages', + ], + '1.2' => [ + 'headers' => '\\SoapEnvelope12\\Headers', + 'parts' => '\\SoapParts', + 'messages' => '\\SoapEnvelope12\\Messages', + ], ]; /** * @var NamingStrategy @@ -30,7 +48,6 @@ class MetadataGenerator implements MetadataGeneratorInterface private $unwrap = false; /** - * @param NamingStrategy $namingStrategy * @param array $namespaces */ public function __construct(NamingStrategy $namingStrategy, array $namespaces) @@ -39,103 +56,91 @@ public function __construct(NamingStrategy $namingStrategy, array $namespaces) $this->namingStrategy = $namingStrategy; } - public function addAlternativeEndpoint($service, $port, $endPoint) + public function addAlternativeEndpoint(string $service, string $port, string $endPoint): void { - $this->alternativeEndpoints[$service][$port] = $endPoint; - } + if (0 === strpos($endPoint, 'env(') && ')' === substr($endPoint, -1) && 'env()' !== $endPoint) { + $endPoint = '%' . $endPoint . '%'; + } - public function setUnwrap($mode = true) - { - $this->unwrap = (bool)$mode; + $this->alternativeEndpoints[$service][$port] = $endPoint; } - public function setBaseNs($baseNs = array()) + public function setUnwrap(bool $mode = true): void { - foreach ($baseNs as $k => $ns) { - if (isset($this->baseNs[$k])) { - $this->baseNs[$k] = $ns; - } - } + $this->unwrap = $mode; } /** * @param Service[] $soapServices + * * @return array */ - public function generate(array $soapServices) + public function generate(array $soapServices): array { $services = []; foreach ($soapServices as $soapService) { $port = $soapService->getPort(); - $endpoint = isset($this->alternativeEndpoints[$port->getService()->getName()][$port->getName()]) ? $this->alternativeEndpoints[$port->getService()->getName()][$port->getName()] : $soapService->getAddress(); + $endpoint = $this->alternativeEndpoints[$port->getService()->getName()][$port->getName()] ?? $soapService->getAddress(); $services[$port->getService()->getName()][$port->getName()] = [ 'operations' => $this->generateService($soapService), 'unwrap' => $this->unwrap, - 'endpoint' => $endpoint + 'endpoint' => $endpoint, + 'version' => $soapService->getVersion(), ]; - } + return $services; } - protected function generateService(Service $service) + protected function generateService(Service $service): array { $operations = []; foreach ($service->getOperations() as $operation) { - $operations[$operation->getOperation()->getName()] = $this->generateOperation($operation); + $operations[$operation->getOperation()->getName()] = $this->generateOperation($operation, $service); } + return $operations; } - protected function generateOperation(Operation $soapOperation) + protected function generateOperation(Operation $soapOperation, Service $service): array { - - $operation = [ + return [ 'action' => $soapOperation->getAction(), 'style' => $soapOperation->getStyle(), + 'version' => $service->getVersion(), 'name' => $soapOperation->getOperation()->getName(), 'method' => Inflector::camelize($soapOperation->getOperation()->getName()), - 'input' => $this->generateInOut($soapOperation, $soapOperation->getInput(), $soapOperation->getOperation()->getPortTypeOperation()->getInput(), 'Input'), - 'output' => $this->generateInOut($soapOperation, $soapOperation->getOutput(), $soapOperation->getOperation()->getPortTypeOperation()->getOutput(), 'Output'), - 'fault' => [] + 'input' => $this->generateInOut($soapOperation, $soapOperation->getInput(), $soapOperation->getOperation()->getPortTypeOperation()->getInput(), 'Input', $service), + 'output' => $this->generateInOut($soapOperation, $soapOperation->getOutput(), $soapOperation->getOperation()->getPortTypeOperation()->getOutput(), 'Output', $service), + 'fault' => [], ]; - - /** - * @var $fault \GoetasWebservices\XML\SOAPReader\Soap\Fault - */ - - foreach ($soapOperation->getFaults() as $fault) { - //$operation['fault'][$fault->getName()] = $fault->get; - // @todo do faults metadata - } - - return $operation; } - protected function generateInOut(Operation $operation, OperationMessage $operationMessage, Param $param, $direction) + protected function generateInOut(Operation $operation, OperationMessage $operationMessage, Param $param, string $direction, Service $service): array { $xmlNs = $operation->getOperation()->getDefinition()->getTargetNamespace(); if (!isset($this->namespaces[$xmlNs])) { - throw new \Exception("Can not find a PHP namespace to be associated with '$xmlNs' XML namespace"); + throw new \Exception(sprintf("Can not find a PHP namespace to be associated with '%s' XML namespace", $xmlNs)); } + $ns = $this->namespaces[$xmlNs]; $operation = [ 'message_fqcn' => $ns - . $this->baseNs['messages'] . '\\' + . $this->baseNs[$service->getVersion()]['messages'] . '\\' . Inflector::classify($operationMessage->getMessage()->getOperation()->getName()) . $direction, 'headers_fqcn' => $ns - . $this->baseNs['headers'] . '\\' + . $this->baseNs[$service->getVersion()]['headers'] . '\\' . Inflector::classify($operationMessage->getMessage()->getOperation()->getName()) . $direction, 'part_fqcn' => $ns - . $this->baseNs['parts'] . '\\' + . $this->baseNs[$service->getVersion()]['parts'] . '\\' . Inflector::classify($operationMessage->getMessage()->getOperation()->getName()) . $direction, - 'parts' => $this->getParts($param->getMessage()->getParts()) + 'parts' => $this->getParts($param->getMessage()->getParts()), ]; return $operation; @@ -143,20 +148,26 @@ protected function generateInOut(Operation $operation, OperationMessage $operati /** * @param Part[] $messageParts + * * @return array */ - private function getParts(array $messageParts) + private function getParts(array $messageParts): array { $parts = []; - foreach ($messageParts as $partName => $part) { - $partName = $this->namingStrategy->getPropertyName($part); + foreach ($messageParts as $part) { + if ($part->getElement()) { + $partName = $this->namingStrategy->getPropertyName($part->getElement()); + } else { + $partName = $this->namingStrategy->getPropertyName($part); + } + if ($part->getType()) { - $parts [$partName] = $this->namingStrategy->getTypeName($part->getType()); + $parts[$partName] = $this->namingStrategy->getTypeName($part->getType()); } else { - $parts [$partName] = $this->namingStrategy->getItemName($part->getElement()); + $parts[$partName] = $this->namingStrategy->getItemName($part->getElement()); } } + return $parts; } } - diff --git a/src/MetadataGenerator/MetadataGeneratorInterface.php b/src/Generator/MetadataGeneratorInterface.php similarity index 53% rename from src/MetadataGenerator/MetadataGeneratorInterface.php rename to src/Generator/MetadataGeneratorInterface.php index 7cfb4c2..0b64134 100644 --- a/src/MetadataGenerator/MetadataGeneratorInterface.php +++ b/src/Generator/MetadataGeneratorInterface.php @@ -1,5 +1,8 @@ metadata = $metadata; } - public function addMetadata($wsdl, array $metadata) + public function addMetadata(string $wsdl, array $metadata): void { $this->metadata[$wsdl] = $metadata; } - public function load($wsdl) + public function load(string $wsdl): array { if (!isset($this->metadata[$wsdl])) { - throw new MetadataException(sprintf("Can not load metadata information for %s", $wsdl)); + throw new MetadataException(sprintf('Can not load metadata information for %s', $wsdl)); } + return $this->metadata[$wsdl]; } } diff --git a/src/MetadataLoader/DevMetadataLoader.php b/src/Loader/DevMetadataLoader.php similarity index 73% rename from src/MetadataLoader/DevMetadataLoader.php rename to src/Loader/DevMetadataLoader.php index 7984b79..d6f9f51 100644 --- a/src/MetadataLoader/DevMetadataLoader.php +++ b/src/Loader/DevMetadataLoader.php @@ -1,8 +1,11 @@ soapReader = $soapReader; } - public function load($wsdl) + public function load(string $wsdl): array { if (!isset($this->metadataCache[$wsdl])) { $this->wsdlReader->readFile($wsdl); try { $this->metadataCache[$wsdl] = $this->metadataGenerator->generate($this->soapReader->getServices()); - } catch (\Exception $e) { - throw new MetadataException(sprintf("Can not generate metadata information for %s", $wsdl), 0, $e); + } catch (\Throwable $e) { + throw new MetadataException(sprintf('Can not generate metadata information for %s', $wsdl), 0, $e); } } diff --git a/src/Loader/MetadataLoaderInterface.php b/src/Loader/MetadataLoaderInterface.php new file mode 100644 index 0000000..fe57e76 --- /dev/null +++ b/src/Loader/MetadataLoaderInterface.php @@ -0,0 +1,10 @@ + - - - - - - - - - - - - - - - - - %goetas_webservices.soap_common.metadata% - - - - - - - - diff --git a/src/Resources/metadata/jms-envelope/Arguments.Headers.Handler.HeaderPlaceholder.yml b/src/Resources/metadata/jms-envelope/Arguments.Headers.Handler.HeaderPlaceholder.yml new file mode 100644 index 0000000..fa78d4f --- /dev/null +++ b/src/Resources/metadata/jms-envelope/Arguments.Headers.Handler.HeaderPlaceholder.yml @@ -0,0 +1,5 @@ +GoetasWebservices\SoapServices\Metadata\Arguments\Headers\Handler\HeaderPlaceholder: + properties: + __headers: + inline: true + type: array diff --git a/src/Resources/metadata/jms-envelope/Envelope.Fault.yml b/src/Resources/metadata/jms-envelope/Envelope.Fault.yml new file mode 100644 index 0000000..b6ed72a --- /dev/null +++ b/src/Resources/metadata/jms-envelope/Envelope.Fault.yml @@ -0,0 +1,2 @@ +GoetasWebservices\SoapServices\Metadata\Envelope\Fault: + properties: [] diff --git a/src/Resources/metadata/jms/Messages.Fault.yml b/src/Resources/metadata/jms/Messages.Fault.yml index 530c5a8..0154d19 100644 --- a/src/Resources/metadata/jms/Messages.Fault.yml +++ b/src/Resources/metadata/jms/Messages.Fault.yml @@ -1,16 +1,16 @@ -GoetasWebservices\SoapServices\SoapCommon\SoapEnvelope\Messages\Fault: +GoetasWebservices\SoapServices\Metadata\Envelope\SoapEnvelope\Messages\Fault: xml_root_name: 'SOAP:Envelope' xml_root_namespace: 'http://schemas.xmlsoap.org/soap/envelope/' xml_namespaces: SOAP: 'http://schemas.xmlsoap.org/soap/envelope/' properties: - fault: + body: expose: true access_type: public_method - type: GoetasWebservices\SoapServices\SoapCommon\SoapEnvelope\Parts\Fault - serialized_name: Fault + type: GoetasWebservices\SoapServices\Metadata\Envelope\SoapEnvelope\Messages\FaultBody + serialized_name: Body xml_element: namespace: 'http://schemas.xmlsoap.org/soap/envelope/' accessor: - getter: getFault - setter: setFault + getter: getBody + setter: setBody diff --git a/src/Resources/metadata/jms/Messages.FaultBody.yml b/src/Resources/metadata/jms/Messages.FaultBody.yml new file mode 100644 index 0000000..c30b117 --- /dev/null +++ b/src/Resources/metadata/jms/Messages.FaultBody.yml @@ -0,0 +1,16 @@ +GoetasWebservices\SoapServices\Metadata\Envelope\SoapEnvelope\Messages\FaultBody: + xml_root_name: 'SOAP:Body' + xml_root_namespace: 'http://schemas.xmlsoap.org/soap/envelope/' + xml_namespaces: + SOAP: 'http://schemas.xmlsoap.org/soap/envelope/' + properties: + fault: + expose: true + access_type: public_method + type: GoetasWebservices\SoapServices\Metadata\Envelope\SoapEnvelope\Parts\Fault + serialized_name: Fault + xml_element: + namespace: 'http://schemas.xmlsoap.org/soap/envelope/' + accessor: + getter: getFault + setter: setFault diff --git a/src/Resources/metadata/jms/Parts.Fault.yml b/src/Resources/metadata/jms/Parts.Fault.yml index ca27e45..14617b0 100644 --- a/src/Resources/metadata/jms/Parts.Fault.yml +++ b/src/Resources/metadata/jms/Parts.Fault.yml @@ -1,21 +1,43 @@ -GoetasWebservices\SoapServices\SoapCommon\SoapEnvelope\Parts\Fault: - xml_root_namespace: 'http://www.example.org/test/' - read_only: true +GoetasWebservices\SoapServices\Metadata\Envelope\SoapEnvelope\Parts\Fault: + xml_root_namespace: 'http://schemas.xmlsoap.org/soap/envelope/' exclusion_policy: all - virtual_properties: - getCode: + properties: + code: expose: true + access_type: public_method + accessor: + getter: getCode + setter: setCode serialized_name: faultcode type: string - getDescription: + string: expose: true serialized_name: faultstring type: string - properties: + accessor: + getter: getString + setter: setString actor: expose: true - access_type: public_method - accessor: - getter: getActor serialized_name: faultactor type: string + accessor: + getter: getActor + setter: setActor + detail: + expose: true + read_only: true + access_type: public_method + accessor: + getter: getDetail + setter: setDetail + serialized_name: detail + + rawDetail: + expose: true + access_type: public_method + serialized_name: detail + accessor: + getter: getRawDetail + setter: setRawDetail + type: GoetasWebservices\SoapServices\Metadata\Arguments\Headers\Handler\RawFaultDetail diff --git a/src/Resources/metadata/jms12/Messages.Fault.yml b/src/Resources/metadata/jms12/Messages.Fault.yml new file mode 100644 index 0000000..ceec604 --- /dev/null +++ b/src/Resources/metadata/jms12/Messages.Fault.yml @@ -0,0 +1,16 @@ +GoetasWebservices\SoapServices\Metadata\Envelope\SoapEnvelope12\Messages\Fault: + xml_root_name: 'SOAP:Envelope' + xml_root_namespace: 'http://www.w3.org/2003/05/soap-envelope' + xml_namespaces: + SOAP: 'http://www.w3.org/2003/05/soap-envelope' + properties: + body: + expose: true + access_type: public_method + type: GoetasWebservices\SoapServices\Metadata\Envelope\SoapEnvelope12\Messages\FaultBody + serialized_name: Body + xml_element: + namespace: 'http://www.w3.org/2003/05/soap-envelope' + accessor: + getter: getBody + setter: setBody diff --git a/src/Resources/metadata/jms12/Messages.FaultBody.yml b/src/Resources/metadata/jms12/Messages.FaultBody.yml new file mode 100644 index 0000000..c111e39 --- /dev/null +++ b/src/Resources/metadata/jms12/Messages.FaultBody.yml @@ -0,0 +1,16 @@ +GoetasWebservices\SoapServices\Metadata\Envelope\SoapEnvelope12\Messages\FaultBody: + xml_root_name: 'SOAP:Envelope' + xml_root_namespace: 'http://www.w3.org/2003/05/soap-envelope' + xml_namespaces: + SOAP: 'http://www.w3.org/2003/05/soap-envelope' + properties: + fault: + expose: true + access_type: public_method + type: GoetasWebservices\SoapServices\Metadata\Envelope\SoapEnvelope12\Parts\Fault + serialized_name: Fault + xml_element: + namespace: 'http://www.w3.org/2003/05/soap-envelope' + accessor: + getter: getFault + setter: setFault diff --git a/src/Resources/metadata/jms12/Parts.Fault.yml b/src/Resources/metadata/jms12/Parts.Fault.yml new file mode 100644 index 0000000..7e59fb3 --- /dev/null +++ b/src/Resources/metadata/jms12/Parts.Fault.yml @@ -0,0 +1,64 @@ +GoetasWebservices\SoapServices\Metadata\Envelope\SoapEnvelope12\Parts\Fault: + xml_root_namespace: 'http://www.w3.org/2003/05/soap-envelope' + properties: + code: + expose: true + access_type: public_method + accessor: + getter: getCode + setter: setCode + serialized_name: Code + xml_element: + namespace: 'http://www.w3.org/2003/05/soap-envelope' + type: GoetasWebservices\SoapServices\Metadata\Envelope\SoapEnvelope12\Parts\FaultCode + reason: + expose: true + serialized_name: Reason + xml_element: + namespace: 'http://www.w3.org/2003/05/soap-envelope' + type: array + xml_list: + inline: false + entry_name: Text + namespace: 'http://www.w3.org/2003/05/soap-envelope' + detail: + expose: true + read_only: true + access_type: public_method + accessor: + getter: getDetail + setter: setDetail + serialized_name: Detail + xml_element: + namespace: 'http://www.w3.org/2003/05/soap-envelope' + role: + expose: true + access_type: public_method + accessor: + getter: getRole + setter: setRole + serialized_name: Role + xml_element: + namespace: 'http://www.w3.org/2003/05/soap-envelope' + type: string + node: + expose: true + access_type: public_method + accessor: + getter: getNode + setter: setNode + serialized_name: Node + xml_element: + namespace: 'http://www.w3.org/2003/05/soap-envelope' + type: string + + rawDetail: + expose: true + access_type: public_method + serialized_name: Detail + xml_element: + namespace: 'http://www.w3.org/2003/05/soap-envelope' + accessor: + getter: getRawDetail + setter: setRawDetail + type: GoetasWebservices\SoapServices\Metadata\Arguments\Headers\Handler\RawFaultDetail diff --git a/src/Resources/metadata/jms12/Parts.FaultCode.yml b/src/Resources/metadata/jms12/Parts.FaultCode.yml new file mode 100644 index 0000000..89b210f --- /dev/null +++ b/src/Resources/metadata/jms12/Parts.FaultCode.yml @@ -0,0 +1,22 @@ +GoetasWebservices\SoapServices\Metadata\Envelope\SoapEnvelope12\Parts\FaultCode: + xml_root_namespace: 'http://www.w3.org/2003/05/soap-envelope' + properties: + value: + expose: true + access_type: public_method + accessor: + getter: getValue + setter: setValue + serialized_name: Value + xml_element: + namespace: 'http://www.w3.org/2003/05/soap-envelope' + type: string + subcode: + expose: true + serialized_name: Subcode + accessor: + getter: getSubcode + setter: setSubcode + xml_element: + namespace: 'http://www.w3.org/2003/05/soap-envelope' + type: GoetasWebservices\SoapServices\Metadata\Envelope\SoapEnvelope12\Parts\FaultCode diff --git a/src/SerializerUtils.php b/src/SerializerUtils.php new file mode 100644 index 0000000..080fb91 --- /dev/null +++ b/src/SerializerUtils.php @@ -0,0 +1,22 @@ +setAccessible(true); + + return $reflectionProperty->getValue($serializer); + } +} diff --git a/src/SoapEnvelope/Messages/Fault.php b/src/SoapEnvelope/Messages/Fault.php deleted file mode 100644 index 1b5878d..0000000 --- a/src/SoapEnvelope/Messages/Fault.php +++ /dev/null @@ -1,40 +0,0 @@ -fault; - } - - /** - * Sets a new fault - * - * @param \GoetasWebservices\SoapServices\SoapCommon\SoapEnvelope\Parts\Fault $fault - * @return self - */ - public function setFault(\GoetasWebservices\SoapServices\SoapCommon\SoapEnvelope\Parts\Fault $fault) - { - $this->fault = $fault; - return $this; - } - - -} - diff --git a/src/SoapEnvelope/Parts/Fault.php b/src/SoapEnvelope/Parts/Fault.php deleted file mode 100644 index 4d44b71..0000000 --- a/src/SoapEnvelope/Parts/Fault.php +++ /dev/null @@ -1,59 +0,0 @@ -exception = $exception; - } - - /** - * @return string - */ - public function getActor() - { - return $this->actor; - } - - /** - * @return string - */ - public function getCode() - { - $ref = new \ReflectionObject($this->exception); - return 'SOAP-ENV:' . str_replace('Exception', '', $ref->getShortName()); //$this->exception->getCode(); - } - - /** - * @return string - */ - public function getDescription() - { - return $this->exception->getMessage(); - } - - /** - * @param string $actor - * @return Fault - */ - public function setActor($actor) - { - $this->actor = $actor; - } - -} - diff --git a/tests/Fixtures/test.php b/tests/Fixtures/test.php deleted file mode 100644 index 5bde355..0000000 --- a/tests/Fixtures/test.php +++ /dev/null @@ -1,316 +0,0 @@ - [ - 'testSOAP' => [ - 'operations' => [ - 'getSimple' => [ - 'action' => 'http://www.example.org/test/getSimple', - 'style' => 'rpc', - 'name' => 'getSimple', - 'method' => 'getSimple', - 'input' => [ - 'message_fqcn' => 'TestNs\\SoapEnvelope\\Messages\\GetSimpleInput', - 'headers_fqcn' => 'TestNs\\SoapEnvelope\\Headers\\GetSimpleInput', - 'part_fqcn' => 'TestNs\\SoapEnvelope\\Parts\\GetSimpleInput', - 'parts' => [ - 'parameters' => 'GetSimple', - ], - ], - 'output' => [ - 'message_fqcn' => 'TestNs\\SoapEnvelope\\Messages\\GetSimpleOutput', - 'headers_fqcn' => 'TestNs\\SoapEnvelope\\Headers\\GetSimpleOutput', - 'part_fqcn' => 'TestNs\\SoapEnvelope\\Parts\\GetSimpleOutput', - 'parts' => [ - 'parameters' => 'GetSimpleResponse', - ], - ], - 'fault' => [ - ], - ], - 'getMultiParam' => [ - 'action' => 'http://www.example.org/test/getMultiParam', - 'style' => 'rpc', - 'name' => 'getMultiParam', - 'method' => 'getMultiParam', - 'input' => [ - 'message_fqcn' => 'TestNs\\SoapEnvelope\\Messages\\GetMultiParamInput', - 'headers_fqcn' => 'TestNs\\SoapEnvelope\\Headers\\GetMultiParamInput', - 'part_fqcn' => 'TestNs\\SoapEnvelope\\Parts\\GetMultiParamInput', - 'parts' => [ - 'parameters' => 'GetMultiParam', - 'otherParam' => 'StringType', - ], - ], - 'output' => [ - 'message_fqcn' => 'TestNs\\SoapEnvelope\\Messages\\GetMultiParamOutput', - 'headers_fqcn' => 'TestNs\\SoapEnvelope\\Headers\\GetMultiParamOutput', - 'part_fqcn' => 'TestNs\\SoapEnvelope\\Parts\\GetMultiParamOutput', - 'parts' => [ - 'parameters' => 'GetMultiParamResponse', - ], - ], - 'fault' => [ - ], - ], - 'getReturnMultiParam' => [ - 'action' => 'http://www.example.org/test/getReturnMultiParam', - 'style' => 'rpc', - 'name' => 'getReturnMultiParam', - 'method' => 'getReturnMultiParam', - 'input' => [ - 'message_fqcn' => 'TestNs\\SoapEnvelope\\Messages\\GetReturnMultiParamInput', - 'headers_fqcn' => 'TestNs\\SoapEnvelope\\Headers\\GetReturnMultiParamInput', - 'part_fqcn' => 'TestNs\\SoapEnvelope\\Parts\\GetReturnMultiParamInput', - 'parts' => [ - 'parameters' => 'GetReturnMultiParam', - ], - ], - 'output' => [ - 'message_fqcn' => 'TestNs\\SoapEnvelope\\Messages\\GetReturnMultiParamOutput', - 'headers_fqcn' => 'TestNs\\SoapEnvelope\\Headers\\GetReturnMultiParamOutput', - 'part_fqcn' => 'TestNs\\SoapEnvelope\\Parts\\GetReturnMultiParamOutput', - 'parts' => [ - 'parameters' => 'GetReturnMultiParamResponse', - 'otherParam' => 'StringType', - ], - ], - 'fault' => [ - ], - ], - 'requestHeader' => [ - 'action' => 'http://www.example.org/test/requestHeader', - 'style' => 'rpc', - 'name' => 'requestHeader', - 'method' => 'requestHeader', - 'input' => [ - 'message_fqcn' => 'TestNs\\SoapEnvelope\\Messages\\RequestHeaderInput', - 'headers_fqcn' => 'TestNs\\SoapEnvelope\\Headers\\RequestHeaderInput', - 'part_fqcn' => 'TestNs\\SoapEnvelope\\Parts\\RequestHeaderInput', - 'parts' => [ - 'parameters' => 'RequestHeader', - ], - ], - 'output' => [ - 'message_fqcn' => 'TestNs\\SoapEnvelope\\Messages\\RequestHeaderOutput', - 'headers_fqcn' => 'TestNs\\SoapEnvelope\\Headers\\RequestHeaderOutput', - 'part_fqcn' => 'TestNs\\SoapEnvelope\\Parts\\RequestHeaderOutput', - 'parts' => [ - 'parameters' => 'RequestHeaderResponse', - ], - ], - 'fault' => [ - ], - ], - 'requestHeaders' => [ - 'action' => 'http://www.example.org/test/requestHeaders', - 'style' => 'rpc', - 'name' => 'requestHeaders', - 'method' => 'requestHeaders', - 'input' => [ - 'message_fqcn' => 'TestNs\\SoapEnvelope\\Messages\\RequestHeadersInput', - 'headers_fqcn' => 'TestNs\\SoapEnvelope\\Headers\\RequestHeadersInput', - 'part_fqcn' => 'TestNs\\SoapEnvelope\\Parts\\RequestHeadersInput', - 'parts' => [ - 'parameters' => 'RequestHeaders', - ], - ], - 'output' => [ - 'message_fqcn' => 'TestNs\\SoapEnvelope\\Messages\\RequestHeadersOutput', - 'headers_fqcn' => 'TestNs\\SoapEnvelope\\Headers\\RequestHeadersOutput', - 'part_fqcn' => 'TestNs\\SoapEnvelope\\Parts\\RequestHeadersOutput', - 'parts' => [ - 'parameters' => 'RequestHeadersResponse', - ], - ], - 'fault' => [ - ], - ], - 'responseHader' => [ - 'action' => 'http://www.example.org/test/responseHader', - 'style' => 'rpc', - 'name' => 'responseHader', - 'method' => 'responseHader', - 'input' => [ - 'message_fqcn' => 'TestNs\\SoapEnvelope\\Messages\\ResponseHaderInput', - 'headers_fqcn' => 'TestNs\\SoapEnvelope\\Headers\\ResponseHaderInput', - 'part_fqcn' => 'TestNs\\SoapEnvelope\\Parts\\ResponseHaderInput', - 'parts' => [ - 'parameters' => 'ResponseHader', - ], - ], - 'output' => [ - 'message_fqcn' => 'TestNs\\SoapEnvelope\\Messages\\ResponseHaderOutput', - 'headers_fqcn' => 'TestNs\\SoapEnvelope\\Headers\\ResponseHaderOutput', - 'part_fqcn' => 'TestNs\\SoapEnvelope\\Parts\\ResponseHaderOutput', - 'parts' => [ - 'parameters' => 'ResponseHaderResponse', - ], - ], - 'fault' => [ - ], - ], - 'responseFault' => [ - 'action' => 'http://www.example.org/test/responseFault', - 'style' => 'rpc', - 'name' => 'responseFault', - 'method' => 'responseFault', - 'input' => [ - 'message_fqcn' => 'TestNs\\SoapEnvelope\\Messages\\ResponseFaultInput', - 'headers_fqcn' => 'TestNs\\SoapEnvelope\\Headers\\ResponseFaultInput', - 'part_fqcn' => 'TestNs\\SoapEnvelope\\Parts\\ResponseFaultInput', - 'parts' => [ - 'parameters' => 'ResponseFault', - ], - ], - 'output' => [ - 'message_fqcn' => 'TestNs\\SoapEnvelope\\Messages\\ResponseFaultOutput', - 'headers_fqcn' => 'TestNs\\SoapEnvelope\\Headers\\ResponseFaultOutput', - 'part_fqcn' => 'TestNs\\SoapEnvelope\\Parts\\ResponseFaultOutput', - 'parts' => [ - 'parameters' => 'ResponseFaultResponse', - ], - ], - 'fault' => [ - ], - ], - 'responseFaults' => [ - 'action' => 'http://www.example.org/test/responseFaults', - 'style' => 'rpc', - 'name' => 'responseFaults', - 'method' => 'responseFaults', - 'input' => [ - 'message_fqcn' => 'TestNs\\SoapEnvelope\\Messages\\ResponseFaultsInput', - 'headers_fqcn' => 'TestNs\\SoapEnvelope\\Headers\\ResponseFaultsInput', - 'part_fqcn' => 'TestNs\\SoapEnvelope\\Parts\\ResponseFaultsInput', - 'parts' => [ - 'parameters' => 'ResponseFaults', - ], - ], - 'output' => [ - 'message_fqcn' => 'TestNs\\SoapEnvelope\\Messages\\ResponseFaultsOutput', - 'headers_fqcn' => 'TestNs\\SoapEnvelope\\Headers\\ResponseFaultsOutput', - 'part_fqcn' => 'TestNs\\SoapEnvelope\\Parts\\ResponseFaultsOutput', - 'parts' => [ - 'parameters' => 'ResponseFaultsResponse', - ], - ], - 'fault' => [ - ], - ], - 'noInput' => [ - 'action' => 'http://www.example.org/test/noInput', - 'style' => 'rpc', - 'name' => 'noInput', - 'method' => 'noInput', - 'input' => [ - 'message_fqcn' => 'TestNs\\SoapEnvelope\\Messages\\NoInputInput', - 'headers_fqcn' => 'TestNs\\SoapEnvelope\\Headers\\NoInputInput', - 'part_fqcn' => 'TestNs\\SoapEnvelope\\Parts\\NoInputInput', - 'parts' => [ - ], - ], - 'output' => [ - 'message_fqcn' => 'TestNs\\SoapEnvelope\\Messages\\NoInputOutput', - 'headers_fqcn' => 'TestNs\\SoapEnvelope\\Headers\\NoInputOutput', - 'part_fqcn' => 'TestNs\\SoapEnvelope\\Parts\\NoInputOutput', - 'parts' => [ - 'parameters' => 'NoInputResponse', - ], - ], - 'fault' => [ - ], - ], - 'noOutput' => [ - 'action' => 'http://www.example.org/test/noOutput', - 'style' => 'rpc', - 'name' => 'noOutput', - 'method' => 'noOutput', - 'input' => [ - 'message_fqcn' => 'TestNs\\SoapEnvelope\\Messages\\NoOutputInput', - 'headers_fqcn' => 'TestNs\\SoapEnvelope\\Headers\\NoOutputInput', - 'part_fqcn' => 'TestNs\\SoapEnvelope\\Parts\\NoOutputInput', - 'parts' => [ - 'parameters' => 'NoOutput', - ], - ], - 'output' => [ - 'message_fqcn' => 'TestNs\\SoapEnvelope\\Messages\\NoOutputOutput', - 'headers_fqcn' => 'TestNs\\SoapEnvelope\\Headers\\NoOutputOutput', - 'part_fqcn' => 'TestNs\\SoapEnvelope\\Parts\\NoOutputOutput', - 'parts' => [ - ], - ], - 'fault' => [ - ], - ], - 'noBoth' => [ - 'action' => 'http://www.example.org/test/noBoth', - 'style' => 'rpc', - 'name' => 'noBoth', - 'method' => 'noBoth', - 'input' => [ - 'message_fqcn' => 'TestNs\\SoapEnvelope\\Messages\\NoBothInput', - 'headers_fqcn' => 'TestNs\\SoapEnvelope\\Headers\\NoBothInput', - 'part_fqcn' => 'TestNs\\SoapEnvelope\\Parts\\NoBothInput', - 'parts' => [ - ], - ], - 'output' => [ - 'message_fqcn' => 'TestNs\\SoapEnvelope\\Messages\\NoBothOutput', - 'headers_fqcn' => 'TestNs\\SoapEnvelope\\Headers\\NoBothOutput', - 'part_fqcn' => 'TestNs\\SoapEnvelope\\Parts\\NoBothOutput', - 'parts' => [ - ], - ], - 'fault' => [ - ], - ], - ], - 'endpoint' => 'http://www.example.org/', - 'unwrap' => false, - ], - ], - 'alternativeTest' => [ - 'aPort' => [ - 'operations' => [ - ], - 'endpoint' => 'http://www.example.org/', - 'unwrap' => false, - ], - 'otherPort' => [ - 'operations' => [ - 'doSomething' => [ - 'action' => 'http://www.example.org/test/doSomething', - 'style' => 'rpc', - 'name' => 'doSomething', - 'method' => 'doSomething', - 'input' => [ - 'message_fqcn' => 'TestNs\\SoapEnvelope\\Messages\\DoSomethingInput', - 'headers_fqcn' => 'TestNs\\SoapEnvelope\\Headers\\DoSomethingInput', - 'part_fqcn' => 'TestNs\\SoapEnvelope\\Parts\\DoSomethingInput', - 'parts' => [ - 'parameters' => 'DoSomething', - ], - ], - 'output' => [ - 'message_fqcn' => 'TestNs\\SoapEnvelope\\Messages\\DoSomethingOutput', - 'headers_fqcn' => 'TestNs\\SoapEnvelope\\Headers\\DoSomethingOutput', - 'part_fqcn' => 'TestNs\\SoapEnvelope\\Parts\\DoSomethingOutput', - 'parts' => [ - 'parameters' => 'DoSomethingResponse', - ], - ], - 'fault' => [ - ], - ], - ], - 'endpoint' => 'http://www.example.org/', - 'unwrap' => false, - ], - 'http' => [ - 'operations' => [ - ], - 'endpoint' => NULL, - 'unwrap' => false, - ], - ], -]; diff --git a/tests/Fixtures/test.wsdl b/tests/Fixtures/test.wsdl deleted file mode 100644 index d89d6a4..0000000 --- a/tests/Fixtures/test.wsdl +++ /dev/null @@ -1,501 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tests/Metadata/MetadataTest.php b/tests/Metadata/MetadataTest.php deleted file mode 100644 index 77582a4..0000000 --- a/tests/Metadata/MetadataTest.php +++ /dev/null @@ -1,39 +0,0 @@ -metadataGenerator = new MetadataGenerator($naming, ['http://www.example.org/test/' => 'TestNs']); - } - - public function testMetadata() - { - - $dispatcher = new EventDispatcher(); - $wsdlReader = new DefinitionsReader(null, $dispatcher); - $soapReader = new SoapReader(); - $dispatcher->addSubscriber($soapReader); - $wsdlReader->readFile(__DIR__ . '/../Fixtures/test.wsdl'); - - $services = $this->metadataGenerator->generate($soapReader->getServices()); - $this->assertExpectedServices($services); - } - - public function assertExpectedServices(array $services) - { - $expected = require __DIR__ . '/../Fixtures/test.php'; - return $this->assertEquals($expected, $services); - } -} diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100644 index 1f32b4e..0000000 --- a/tests/bootstrap.php +++ /dev/null @@ -1,4 +0,0 @@ -