These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * This script is intended to "fix" the schema as the native PHP SoapClient class does not handle correctly the substitutionGroup attribute. |
||
4 | * In order to "fix" the schema widely, programmatically and quickly, we use this script. |
||
5 | * Make sure to run this command line first: composer require --dev wsdltophp/packagegenerator |
||
6 | * Then run: php substitutionGroup.php |
||
7 | * Then regenerate the package: ./generate.sh |
||
8 | * |
||
9 | * This script show the usage of the classes contained by the packagegenerator project which are very useful. |
||
10 | * In addition, it shows that we can pretty easeily manipulate an update any schema. |
||
11 | */ |
||
12 | |||
13 | require_once 'vendor/autoload.php'; |
||
14 | |||
15 | use WsdlToPhp\PackageGenerator\DomHandler\Wsdl\Wsdl; |
||
16 | use WsdlToPhp\PackageGenerator\Generator\Generator; |
||
17 | use WsdlToPhp\PackageGenerator\ConfigurationReader\GeneratorOptions; |
||
18 | use WsdlToPhp\PackageGenerator\Parser\Wsdl\TagInclude; |
||
19 | use WsdlToPhp\PackageGenerator\Parser\Wsdl\TagImport; |
||
20 | |||
21 | $dom = new \DOMDocument('1.0', 'UTF-8'); |
||
22 | $dom->ouputFormated = true; |
||
0 ignored issues
–
show
|
|||
23 | $dom->formatedOutput = true; |
||
0 ignored issues
–
show
The property
formatedOutput does not seem to exist. Did you mean formatOutput ?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
|||
24 | $dom->load(__DIR__ . '/wsdl/services.wsdl'); |
||
25 | $generator = new Generator(GeneratorOptions::instance()->setOrigin(__DIR__ . '/wsdl/services.wsdl')); |
||
26 | |||
27 | $wsdl = new Wsdl($dom, $generator); |
||
28 | $includeParser = new TagInclude($generator); |
||
29 | $importParser = new TagImport($generator); |
||
30 | $includeParser->parse(); |
||
31 | $importParser->parse(); |
||
32 | |||
33 | echo $generator->getWsdl()->getContent()->getExternalSchemas()->count(); |
||
34 | |||
35 | $substitionGroupNames = array('t:SearchExpression', 't:Path', 't:Transition'); |
||
36 | foreach($substitionGroupNames as $substitionGroupName) { |
||
37 | $substitionGroups = $generator->getWsdl()->getContent()->getElementsByNameAndAttributes('element', array( |
||
38 | 'substitutionGroup' => $substitionGroupName |
||
39 | ), null, true); |
||
40 | |||
41 | echo PHP_EOL . sprintf(' %s subscription groups found for %s', count($substitionGroups), $substitionGroupName) . PHP_EOL; |
||
42 | |||
43 | foreach($generator->getWsdl()->getContent()->getExternalSchemas() as $externalSchema) { |
||
44 | /** @var \WsdlToPhp\PackageGenerator\Container\Model\Schema $externalSchema */ |
||
45 | $searchExpressions = $externalSchema->getContent()->getElementsByNameAndAttributes('element', array( |
||
46 | 'ref' => $substitionGroupName |
||
47 | ), null, true); |
||
48 | |||
49 | echo PHP_EOL . sprintf('%s %s found in %s', count($searchExpressions), $substitionGroupName, $externalSchema->getName()) . PHP_EOL; |
||
50 | |||
51 | foreach($searchExpressions as $searchExpression) { |
||
52 | $parent = $searchExpression->getParent(); |
||
53 | $parent->getElement()->removeChild($searchExpression->getNode()); |
||
54 | $parent->getElement()->appendChild($parent->getDomDocumentHandler()->getRootElement()->getParent()->getNode()->createComment(' ### Subscription group ' . $substitionGroupName . ' is replaced by actual elements ### ')); |
||
55 | foreach($substitionGroups as $substitionGroup) { |
||
56 | echo PHP_EOL . $substitionGroup->getAttributeName(); |
||
57 | $node = $parent->getDomDocumentHandler()->getRootElement()->getParent()->getNode()->createElementNS('http://www.w3.org/2001/XMLSchema', 'element'); |
||
58 | $node->setAttribute('name', $substitionGroup->getAttributeName()); |
||
59 | $node->setAttribute('type', $substitionGroup->getAttribute('type')->getValue(true)); |
||
60 | $parent->getElement()->appendChild($node); |
||
61 | } |
||
62 | $parent->getDomDocumentHandler()->getRootElement()->getParent()->getNode()->formatOutput = true; |
||
63 | } |
||
64 | echo $externalSchema->getContent()->getRootElement()->getParent()->getNode()->save(str_replace('.xsd', '.updated.xsd', $externalSchema->getName())); |
||
65 | } |
||
66 | } |
||
67 | |||
68 | echo PHP_EOL; |
||
69 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.