forked from php-soap/wsdl-reader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNamespacesParser.php
More file actions
44 lines (40 loc) · 1.37 KB
/
NamespacesParser.php
File metadata and controls
44 lines (40 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
declare(strict_types=1);
namespace Soap\WsdlReader\Parser\Definitions;
use Dom\NamespaceInfo;
use Soap\WsdlReader\Model\Definitions\Namespaces;
use VeeWee\Xml\Dom\Document;
use function Psl\Dict\merge;
use function Psl\Iter\reduce;
use function VeeWee\Xml\Dom\Locator\document_element;
use function VeeWee\Xml\Dom\Locator\Xmlns\recursive_linked_namespaces;
final class NamespacesParser
{
public static function tryParse(Document $wsdl): Namespaces
{
$root = $wsdl->map(document_element());
$allNamespaces = recursive_linked_namespaces($root);
return new Namespaces(
reduce(
$allNamespaces,
/**
* @param array<string, string> $map
* @return array<string, string>
*/
static fn (array $map, NamespaceInfo $node): array
=> merge($map, [(string)$node->prefix => (string)$node->namespaceURI]),
[]
),
reduce(
$allNamespaces,
/**
* @param array<string, string> $map
* @return array<string, string>
*/
static fn (array $map, NamespaceInfo $node): array
=> merge($map, [(string)$node->namespaceURI => (string)$node->prefix]),
[]
)
);
}
}