Skip to content

Commit 2678c9f

Browse files
committed
Add tests + docs
1 parent 5eea7fc commit 2678c9f

24 files changed

+775
-296
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/vendor/
2+
.phpunit.result.cache
3+
composer.lock

README.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,129 @@ This package provides some tools on top of [veewee/xml](https://github.com/veewe
66

77
### SoapHeaders
88

9+
Makes it possible to build the content of a `soap:Header` element.
10+
11+
```php
12+
use Soap\Xml\Builder\SoapHeaders;
13+
use Soap\Xml\Manipulator\PrependSoapHeaders;use VeeWee\Xml\Dom\Document;
14+
use function VeeWee\Xml\Dom\Builder\children;
15+
use function VeeWee\Xml\Dom\Builder\element;
16+
use function VeeWee\Xml\Dom\Builder\value;
17+
18+
$doc = Document::fromXmlString($xml);
19+
$builder = new SoapHeaders(
20+
children(
21+
element('user', value('josbos')),
22+
element('password', value('topsecret'))
23+
)
24+
);
25+
26+
$header = $doc->build($builder)[0];
27+
28+
// You can prepend the soap:Header as first element of the soap:envelope
29+
// Like this
30+
$doc->manipulate(new PrependSoapHeaders($header));
31+
```
32+
933
## Locator
1034

1135
### BodyNamespaceLocator
36+
37+
Locates the namespace of the first element inside the soap:Body.
38+
39+
```php
40+
use Soap\Xml\Locator\BodyNamespaceLocator;
41+
use VeeWee\Xml\Dom\Document;
42+
43+
$doc = Document::fromXmlString($xml);
44+
$bodyNamespace = $doc->locate(new BodyNamespaceLocator());
45+
```
46+
1247
### SoapBodyLocator
48+
49+
Locates the `soap:Body` element inside a `soap:Envelope`
50+
51+
```php
52+
use Soap\Xml\Locator\SoapBodyLocator;
53+
use VeeWee\Xml\Dom\Document;
54+
55+
$doc = Document::fromXmlString($xml);
56+
$bodyElement = $doc->locate(new SoapBodyLocator());
57+
```
58+
59+
1360
### SoapEnvelopeLocator
61+
62+
Locates the `soap:Envelope` inside XML.
63+
64+
```php
65+
use Soap\Xml\Locator\SoapEnvelopeLocator;
66+
use VeeWee\Xml\Dom\Document;
67+
68+
$doc = Document::fromXmlString($xml);
69+
$bodyElement = $doc->locate(new SoapEnvelopeLocator());
70+
```
71+
1472
### SoapHeaderLocator
1573

74+
Locates the `soap:Header` element inside a `soap:Envelope`
75+
76+
```php
77+
use Soap\Xml\Locator\SoapHeaderLocator;
78+
use VeeWee\Xml\Dom\Document;
79+
80+
$doc = Document::fromXmlString($xml);
81+
$bodyElement = $doc->locate(new SoapHeaderLocator());
82+
```
83+
1684
## Manipulator
1785

1886
### PrependSoapHeaders
1987

88+
See SoapHeaders builder:
89+
90+
```php
91+
$doc = Document::fromXmlString($xml);
92+
$doc->manipulate(new PrependSoapHeaders($soapHeader));
93+
```
94+
2095
## XPath
2196

2297
### EnvelopePreset
98+
99+
This preset allows you to use following xpath prefixes:
100+
101+
- `application`: The namespace of the SOAP implementation.
102+
- `soap`: The soap prefix allows you to fetch common elements like Body, header, Envelope, ...
103+
104+
```php
105+
use Soap\Xml\Xpath\EnvelopePreset;
106+
use VeeWee\Xml\Dom\Document;
107+
108+
$doc = Document::fromXmlString($xml);
109+
$xpath = $doc->xpath(new EnvelopePreset($doc));
110+
111+
$xpath->querySingle('/soap:Envelope');
112+
$xpath->querySingle('//soap:Body');
113+
$xpath->querySingle('//soap:Header');
114+
$xpath->querySingle('//soap:Body//application:Foo');
115+
```
116+
117+
23118
### WsdlPreset
119+
120+
This preset allows you to use following xpath prefixes:
121+
122+
- `wsdl`: The wsdl prefix allows you to fetch common elements like definitions, types, services, operations, ...
123+
124+
```php
125+
use Soap\Xml\Xpath\WsdlPreset;
126+
use VeeWee\Xml\Dom\Document;
127+
128+
$doc = Document::fromXmlString($xml);
129+
$xpath = $doc->xpath(new WsdlPreset($doc));
130+
131+
$xpath->querySingle('/wsdl:definitions');
132+
$xpath->querySingle('//wsdl:types');
133+
$xpath->querySingle('//wsdl:services');
134+
```

composer.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
"Soap\\Xml\\": "src/"
99
}
1010
},
11+
"autoload-dev": {
12+
"psr-4": {
13+
"SoapTest\\Xml\\": "tests/"
14+
}
15+
},
1116
"authors": [
1217
{
1318
"name": "Toon Verwerft",
@@ -18,5 +23,8 @@
1823
"php": "^8.0",
1924
"ext-dom": "*",
2025
"veewee/xml": "^0.6.1"
26+
},
27+
"require-dev": {
28+
"phpunit/phpunit": "^9.5"
2129
}
2230
}

0 commit comments

Comments
 (0)