Skip to content

Migrate DOM-classes to PHP 8.4's new DOM-API#84

Open
tvdijen wants to merge 5 commits into
release-3.xfrom
feature/dom-migration-php84
Open

Migrate DOM-classes to PHP 8.4's new DOM-API#84
tvdijen wants to merge 5 commits into
release-3.xfrom
feature/dom-migration-php84

Conversation

@tvdijen
Copy link
Copy Markdown
Member

@tvdijen tvdijen commented May 31, 2026

Closes #85

@tvdijen tvdijen force-pushed the feature/dom-migration-php84 branch from 2d7bf7a to 4aa2b3d Compare May 31, 2026 15:58
@codecov
Copy link
Copy Markdown

codecov Bot commented May 31, 2026

Codecov Report

❌ Patch coverage is 95.52239% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.92%. Comparing base (d99f764) to head (bbcec53).

Additional details and impacted files
@@                Coverage Diff                @@
##             release-3.x      #84      +/-   ##
=================================================
- Coverage          92.93%   92.92%   -0.02%     
- Complexity           747      750       +3     
=================================================
  Files                125      125              
  Lines               2875     2884       +9     
=================================================
+ Hits                2672     2680       +8     
- Misses               203      204       +1     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tvdijen tvdijen requested a review from ioigoume May 31, 2026 16:25
Comment thread src/XML/ds/Signature.php

$this->getSignedInfo()->toXML($e);
$this->getSignatureValue()->toXML($e);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a little awkward, but just like the QName-issues in xml-wsdl I had to set the xmlns:ds namespace-attribute on the parent.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tvdijen in what sense it feels awkward? Because you mutate the parent in a method that is responsible for the signature? Two suggestions for this one either add the ns attribute to the parent the way you do it now, but i would propose this implementation:

    public function toXML(?Dom\Element $parent = null): Dom\Element
    {
        $e = $this->instantiateParentElement($parent);

        if ($parent !== null && $parent->lookupNamespaceURI('ds') !== C::NS_XDSIG) {
            $parent->setAttributeNS(C::NS_XMLNS, 'xmlns:ds', C::NS_XDSIG);
        }


        if ($this->getId() !== null) {
            $e->setAttribute('Id', strval($this->getId()));
        }

        $this->getSignedInfo()->toXML($e);
        $this->getSignatureValue()->toXML($e);

        $this->getKeyInfo()?->toXML($e);

        foreach ($this->getObjects() as $o) {
            $o->toXML($e);
        }

        return $e;
    }

or if you want to avoid mutating the parent then this should be like this:

 public function toXML(?Dom\Element $parent = null): Dom\Element
    {
        $e = $this->instantiateParentElement($parent);

        // Bind the ds prefix on this element (the Signature subtree root).
        $e->setAttributeNS(C::NS_XMLNS, 'xmlns:ds', C::NS_XDSIG);


        if ($this->getId() !== null) {
            $e->setAttribute('Id', strval($this->getId()));
        }

        $this->getSignedInfo()->toXML($e);
        $this->getSignatureValue()->toXML($e);

        $this->getKeyInfo()?->toXML($e);

        foreach ($this->getObjects() as $o) {
            $o->toXML($e);
        }

        return $e;
    }

then the fixtures need to change. I think for SAML2 xsd both ns attribute placements are correct.

if ($nsnode->localName != "xml") {
$arXPath['namespaces'][$nsnode->localName] = $nsnode->nodeValue;
if ($nsnode instanceof Dom\Element) {
if ($nsnode->localName !== "xml") {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI complained about localName not existing on Dom\Node, so I added the check for Dom\Element

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1
Perhaps we could consider:

if ($nsnode instanceof Dom\Attr || $nsnode instanceof Dom\Element) {

since DOMXPath namespace::* can return nodes that CI/PHPStan types as Dom\Node (often Dom\Attr)

Comment thread tests/XML/SignableElementTest.php
Comment thread tests/XML/SignableElementTest.php
Comment thread tests/XML/SignableElementTest.php
Copy link
Copy Markdown

@ioigoume ioigoume left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR looks good. I’ve added a few comments for consideration and an additional PR with a test fix and a composer improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants