Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/analyzers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: [ '8.3', '8.4', '8.5' ]
php-versions: [ '8.4', '8.5' ]
composer-options: [ '--ignore-platform-req=php+' ]
fail-fast: false
name: PHP ${{ matrix.php-versions }} @ ${{ matrix.operating-system }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/code-style.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: [ '8.3', '8.4', '8.5' ]
php-versions: [ '8.4', '8.5' ]
composer-options: [ '--ignore-platform-req=php+' ]
fail-fast: false
name: PHP ${{ matrix.php-versions }} @ ${{ matrix.operating-system }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: [ '8.3', '8.4', '8.5' ]
php-versions: [ '8.4', '8.5' ]
composer-options: [ '--ignore-platform-req=php+' ]
dependency-preference: ['current', 'lowest', 'stable']
fail-fast: false
Expand Down
29 changes: 20 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,34 @@
}
],
"require": {
"php": "~8.3.0 || ~8.4.0 || ~8.5.0",
"php-standard-library/php-standard-library": "^3.0 || ^4.0 || ^5.0 || ^6.0",
"php": "~8.4.0 || ~8.5.0",
"php-standard-library/collection": "^6.1",
"php-standard-library/dict": "^6.1",
"php-standard-library/encoding": "^6.1",
"php-standard-library/foundation": "^6.1",
"php-standard-library/fun": "^6.1",
"php-standard-library/iter": "^6.1",
"php-standard-library/option": "^6.1",
"php-standard-library/regex": "^6.1",
"php-standard-library/result": "^6.1",
"php-standard-library/str": "^6.1",
"php-standard-library/type": "^6.1",
"php-standard-library/vec": "^6.1",
"veewee/reflecta": "~0.16",
"veewee/xml": "^3.6",
"php-soap/engine": "^2.19",
"php-soap/wsdl": "^1.18",
"php-soap/xml": "^1.9",
"php-soap/wsdl-reader": "^0.31"
"veewee/xml": "^4.10",
"php-soap/engine": "^2.20",
"php-soap/wsdl": "^1.19",
"php-soap/xml": "^1.10",
"php-soap/wsdl-reader": "^0.32"
},
"require-dev": {
"vimeo/psalm": "~6.13",
"phpunit/phpunit": "~12.4",
"php-cs-fixer/shim": "~3.88",
"symfony/var-dumper": "^7.0 || ^6.4",
"php-standard-library/psalm-plugin": "^2.3",
"php-soap/engine-integration-tests": "^1.10",
"php-soap/psr18-transport": "^1.8",
"php-soap/engine-integration-tests": "^1.12",
"php-soap/psr18-transport": "^2.0",
"guzzlehttp/guzzle": "^7.8",
"phpbench/phpbench": "^1.6"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/encoders/simpleType/anyXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function iso(Context $context): Iso
$targetElementName = $context->type->getXmlTargetNodeName();
return new Iso(
to: static fn (array $data): string => document_encode([$targetElementName => $data])
->manipulate(static fn (\DOMDocument $document) => $document->documentElement->setAttributeNS(
->manipulate(static fn (\Dom\XMLDocument $document) => $document->documentElement->setAttributeNS(
VeeWee\Xml\Xmlns\Xmlns::xsi()->value(),
'xsi:type',
'custom:type'
Expand Down
4 changes: 4 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
findUnusedBaselineEntry="true"
findUnusedCode="false"
ensureOverrideAttribute="false"
phpVersion="8.4"
>
<projectFiles>
<directory name="src"/>
<ignoreFiles>
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>
<stubs>
<file name="vendor/veewee/xml/stubs/DOM.phpstub"/>
</stubs>
<plugins>
<pluginClass class="Psl\Psalm\Plugin"/>
<pluginClass class="VeeWee\Reflecta\Psalm\Plugin"/>
Expand Down
4 changes: 2 additions & 2 deletions src/Encoder/SoapEnc/ApacheMapEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Soap\Encoding\Encoder\SoapEnc;

use Closure;
use DOMElement;
use Dom\Element as DomElement;
use Soap\Encoding\Encoder\Context;
use Soap\Encoding\Encoder\SimpleType\ScalarTypeEncoder;
use Soap\Encoding\Encoder\XmlEncoder;
Expand Down Expand Up @@ -84,7 +84,7 @@ private function decodeArray(Context $context, Element $value): array
$xpath = $value->document()->xpath();

return readChildren($element)->reduce(
static function (array $map, DOMElement $item) use ($context, $xpath): array {
static function (array $map, DomElement $item) use ($context, $xpath): array {
$key = $xpath->evaluate('string(./key)', string(), $item);
/** @psalm-var mixed $value */
$value = ElementValueReader::forEncoder(
Expand Down
4 changes: 2 additions & 2 deletions src/Encoder/SoapEnc/SoapArrayEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Soap\Encoding\Encoder\SoapEnc;

use Closure;
use DOMElement;
use Dom\Element as DomElement;
use Soap\Encoding\Encoder\Context;
use Soap\Encoding\Encoder\Feature\ListAware;
use Soap\Encoding\Encoder\XmlEncoder;
Expand Down Expand Up @@ -100,7 +100,7 @@ private function decodeArray(Context $context, SoapArrayAccess $arrayAccess, Ele
* @param list<mixed> $list
* @return list<mixed>
*/
static function (array $list, DOMElement $item) use ($iso): array {
static function (array $list, DomElement $item) use ($iso): array {
/** @var mixed $value */
$value = $iso->from(Element::fromDOMElement($item));

Expand Down
6 changes: 3 additions & 3 deletions src/Encoder/SoapEnc/SoapObjectEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Soap\Encoding\Encoder\SoapEnc;

use Closure;
use DOMElement;
use Dom\Element as DomElement;
use Soap\Encoding\Encoder\Context;
use Soap\Encoding\Encoder\SimpleType\ScalarTypeEncoder;
use Soap\Encoding\Encoder\XmlEncoder;
Expand Down Expand Up @@ -75,8 +75,8 @@ private function decodeArray(Context $context, Element $value): object
$element = $value->element();

return (object) readChildren($element)->reduce(
static function (array $map, DOMElement $item) use ($context): array {
$key = $item->localName ?? 'unkown';
static function (array $map, DomElement $item) use ($context): array {
$key = $item->localName;
/** @psalm-var mixed $value */
$value = ElementValueReader::forEncoder(
$context->withType(XsdType::any()),
Expand Down
6 changes: 3 additions & 3 deletions src/Fault/Encoder/Soap11FaultEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ private function from(string $fault): Soap11Fault
$detail = $xpath->query('./detail');

return new Soap11Fault(
faultCode: WhitespaceRestriction::collapse($xpath->querySingle('./faultcode')->textContent),
faultString: WhitespaceRestriction::collapse($xpath->querySingle('./faultstring')->textContent),
faultActor: $actor->count() ? trim($actor->expectFirst()->textContent) : null,
faultCode: WhitespaceRestriction::collapse($xpath->querySingle('./faultcode')->textContent ?? ''),
faultString: WhitespaceRestriction::collapse($xpath->querySingle('./faultstring')->textContent ?? ''),
faultActor: $actor->count() ? trim($actor->expectFirst()->textContent ?? '') : null,
detail: $detail->count() ? Document::fromXmlNode($detail->expectFirst())->stringifyDocumentElement() : null,
);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Fault/Encoder/Soap12FaultEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ private function from(string $fault): Soap12Fault
$detail = $xpath->query('./env:Detail');

return new Soap12Fault(
code: WhitespaceRestriction::collapse($xpath->querySingle('./env:Code/env:Value')->textContent),
reason: WhitespaceRestriction::collapse($xpath->querySingle('./env:Reason/env:Text')->textContent),
subCode: $subCode->count() ? WhitespaceRestriction::collapse($subCode->expectFirst()->textContent) : null,
node: $node->count() ? trim($node->expectFirst()->textContent) : null,
role: $role->count() ? trim($role->expectFirst()->textContent) : null,
code: WhitespaceRestriction::collapse($xpath->querySingle('./env:Code/env:Value')->textContent ?? ''),
reason: WhitespaceRestriction::collapse($xpath->querySingle('./env:Reason/env:Text')->textContent ?? ''),
subCode: $subCode->count() ? WhitespaceRestriction::collapse($subCode->expectFirst()->textContent ?? '') : null,
node: $node->count() ? trim($node->expectFirst()->textContent ?? '') : null,
role: $role->count() ? trim($role->expectFirst()->textContent ?? '') : null,
detail: $detail->count() ? Document::fromXmlNode($detail->expectFirst())->stringifyDocumentElement() : null,
);
}
Expand Down
10 changes: 5 additions & 5 deletions src/TypeInference/XsiTypeDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Soap\Encoding\TypeInference;

use DOMElement;
use Dom\Element;
use Psl\Option\Option;
use Soap\Encoding\Cache\ScopedCache;
use Soap\Encoding\Encoder\Context;
Expand Down Expand Up @@ -58,10 +58,10 @@ static function () use ($context, $value) {
/**
* @return Option<XsdType>
*/
public static function detectXsdTypeFromXmlElement(Context $context, DOMElement $element): Option
public static function detectXsdTypeFromXmlElement(Context $context, Element $element): Option
{
$xsiType = $element->getAttributeNS(Xmlns::xsi()->value(), 'type') ?: $element->getAttribute('xsi:type');
if (!$xsiType) {
$xsiType = $element->getAttributeNS(Xmlns::xsi()->value(), 'type') ?? $element->getAttribute('xsi:type');
if ($xsiType === null || $xsiType === '') {
return none();
}

Expand Down Expand Up @@ -91,7 +91,7 @@ public static function detectXsdTypeFromXmlElement(Context $context, DOMElement
/**
* @return Option<FixedIsoEncoder<mixed, string>>
*/
public static function detectEncoderFromXmlElement(Context $context, DOMElement $element): Option
public static function detectEncoderFromXmlElement(Context $context, Element $element): Option
{
$requestedXsiType = self::detectXsdTypeFromXmlElement($context, $element);
if (!$requestedXsiType->isSome()) {
Expand Down
11 changes: 6 additions & 5 deletions src/Xml/Node/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

namespace Soap\Encoding\Xml\Node;

use DOMElement;
use Dom\Element as DomElement;
use Stringable;
use VeeWee\Xml\Dom\Document;
use function Psl\invariant;
use function VeeWee\Xml\Dom\Assert\assert_document;

final class Element implements Stringable
{
private ?DOMElement $element = null;
private ?DomElement $element = null;
/**
* @var non-empty-string|null
*/
Expand All @@ -32,7 +33,7 @@ public static function fromString(string $xml): Element
return $new;
}

public static function fromDOMElement(DOMElement $element): self
public static function fromDOMElement(DomElement $element): self
{
$new = new self();
$new->element = $element;
Expand All @@ -41,7 +42,7 @@ public static function fromDOMElement(DOMElement $element): self
return $new;
}

public function element(): DOMElement
public function element(): DomElement
{
if (!$this->element) {
invariant($this->value !== null, 'Expected an XML value to be present');
Expand All @@ -66,7 +67,7 @@ public function value(): string

public function document(): Document
{
return Document::fromUnsafeDocument($this->element()->ownerDocument);
return Document::fromUnsafeDocument(assert_document($this->element()->ownerDocument));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Xml/Node/ElementList.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use Closure;
use Countable;
use DOMElement;
use Dom\Element as DomElement;
use Soap\Encoding\Xml\Reader\DocumentToLookupArrayReader;
use Stringable;
use VeeWee\Xml\Dom\Document;
Expand Down Expand Up @@ -69,7 +69,7 @@ public static function fromString(string $xml): self

return new self(
...readChildren($doc->locateDocumentElement())->map(
static fn (DOMElement $element): Element => Element::fromDOMElement($element)
static fn (DomElement $element): Element => Element::fromDOMElement($element)
)
);
}
Expand Down
14 changes: 7 additions & 7 deletions src/Xml/Reader/DocumentToLookupArrayReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

namespace Soap\Encoding\Xml\Reader;

use DOMAttr;
use DOMNode;
use Dom\Attr;
use Dom\Node;
use Soap\Encoding\Xml\Node\Element;
use Soap\Encoding\Xml\Node\ElementList;
use VeeWee\Xml\Xmlns\Xmlns;
Expand All @@ -28,14 +28,14 @@ public function __invoke(Element $xml): array
// Read all child elements.
// The key is the name of the elements
// The value is the raw XML for those element(s)
/** @var iterable<DOMNode> $children */
/** @var iterable<Node> $children */
$children = $root->childNodes;
foreach ($children as $element) {
if (!is_element($element)) {
continue;
}

$key = $element->localName ?? 'unknown';
$key = $element->localName;
$previousValue = $nodes[$key] ?? null;
$currentElement = Element::fromDOMElement($element);

Expand All @@ -53,14 +53,14 @@ public function __invoke(Element $xml): array
// It might be possible that the child is a regular textNode.
// In that case, we use '_' as the key and the value of the textNode as value.
if (!$nodes && $root->getAttributeNS(Xmlns::xsi()->value(), 'nil') !== 'true') {
$nodes['_'] = $root->textContent;
$nodes['_'] = $root->textContent ?? '';
}

// All attributes also need to be added as key => value pairs.
/** @var \iterable<DOMAttr> $attributes */
/** @var \iterable<Attr> $attributes */
$attributes = $root->attributes;
foreach ($attributes as $attribute) {
$key = $attribute->localName ?? 'unknown';
$key = $attribute->localName;
$nodes[$key] = $attribute->value;
}

Expand Down
8 changes: 4 additions & 4 deletions src/Xml/Reader/ElementValueReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Soap\Encoding\Xml\Reader;

use DOMElement;
use Dom\Element;
use Soap\Encoding\Encoder\Context;
use Soap\Encoding\Encoder\XmlEncoder;
use VeeWee\Reflecta\Iso\Iso;
Expand All @@ -19,7 +19,7 @@ final class ElementValueReader
public function __invoke(
Context $context,
XmlEncoder $encoder,
DOMElement $element
Element $element
): mixed {
return self::forEncoder($context, $encoder, $element);
}
Expand All @@ -28,7 +28,7 @@ public function __invoke(
* @param XmlEncoder<mixed, string> $encoder
* @psalm-return mixed
*/
public static function forEncoder(Context $context, XmlEncoder $encoder, DOMElement $element): mixed
public static function forEncoder(Context $context, XmlEncoder $encoder, Element $element): mixed
{
return $encoder->iso($context)->from(
readValue($element, string())
Expand All @@ -39,7 +39,7 @@ public static function forEncoder(Context $context, XmlEncoder $encoder, DOMElem
* @param Iso<mixed, string> $iso
* @psalm-return mixed
*/
public static function forIso(Iso $iso, DOMElement $element): mixed
public static function forIso(Iso $iso, Element $element): mixed
{
return $iso->from(
readValue($element, string())
Expand Down
3 changes: 1 addition & 2 deletions src/Xml/Reader/SoapEnvelopeReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Soap\Xml\Locator\SoapBodyLocator;
use VeeWee\Xml\Dom\Document;
use function VeeWee\Xml\Dom\Assert\assert_element;
use function VeeWee\Xml\Dom\Configurator\loader;
use function VeeWee\Xml\Dom\Loader\xml_string_loader;

final class SoapEnvelopeReader
Expand All @@ -19,7 +18,7 @@ final class SoapEnvelopeReader
*/
public function __invoke(string $xml, int $libXmlOptions = 0): Element
{
$envelope = Document::configure(loader(xml_string_loader($xml, $libXmlOptions)));
$envelope = Document::fromLoader(xml_string_loader($xml, $libXmlOptions));

// Make sure it does not contain a fault response before parsing the body parts.
(new SoapFaultGuard())($envelope);
Expand Down
Loading