Issues (3541)

substitutionGroup.php (8 issues)

Labels
Severity
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 shows the usage of the very useful classes contained by the PackageGenerator project.
10
 * In addition, it shows that we can easily manipulate and update any schema.
11
 */
12
13
require_once 'vendor/autoload.php';
14
15
use WsdlToPhp\PackageGenerator\DomHandler\Wsdl\Wsdl;
0 ignored issues
show
The type WsdlToPhp\PackageGenerator\DomHandler\Wsdl\Wsdl was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use WsdlToPhp\PackageGenerator\Generator\Generator;
0 ignored issues
show
The type WsdlToPhp\PackageGenerator\Generator\Generator was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
This use statement conflicts with another class in this namespace, Generator. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
17
use WsdlToPhp\PackageGenerator\ConfigurationReader\GeneratorOptions;
0 ignored issues
show
The type WsdlToPhp\PackageGenerat...Reader\GeneratorOptions was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use WsdlToPhp\PackageGenerator\Parser\Wsdl\TagInclude;
0 ignored issues
show
The type WsdlToPhp\PackageGenerator\Parser\Wsdl\TagInclude was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use WsdlToPhp\PackageGenerator\Parser\Wsdl\TagImport;
0 ignored issues
show
The type WsdlToPhp\PackageGenerator\Parser\Wsdl\TagImport was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
21
$dom = new \DOMDocument('1.0', 'UTF-8');
22
$dom->ouputFormated = true;
0 ignored issues
show
The property ouputFormated does not seem to exist on DOMDocument.
Loading history...
23
$dom->formatedOutput = true;
0 ignored issues
show
The property formatedOutput does not exist on DOMDocument. Did you mean formatOutput?
Loading history...
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