Skip to content

Commit c6b7057

Browse files
authored
Migrate DOM-classes to PHP 8.4's new DOM-API (#415)
* Migrate DOM-classes to PHP 8.4's new DOM-API * Migrate DOM-classes to PHP 8.4's new DOM-API * Migrate DOM-classes to PHP 8.4's new DOM-API * Fix syntax * Fix unit tests * Fix unit tests
1 parent e4a7c00 commit c6b7057

286 files changed

Lines changed: 1321 additions & 1107 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
"psr/http-message": "~2.0",
3232
"psr/log": "~3.0",
3333
"simplesamlphp/assert": "~2.0",
34-
"simplesamlphp/xml-common": "~2.8",
35-
"simplesamlphp/xml-security": "~2.3",
36-
"simplesamlphp/xml-soap": "~2.3"
34+
"simplesamlphp/xml-common": "dev-feature/dom-migration-php84",
35+
"simplesamlphp/xml-security": "dev-feature/dom-migration-php84",
36+
"simplesamlphp/xml-soap": "dev-feature/dom-migration-php84"
3737
},
3838
"require-dev": {
3939
"ext-intl": "*",

phpstan-baseline-dev.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ parameters:
3030
count: 1
3131
path: tests/SAML2/Assertion/Validation/AssertionValidatorTest.php
3232

33-
-
34-
message: '#^Parameter \#1 \$xml of static method SimpleSAML\\SAML2\\XML\\saml\\Assertion\:\:fromXML\(\) expects DOMElement, DOMNode\|null given\.$#'
35-
identifier: argument.type
36-
count: 2
37-
path: tests/SAML2/Assertion/Validation/AssertionValidatorTest.php
38-
3933
-
4034
message: '#^Result of method SimpleSAML\\SAML2\\Assertion\\Processor\:\:validateAssertion\(\) \(void\) is used\.$#'
4135
identifier: method.void

src/Binding/HTTPArtifact.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ public function getRedirectURL(AbstractMessage $message): string
8484
"\x00\x04\x00\x00" . sha1($issuer->getContent()->getValue(), true) . $generatedId,
8585
);
8686
$artifactData = $message->toXML();
87-
$artifactDataString = $artifactData->ownerDocument?->saveXML($artifactData);
87+
/** @var \Dom\XMLDocument $ownerDocument */
88+
$ownerDocument = $artifactData->ownerDocument;
89+
$artifactDataString = $ownerDocument->saveXML($artifactData);
8890

8991
$clock = Utils::getContainer()->getClock();
9092
$store->set('artifact', $artifact, $artifactDataString, $clock->now()->add(new DateInterval('PT15M')));

src/Binding/HTTPPost.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ public function send(AbstractMessage $message): ResponseInterface
5353
$msgStr = $message->toXML();
5454

5555
Utils::getContainer()->debugMessage($msgStr, 'out');
56-
$msgStr = $msgStr->ownerDocument?->saveXML($msgStr);
56+
/** @var \Dom\XMLDocument $ownerDocument */
57+
$ownerDocument = $msgStr->ownerDocument;
58+
$msgStr = $ownerDocument?->saveXML($msgStr);
5759

5860
$msgStr = base64_encode($msgStr);
5961

src/Binding/HTTPRedirect.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ public function getRedirectURL(AbstractMessage $message): string
6666
$msgStr = $message->toXML();
6767

6868
Utils::getContainer()->debugMessage($msgStr, 'out');
69-
$msgStr = $msgStr->ownerDocument?->saveXML($msgStr);
69+
/** @var \Dom\XMLDocument $ownerDocument */
70+
$ownerDocument = $msgStr->ownerDocument;
71+
$msgStr = $ownerDocument->saveXML($msgStr);
7072

7173
$msgStr = gzdeflate($msgStr);
7274
$msgStr = base64_encode($msgStr);

src/Binding/SOAP.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ public function getOutputToSend(AbstractMessage $message): string|false
6363
new Body([$message]),
6464
$header,
6565
);
66-
return $env->toXML()->ownerDocument?->saveXML();
66+
/** @var \Dom\XMLDocument $ownerDocument */
67+
$ownerDocument = $env->toXML()->ownerDocument;
68+
return $ownerDocument->saveXML();
6769
}
6870

