Skip to content

Commit

Permalink
Fix: properly deal with default value
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Oct 29, 2024
1 parent 75eb9da commit d1506a5
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions src/XML/ecp/RequestAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ final class RequestAuthenticated extends AbstractEcpElement
/**
* Create a ECP RequestAuthenticated element.
*
* @param bool $mustUnderstand
* @param bool|null $mustUnderstand
*/
public function __construct(
protected bool $mustUnderstand,
protected ?bool $mustUnderstand = false,
) {
}


/**
* Collect the value of the mustUnderstand-property
*
* @return bool
* @return bool|null
*/
public function getMustUnderstand(): bool
public function getMustUnderstand(): ?bool
{
return $this->mustUnderstand;
}
Expand Down Expand Up @@ -66,23 +66,29 @@ public static function fromXML(DOMElement $xml): static
MissingAttributeException::class,
);

$mustUnderstand = $xml->getAttributeNS(C::NS_SOAP_ENV_11, 'mustUnderstand');
$actor = $xml->getAttributeNS(C::NS_SOAP_ENV_11, 'actor');
$mustUnderstand = null;
if ($xml->hasAttributeNS(C::NS_SOAP_ENV_11, 'mustUnderstand')) {
$mustUnderstand = $xml->getAttributeNS(C::NS_SOAP_ENV_11, 'mustUnderstand');

Assert::oneOf(
$mustUnderstand,
['0', '1'],
'Invalid value of env:mustUnderstand attribute in <ecp:RequestAuthenticated>.',
ProtocolViolationException::class,
);
Assert::nullOrOneOf(
$mustUnderstand,
['0', '1'],
'Invalid value of env:mustUnderstand attribute in <ecp:RequestAuthenticated>.',
ProtocolViolationException::class,
);

$mustUnderstand = boolval($mustUnderstand);
}

$actor = $xml->getAttributeNS(C::NS_SOAP_ENV_11, 'actor');
Assert::same(
$actor,
'http://schemas.xmlsoap.org/soap/actor/next',
'Invalid value of env:actor attribute in <ecp:RequestAuthenticated>.',
ProtocolViolationException::class,
);

return new static(boolval($mustUnderstand));
return new static($mustUnderstand);
}


Expand All @@ -95,7 +101,11 @@ public static function fromXML(DOMElement $xml): static
public function toXML(DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);
$e->setAttributeNS(C::NS_SOAP_ENV_11, 'env:mustUnderstand', strval(intval($this->getMustUnderstand())));

if ($this->getMustUnderstand() !== null) {
$e->setAttributeNS(C::NS_SOAP_ENV_11, 'env:mustUnderstand', strval(intval($this->getMustUnderstand())));
}

$e->setAttributeNS(C::NS_SOAP_ENV_11, 'env:actor', C::SOAP_ACTOR_NEXT);

return $e;
Expand Down

0 comments on commit d1506a5

Please sign in to comment.