1
|
|
|
<?php |
2
|
|
|
namespace GoetasWebservices\SoapServices\SoapClient\Arguments; |
3
|
|
|
|
4
|
|
|
use Doctrine\Common\Inflector\Inflector; |
5
|
|
|
use Doctrine\Instantiator\Instantiator; |
6
|
|
|
use JMS\Serializer\Serializer; |
7
|
|
|
|
8
|
|
|
class ArgumentsReader implements ArgumentsReaderInterface |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var Serializer |
12
|
|
|
*/ |
13
|
|
|
private $serializer; |
14
|
|
|
|
15
|
14 |
|
public function __construct(Serializer $serializer) |
16
|
|
|
{ |
17
|
14 |
|
$this->serializer = $serializer; |
18
|
14 |
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param array $args |
22
|
|
|
* @param array $input |
23
|
|
|
* @return null|object |
24
|
|
|
*/ |
25
|
12 |
|
public function readArguments(array $args, array $input) |
26
|
|
|
{ |
27
|
12 |
|
$instantiator = new Instantiator(); |
28
|
12 |
|
$envelope = $instantiator->instantiate($input['message_fqcn']); |
29
|
|
|
|
30
|
12 |
|
if (!count($input['parts'])) { |
31
|
2 |
|
return $envelope; |
32
|
|
|
} |
33
|
|
|
|
34
|
10 |
|
$body = $instantiator->instantiate($input['part_fqcn']); |
35
|
10 |
|
$envelope->setBody($body); |
36
|
10 |
|
$factory = $this->serializer->getMetadataFactory(); |
37
|
10 |
|
$classMetadata = $factory->getMetadataForClass($input['part_fqcn']); |
38
|
|
|
|
39
|
10 |
|
if (count($input['parts']) > 1) { |
40
|
|
|
|
41
|
1 |
|
if (count($input['parts']) !== count($args)) { |
42
|
|
|
throw new \Exception("Expected to have exactly " . count($input['parts']) . " arguments, supplied " . count($args)); |
43
|
|
|
} |
44
|
|
|
|
45
|
1 |
|
foreach ($input['parts'] as $paramName) { |
46
|
|
|
//@todo $propertyName should use the xsd2php naming strategy (or do in the metadata extractor) |
47
|
1 |
|
$propertyName = Inflector::camelize(str_replace(".", " ", $paramName)); |
48
|
1 |
|
$propertyMetadata = $classMetadata->propertyMetadata[$propertyName]; |
49
|
1 |
|
$propertyMetadata->setValue($body, array_shift($args)); |
50
|
1 |
|
} |
51
|
1 |
|
return $envelope; |
52
|
|
|
} |
53
|
|
|
|
54
|
9 |
|
$propertyName = Inflector::camelize(str_replace(".", " ", reset($input['parts']))); |
55
|
9 |
|
$propertyMetadata = $classMetadata->propertyMetadata[$propertyName]; |
56
|
9 |
|
if ($args[0] instanceof $propertyMetadata->type['name']) { |
57
|
1 |
|
$propertyMetadata->setValue($body, reset($args)); |
58
|
1 |
|
return $envelope; |
59
|
|
|
} |
60
|
|
|
|
61
|
8 |
|
$instance2 = $instantiator->instantiate($propertyMetadata->type['name']); |
62
|
8 |
|
$classMetadata2 = $factory->getMetadataForClass($propertyMetadata->type['name']); |
63
|
8 |
|
$propertyMetadata->setValue($body, $instance2); |
64
|
|
|
|
65
|
8 |
|
foreach ($classMetadata2->propertyMetadata as $propertyMetadata2) { |
66
|
8 |
|
if (!count($args)) { |
67
|
|
|
throw new \Exception("Not enough arguments provided. Can't fina a parameter to set " . $propertyMetadata2->name); |
68
|
|
|
} |
69
|
8 |
|
$value = array_pop($args); |
70
|
8 |
|
$propertyMetadata2->setValue($instance2, $value); |
71
|
8 |
|
} |
72
|
8 |
|
return $envelope; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|