Skip to content

Commit

Permalink
Merge pull request #10 from veewee/configurable-wsdl-tools
Browse files Browse the repository at this point in the history
Make WSDL tools configurable by other packages
  • Loading branch information
veewee authored Apr 1, 2023
2 parents c622287 + 1974af9 commit 4576557
Show file tree
Hide file tree
Showing 10 changed files with 100,324 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/analyzers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
- name: Install dependencies
run: composer update --prefer-dist --no-progress --no-suggest ${{ matrix.composer-options }}
- name: Run the tests
run: ./tools/psalm.phar
run: ./vendor/bin/psalm
1 change: 0 additions & 1 deletion .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="psalm" version="^4.30.0" installed="4.30.0" location="./tools/psalm.phar" copy="true"/>
<phar name="php-cs-fixer" version="^3.13.0" installed="3.13.0" location="./tools/php-cs-fixer.phar" copy="true"/>
</phive>
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ The final result is stored in a single WSDL file.
This command performs some basic validations on the provided WSDL file.
If your WSDL contains any imports, you'll have to flatten the WSDL into a single file first.

### Extensions

By installing additional packages from `php-soap`, additional commands will be added to the WSDL tools:

* [wsdl-reader](https://github.com/php-soap/wsdl-reader): Will install inspect commands that will give you a human-readable version of all information inside your WSDL.

### Custom WSDL Loader

By default, all CLI tools use the StreamWrapperLoader.
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"psalm/plugin-symfony": "^4.0"
"psalm/plugin-symfony": "^5.0",
"vimeo/psalm": "^5.9.0"
}
}
21 changes: 21 additions & 0 deletions src/Console/AppFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@

final class AppFactory
{
/**
* @psalm-suppress UndefinedClass
* @var list<class-string>
*/
private static array $configurators = [
\Soap\WsdlReader\Console\WsdlReaderConfigurator::class
];

/**
* @throws LogicException
*/
Expand All @@ -19,6 +27,19 @@ public static function create(): Application
new Command\ValidateCommand(),
]);

self::configure($app);

return $app;
}

private static function configure(Application $app): void
{
foreach (self::$configurators as $configurator) {
if (!class_exists($configurator) || !is_a($configurator, Configurator::class, true)) {
continue;
}

$configurator::configure($app);
}
}
}
11 changes: 11 additions & 0 deletions src/Console/Configurator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);

namespace Soap\Wsdl\Console;

use Symfony\Component\Console\Application;

interface Configurator
{
public static function configure(Application $application): void;
}
2 changes: 1 addition & 1 deletion src/Xml/Configurator/FlattenWsdlImports.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __invoke(DOMDocument $document): DOMDocument
$xml = Document::fromUnsafeDocument($document);
$xpath = $xml->xpath(new WsdlPreset($xml));

$imports = $xpath->query('wsdl:import');
$imports = $xpath->query('wsdl:import')->expectAllOfType(DOMElement::class);
$imports->forEach(fn (DOMElement $import) => $this->importWsdlImportElement($import));

return $document;
Expand Down
17 changes: 10 additions & 7 deletions src/Xml/Validator/SchemaSyntaxValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ public function __invoke(DOMDocument $document): IssueCollection
$xml = Document::fromUnsafeDocument($document);
$xpath = $xml->xpath(new WsdlPreset($xml));

return $xpath->query('//schema:schema')->reduce(
fn (IssueCollection $issues, DOMElement $schema) => new IssueCollection(
...$issues,
...Document::fromXmlNode($schema)->validate(xsd_validator($this->xsd))
),
new IssueCollection()
);
return $xpath
->query('//schema:schema')
->expectAllOfType(DOMElement::class)
->reduce(
fn (IssueCollection $issues, DOMElement $schema) => new IssueCollection(
...$issues,
...Document::fromXmlNode($schema)->validate(xsd_validator($this->xsd))
),
new IssueCollection()
);
}
}
100,272 changes: 100,272 additions & 0 deletions tools/phpunit.phar

Large diffs are not rendered by default.

Binary file removed tools/psalm.phar
Binary file not shown.

0 comments on commit 4576557

Please sign in to comment.