Skip to content

Commit

Permalink
ref
Browse files Browse the repository at this point in the history
  • Loading branch information
goetas committed Dec 30, 2020
1 parent 2944ee9 commit dfe2d29
Show file tree
Hide file tree
Showing 50 changed files with 1,295 additions and 1,490 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
/vendor
composer.lock
composer.lock
tmp
10 changes: 0 additions & 10 deletions .scrutinizer.yml

This file was deleted.

30 changes: 0 additions & 30 deletions .travis.yml

This file was deleted.

19 changes: 0 additions & 19 deletions LICENSE

This file was deleted.

9 changes: 0 additions & 9 deletions README.md

This file was deleted.

24 changes: 7 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,21 @@
"email": "[email protected]"
}
],
"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"
}
}
}
33 changes: 0 additions & 33 deletions phpunit.xml.dist

This file was deleted.

148 changes: 148 additions & 0 deletions src/Arguments/ArgumentsReader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?php

declare(strict_types=1);

namespace GoetasWebservices\SoapServices\Metadata\Arguments;

use Doctrine\Instantiator\Instantiator;
use GoetasWebservices\SoapServices\Metadata\Arguments\Headers\Header;
use GoetasWebservices\SoapServices\Metadata\SerializerUtils;
use JMS\Serializer\Accessor\DefaultAccessorStrategy;
use JMS\Serializer\DeserializationContext;
use JMS\Serializer\Metadata\PropertyMetadata;
use JMS\Serializer\Serializer;

class ArgumentsReader implements ArgumentsReaderInterface
{
/**
* @var Serializer
*/
private $serializer;

public function __construct(Serializer $serializer)
{
$this->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);
}
}
14 changes: 14 additions & 0 deletions src/Arguments/ArgumentsReaderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace GoetasWebservices\SoapServices\Metadata\Arguments;

interface ArgumentsReaderInterface
{
/**
* @param array $args
* @param array $input
*/
public function readArguments(array $args, array $input): object;
}
30 changes: 30 additions & 0 deletions src/Arguments/Headers/Handler/FaultHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace GoetasWebservices\SoapServices\Metadata\Arguments\Headers\Handler;

use JMS\Serializer\DeserializationContext;
use JMS\Serializer\GraphNavigator;
use JMS\Serializer\Handler\SubscribingHandlerInterface;
use JMS\Serializer\XmlDeserializationVisitor;

class FaultHandler implements SubscribingHandlerInterface
{
public static function getSubscribingMethods(): array
{
return [
[
'direction' => 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();
}
}
Loading

0 comments on commit dfe2d29

Please sign in to comment.