-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
50 changed files
with
1,295 additions
and
1,490 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.idea | ||
/vendor | ||
composer.lock | ||
composer.lock | ||
tmp |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.