|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GoetasWebservices\SoapServices\Metadata\Arguments\Headers\Handler; |
|
4
|
|
|
|
|
5
|
|
|
use GoetasWebservices\SoapServices\Metadata\Arguments\Headers\Header; |
|
6
|
|
|
use GoetasWebservices\SoapServices\Metadata\Arguments\Headers\HeaderBag; |
|
7
|
|
|
use JMS\Serializer\DeserializationContext; |
|
8
|
|
|
use JMS\Serializer\GraphNavigator; |
|
9
|
|
|
use JMS\Serializer\Handler\SubscribingHandlerInterface; |
|
10
|
|
|
use JMS\Serializer\Metadata\StaticPropertyMetadata; |
|
11
|
|
|
use JMS\Serializer\SerializationContext; |
|
12
|
|
|
use JMS\Serializer\XmlDeserializationVisitor; |
|
13
|
|
|
use JMS\Serializer\XmlSerializationVisitor; |
|
14
|
|
|
use Symfony\Component\DependencyInjection\SimpleXMLElement; |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
class HeaderHandler implements SubscribingHandlerInterface |
|
17
|
|
|
{ |
|
18
|
|
|
const SOAP = 'http://schemas.xmlsoap.org/soap/envelope/'; |
|
19
|
|
|
const SOAP_12 = 'http://www.w3.org/2003/05/soap-envelope'; |
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
protected $headerData = []; |
|
23
|
|
|
|
|
24
|
|
|
public static function getSubscribingMethods() |
|
25
|
|
|
{ |
|
26
|
|
|
return array( |
|
27
|
|
|
array( |
|
28
|
|
|
'direction' => GraphNavigator::DIRECTION_SERIALIZATION, |
|
29
|
|
|
'format' => 'xml', |
|
30
|
|
|
'type' => HeaderPlaceholder::class, |
|
31
|
|
|
'method' => 'serializeHeaderPlaceholder' |
|
32
|
|
|
), |
|
33
|
|
|
array( |
|
34
|
|
|
'direction' => GraphNavigator::DIRECTION_DESERIALIZATION, |
|
35
|
|
|
'format' => 'xml', |
|
36
|
|
|
'type' => HeaderPlaceholder::class, |
|
37
|
|
|
'method' => 'deserializeHeaderPlaceholder' |
|
38
|
|
|
), |
|
39
|
|
|
array( |
|
40
|
|
|
'direction' => GraphNavigator::DIRECTION_DESERIALIZATION, |
|
41
|
|
|
'format' => 'xml', |
|
42
|
|
|
'type' => 'GoetasWebservices\SoapServices\SoapEnvelope\Header', |
|
43
|
|
|
'method' => 'deserializeHeader' |
|
44
|
|
|
), |
|
45
|
|
|
array( |
|
46
|
|
|
'direction' => GraphNavigator::DIRECTION_SERIALIZATION, |
|
47
|
|
|
'format' => 'xml', |
|
48
|
|
|
'type' => Header::class, |
|
49
|
|
|
'method' => 'serializeHeader' |
|
50
|
|
|
), |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function deserializeHeaderPlaceholder(XmlDeserializationVisitor $visitor, \SimpleXMLElement $data, array $type, DeserializationContext $context) |
|
|
|
|
|
|
55
|
|
|
{ |
|
56
|
|
|
$type = array('name' => $type['params'][0], 'params' => []); |
|
57
|
|
|
|
|
58
|
|
|
return $context->getNavigator()->accept($data, $type, $context); |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function deserializeHeader(XmlDeserializationVisitor $visitor, \SimpleXMLElement $data, array $type, DeserializationContext $context) |
|
62
|
|
|
{ |
|
63
|
|
|
$type = array('name' => $type['params'][0], 'params' => []); |
|
64
|
|
|
|
|
65
|
|
|
$return = $context->getNavigator()->accept($data, $type, $context); |
|
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
$mustUnderstandAttr = $data->attributes(self::SOAP_12)->mustUnderstand ?: $data->attributes(self::SOAP)->mustUnderstand; |
|
68
|
|
|
$mustUnderstand = $mustUnderstandAttr !== null && $visitor->visitBoolean($mustUnderstandAttr, [], $context); |
|
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @var HeaderBag $headerBag |
|
71
|
|
|
*/ |
|
72
|
|
|
$headerBag = $context->getAttribute('headers_bag'); |
|
73
|
|
|
|
|
74
|
|
|
if ($mustUnderstand) { |
|
75
|
|
|
$headerBag->addMustUnderstandHeader($return); |
|
76
|
|
|
} else { |
|
77
|
|
|
$headerBag->addHeader($return); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return $return; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function serializeHeaderPlaceholder(XmlSerializationVisitor $visitor, HeaderPlaceholder $data, array $type, SerializationContext $context) |
|
|
|
|
|
|
84
|
|
|
{ |
|
85
|
|
|
/** |
|
86
|
|
|
* @var HeaderBag $headerBag |
|
87
|
|
|
*/ |
|
88
|
|
|
$headerBag = $context->getAttribute('headers_bag'); |
|
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
$factory = $context->getMetadataFactory(); |
|
91
|
|
|
/** |
|
92
|
|
|
* @var $header Header |
|
93
|
|
|
*/ |
|
94
|
|
|
foreach ($this->headerData[spl_object_hash($data)] as $header) { |
|
95
|
|
|
/** |
|
96
|
|
|
* @var $classMetadata \JMS\Serializer\Metadata\ClassMetadata |
|
97
|
|
|
*/ |
|
98
|
|
|
$classMetadata = $factory->getMetadataForClass(get_class($header->getData())); |
|
99
|
|
|
|
|
100
|
|
|
$name = ($pos = strpos($classMetadata->xmlRootName, ':')) !== false ? substr($classMetadata->xmlRootName, $pos + 1) : $classMetadata->xmlRootName; |
|
101
|
|
|
|
|
102
|
|
|
$metadata = new StaticPropertyMetadata($classMetadata->name, $name, $header->getData()); |
|
103
|
|
|
$metadata->xmlNamespace = $classMetadata->xmlRootNamespace; |
|
104
|
|
|
$metadata->serializedName = $name; |
|
105
|
|
|
|
|
106
|
|
|
$visitor->visitProperty($metadata, $header->getData(), $context); |
|
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
$this->handleOptions($visitor, $header); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
public function serializeHeader(XmlSerializationVisitor $visitor, Header $header, array $type, SerializationContext $context) |
|
|
|
|
|
|
114
|
|
|
{ |
|
115
|
|
|
|
|
116
|
|
|
$factory = $context->getMetadataFactory(); |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @var $classMetadata \JMS\Serializer\Metadata\ClassMetadata |
|
120
|
|
|
*/ |
|
121
|
|
|
$classMetadata = $factory->getMetadataForClass(get_class($header->getData())); |
|
122
|
|
|
|
|
123
|
|
|
$name = ($pos = strpos($classMetadata->xmlRootName, ':')) !== false ? substr($classMetadata->xmlRootName, $pos + 1) : $classMetadata->xmlRootName; |
|
124
|
|
|
|
|
125
|
|
|
$metadata = new StaticPropertyMetadata($classMetadata->name, $name, $header->getData()); |
|
126
|
|
|
$metadata->xmlNamespace = $classMetadata->xmlRootNamespace; |
|
127
|
|
|
$metadata->serializedName = $name; |
|
128
|
|
|
|
|
129
|
|
|
$visitor->visitProperty($metadata, $header->getData(), $context); |
|
|
|
|
|
|
130
|
|
|
|
|
131
|
|
|
$this->handleOptions($visitor, $header->getOptions()); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
private function handleOptions(XmlSerializationVisitor $visitor, $options) |
|
135
|
|
|
{ |
|
136
|
|
|
if (!count($options)) { |
|
137
|
|
|
return; |
|
138
|
|
|
} |
|
139
|
|
|
/** |
|
140
|
|
|
* @var $currentNode \DOMNode |
|
141
|
|
|
*/ |
|
142
|
|
|
$currentNode = $visitor->getCurrentNode(); |
|
143
|
|
|
foreach ($options as $option => $value) { |
|
144
|
|
|
if (in_array($option, ['mustUnderstand', 'required', 'role', 'actor'])) { |
|
145
|
|
|
|
|
146
|
|
|
if ($currentNode->ownerDocument->documentElement->namespaceURI === self::SOAP_12) { |
|
147
|
|
|
$envelopeNS = self::SOAP_12; |
|
148
|
|
|
} else { |
|
149
|
|
|
$envelopeNS = self::SOAP; |
|
150
|
|
|
} |
|
151
|
|
|
$this->setAttributeOnNode($currentNode->lastChild, $option, $value, $envelopeNS); |
|
152
|
|
|
} |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
private function setAttributeOnNode(\DOMElement $node, $name, $value, $namespace) |
|
157
|
|
|
{ |
|
158
|
|
|
if (!($prefix = $node->lookupPrefix($namespace)) && !($prefix = $node->ownerDocument->lookupPrefix($namespace))) { |
|
159
|
|
|
$prefix = 'ns-' . substr(sha1($namespace), 0, 8); |
|
160
|
|
|
} |
|
161
|
|
|
$node->setAttributeNS($namespace, $prefix . ':' . $name, is_bool($value) || is_null($value) ? ($value ? 'true' : 'false') : $value); |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
|
|
166
|
|
|
|
|
167
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths