1
|
|
|
<?php |
2
|
|
|
namespace GoetasWebservices\Xsd\XsdToPhpRuntime\Jms\Handler; |
3
|
|
|
|
4
|
|
|
use JMS\Serializer\Context; |
5
|
|
|
use JMS\Serializer\GraphNavigator; |
6
|
|
|
use JMS\Serializer\Handler\SubscribingHandlerInterface; |
7
|
|
|
use JMS\Serializer\XmlDeserializationVisitor; |
8
|
|
|
use JMS\Serializer\XmlSerializationVisitor; |
9
|
|
|
|
10
|
|
|
class BaseTypesHandler implements SubscribingHandlerInterface |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
public static function getSubscribingMethods() |
14
|
|
|
{ |
15
|
|
|
return array( |
16
|
|
|
array( |
17
|
|
|
'direction' => GraphNavigator::DIRECTION_SERIALIZATION, |
18
|
|
|
'format' => 'xml', |
19
|
|
|
'type' => 'GoetasWebservices\Xsd\XsdToPhp\Jms\SimpleListOf', |
20
|
|
|
'method' => 'simpleListOfToXml' |
21
|
|
|
), |
22
|
|
|
array( |
23
|
|
|
'direction' => GraphNavigator::DIRECTION_DESERIALIZATION, |
24
|
|
|
'format' => 'xml', |
25
|
|
|
'type' => 'GoetasWebservices\Xsd\XsdToPhp\Jms\SimpleListOf', |
26
|
|
|
'method' => 'simpleListOfFromXML' |
27
|
|
|
), |
28
|
|
|
array( |
29
|
|
|
'direction' => GraphNavigator::DIRECTION_SERIALIZATION, |
30
|
|
|
'format' => 'xml', |
31
|
|
|
'type' => 'GoetasWebservices\Xsd\XsdToPhp\Jms\Base64Encoded', |
32
|
|
|
'method' => 'base64EncodedToXml' |
33
|
|
|
), |
34
|
|
|
array( |
35
|
|
|
'direction' => GraphNavigator::DIRECTION_DESERIALIZATION, |
36
|
|
|
'format' => 'xml', |
37
|
|
|
'type' => 'GoetasWebservices\Xsd\XsdToPhp\Jms\Base64Encoded', |
38
|
|
|
'method' => 'base64EncodedFromXml' |
39
|
|
|
) |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
public function base64EncodedToXml(XmlSerializationVisitor $visitor, $data, array $type, Context $context) |
43
|
|
|
{ |
44
|
|
|
return $visitor->visitSimpleString(base64_encode($data), $type, $context); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
View Code Duplication |
public function base64EncodedFromXml(XmlDeserializationVisitor $visitor, $data, array $type) |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
$attributes = $data->attributes('xsi', true); |
50
|
|
|
if (isset($attributes['nil'][0]) && (string)$attributes['nil'][0] === 'true') { |
51
|
|
|
return null; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return base64_decode((string)$data); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
View Code Duplication |
public function simpleListOfToXml(XmlSerializationVisitor $visitor, $object, array $type, Context $context) |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
|
60
|
|
|
$newType = array( |
61
|
|
|
'name' => $type["params"][0]["name"], |
62
|
|
|
'params' => array() |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
$navigator = $context->getNavigator(); |
66
|
|
|
$ret = array(); |
67
|
|
|
foreach ($object as $v) { |
68
|
|
|
$ret[] = $navigator->accept($v, $newType, $context)->data; |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return $visitor->getDocument()->createTextNode(implode(" ", $ret)); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
View Code Duplication |
public function simpleListOfFromXml(XmlDeserializationVisitor $visitor, $node, array $type, Context $context) |
|
|
|
|
75
|
|
|
{ |
76
|
|
|
$newType = array( |
77
|
|
|
'name' => $type["params"][0]["name"], |
78
|
|
|
'params' => array() |
79
|
|
|
); |
80
|
|
|
$ret = array(); |
81
|
|
|
$navigator = $context->getNavigator(); |
82
|
|
|
foreach (explode(" ", (string)$node) as $v) { |
83
|
|
|
$ret[] = $navigator->accept($v, $newType, $context); |
|
|
|
|
84
|
|
|
} |
85
|
|
|
return $ret; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.