6971

@@ -99,12 +101,12 @@ public function receive(/** @scrutinizer ignore-unused */ServerRequestInterface
99101
}
100102

101103
$document = DOMDocumentFactory::fromString($postText);
102-
/** @var \DOMNode $xml */
104+
/** @var \Dom\Node $xml */
103105
$xml = $document->firstChild;
104106
Utils::getContainer()->debugMessage($document->documentElement, 'in');
105107

106108
$xpCache = XPath::getXPath($document->documentElement);
107-
/** @var \DOMElement[] $results */
109+
/** @var \Dom\Element[] $results */
108110
$results = XPath::xpQuery($xml, '/SOAP-ENV:Envelope/SOAP-ENV:Body/*[1]', $xpCache);
109111

110112
return MessageFactory::fromXML($results[0]);

src/Compat/AbstractContainer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ abstract public function getLogger(): LoggerInterface;
142142
* - **encrypt** XML that is about to be encrypted
143143
* - **decrypt** XML that was just decrypted
144144
*
145-
* @param \DOMElement|string $message
145+
* @param \Dom\Element|string $message
146146
*/
147147
abstract public function debugMessage($message, string $type): void;
148148

src/Compat/MockContainer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function getLogger(): LoggerInterface
4545
* - **encrypt** XML that is about to be encrypted
4646
* - **decrypt** XML that was just decrypted
4747
*
48-
* @param \DOMElement|string $message
48+
* @param \Dom\Element|string $message
4949
*/
5050
public function debugMessage($message, string $type): void
5151
{

src/SOAPClient.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ public function send(
147147

148148
// Add soap-envelopes
149149
$env = (new Envelope(new Body([new Chunk($msg->toXML())])))->toXML();
150-
$request = $env->ownerDocument?->saveXML();
150+
/** @var \Dom\XMLDocument $ownerDocument */
151+
$ownerDocument = $env->ownerDocument;
152+
$request = $ownerDocument->saveXML();
151153

152154
$container->debugMessage($request, 'out');
153155

@@ -163,7 +165,9 @@ public function send(
163165

164166
$dom = DOMDocumentFactory::fromString($soapresponsexml);
165167
$env = Envelope::fromXML($dom->documentElement);
166-
$container->debugMessage($env->toXML()->ownerDocument?->saveXML(), 'in');
168+
/** @var \Dom\XMLDocument $ownerDocument */
169+
$ownerDocument = $env->toXML()->ownerDocument;
170+
$container->debugMessage($ownerDocument->saveXML(), 'in');
167171

168172
$soapfault = $this->getSOAPFault($dom);
169173
if ($soapfault !== null) {

src/Utils/XPath.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
namespace SimpleSAML\SAML2\Utils;
66

7-
use DOMNode;
8-
use DOMXPath;
7+
use Dom;
98
use SimpleSAML\SAML2\Constants as C;
109

1110
/**
@@ -16,15 +15,15 @@
1615
class XPath extends \SimpleSAML\XMLSecurity\Utils\XPath
1716
{
1817
/**
19-
* Get a DOMXPath object that can be used to search for SAML elements.
18+
* Get a Dom\XPath object that can be used to search for SAML elements.
2019
*
21-
* @param \DOMNode $node The document to associate to the DOMXPath object.
20+
* @param \Dom\Node $node The document to associate to the Dom\XPath object.
2221
* @param bool $autoregister Whether to auto-register all namespaces used in the document
2322
*
24-
* @return \DOMXPath A DOMXPath object ready to use in the given document, with several
23+
* @return \Dom\XPath A Dom\XPath object ready to use in the given document, with several
2524
* saml-related namespaces already registered.
2625
*/
27-
public static function getXPath(DOMNode $node, bool $autoregister = false): DOMXPath
26+
public static function getXPath(Dom\Node $node, bool $autoregister = false): Dom\XPath
2827
{
2928
$xp = parent::getXPath($node, $autoregister);
3029

0 commit comments

Comments
 (0)