-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Soap\Encoding\Encoder\Fault; | ||
|
||
use RuntimeException; | ||
use Soap\Encoding\Encoder\Context; | ||
use Soap\Encoding\Encoder\XmlEncoder; | ||
use Soap\Encoding\Model\Soap11Fault; | ||
use VeeWee\Reflecta\Iso\Iso; | ||
|
||
/** | ||
* @implements XmlEncoder<Soap11Fault, string> | ||
*/ | ||
final class Soap11FaultEncoder implements XmlEncoder | ||
Check failure on line 15 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.3 @ ubuntu-latestUnusedClass
Check failure on line 15 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.1 @ ubuntu-latestUnusedClass
Check failure on line 15 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.2 @ ubuntu-latestUnusedClass
Check failure on line 15 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.1 @ ubuntu-latestUnusedClass
Check failure on line 15 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.3 @ ubuntu-latestUnusedClass
Check failure on line 15 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.2 @ ubuntu-latestUnusedClass
|
||
{ | ||
/** | ||
* @return Iso<Soap11Fault, string> | ||
*/ | ||
public function iso(Context $context): Iso | ||
{ | ||
return new Iso( | ||
static fn (Soap11Fault $fault): string => throw new RuntimeException('not implemented yet'), | ||
Check failure on line 23 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.3 @ ubuntu-latestUnusedClosureParam
Check failure on line 23 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.3 @ ubuntu-latestNoValue
Check failure on line 23 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.1 @ ubuntu-latestUnusedClosureParam
Check failure on line 23 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.1 @ ubuntu-latestNoValue
Check failure on line 23 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.2 @ ubuntu-latestUnusedClosureParam
Check failure on line 23 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.2 @ ubuntu-latestNoValue
Check failure on line 23 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.1 @ ubuntu-latestUnusedClosureParam
Check failure on line 23 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.1 @ ubuntu-latestNoValue
Check failure on line 23 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.3 @ ubuntu-latestUnusedClosureParam
Check failure on line 23 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.3 @ ubuntu-latestNoValue
Check failure on line 23 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.2 @ ubuntu-latestUnusedClosureParam
Check failure on line 23 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.2 @ ubuntu-latestNoValue
|
||
static fn (string $fault): Soap11Fault => throw new RuntimeException('not implemented yet') | ||
Check failure on line 24 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.3 @ ubuntu-latestUnusedClosureParam
Check failure on line 24 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.3 @ ubuntu-latestNoValue
Check failure on line 24 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.1 @ ubuntu-latestUnusedClosureParam
Check failure on line 24 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.1 @ ubuntu-latestNoValue
Check failure on line 24 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.2 @ ubuntu-latestUnusedClosureParam
Check failure on line 24 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.2 @ ubuntu-latestNoValue
Check failure on line 24 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.1 @ ubuntu-latestUnusedClosureParam
Check failure on line 24 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.1 @ ubuntu-latestNoValue
Check failure on line 24 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.3 @ ubuntu-latestUnusedClosureParam
Check failure on line 24 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.3 @ ubuntu-latestNoValue
Check failure on line 24 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.2 @ ubuntu-latestUnusedClosureParam
Check failure on line 24 in src/Encoder/Fault/Soap11FaultEncoder.php GitHub Actions / PHP 8.2 @ ubuntu-latestNoValue
|
||
); | ||
} | ||
} | ||
|
||
|
||
/* | ||
* | ||
* <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> | ||
<s:Body> | ||
<s:Fault> | ||
<faultcode xmlns:a="urn:microsoft-dynamics-schemas/error"> | ||
a:Microsoft.Dynamics.Nav.Service.WebServices.ServiceBrokerException | ||
</faultcode> | ||
<faultstring xml:lang="nl-BE">Parameter languagecode in method CategoryList in service DumpServices is | ||
null! | ||
</faultstring> | ||
<detail> | ||
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">Parameter languagecode in method | ||
CategoryList in service DumpServices is null! | ||
</string> | ||
</detail> | ||
</s:Fault> | ||
</s:Body> | ||
</s:Envelope> | ||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Soap\Encoding\Encoder\Fault; | ||
|
||
use Soap\Encoding\Encoder\Context; | ||
use Soap\Encoding\Encoder\XmlEncoder; | ||
use Soap\Encoding\Model\Soap12Fault; | ||
use VeeWee\Reflecta\Iso\Iso; | ||
use VeeWee\Xml\Dom\Document; | ||
use VeeWee\Xml\Writer\Writer; | ||
use function VeeWee\Xml\Dom\Xpath\Configurator\namespaces; | ||
use function VeeWee\Xml\Writer\Builder\children; | ||
use function VeeWee\Xml\Writer\Builder\namespaced_element; | ||
use function VeeWee\Xml\Writer\Builder\prefixed_element; | ||
use function VeeWee\Xml\Writer\Builder\raw; | ||
use function VeeWee\Xml\Writer\Builder\value; | ||
use function VeeWee\Xml\Writer\Mapper\memory_output; | ||
|
||
/** | ||
* @implements XmlEncoder<Soap12Fault, non-empty-string> | ||
*/ | ||
final class Soap12FaultEncoder implements XmlEncoder | ||
Check failure on line 23 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.3 @ ubuntu-latestUnusedClass
Check failure on line 23 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.1 @ ubuntu-latestUnusedClass
Check failure on line 23 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.2 @ ubuntu-latestUnusedClass
Check failure on line 23 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.1 @ ubuntu-latestUnusedClass
Check failure on line 23 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.3 @ ubuntu-latestUnusedClass
Check failure on line 23 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.2 @ ubuntu-latestUnusedClass
|
||
{ | ||
private const ENV_NAMESPACE = 'http://www.w3.org/2003/05/soap-envelope'; | ||
|
||
/** | ||
* @return Iso<Soap12Fault, non-empty-string> | ||
Check failure on line 28 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.3 @ ubuntu-latestMoreSpecificReturnType
Check failure on line 28 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.1 @ ubuntu-latestMoreSpecificReturnType
Check failure on line 28 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.2 @ ubuntu-latestMoreSpecificReturnType
Check failure on line 28 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.1 @ ubuntu-latestMoreSpecificReturnType
Check failure on line 28 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.3 @ ubuntu-latestMoreSpecificReturnType
Check failure on line 28 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.2 @ ubuntu-latestMoreSpecificReturnType
|
||
*/ | ||
public function iso(Context $context): Iso | ||
{ | ||
return new Iso( | ||
Check failure on line 32 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.3 @ ubuntu-latestArgumentTypeCoercion
Check failure on line 32 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.3 @ ubuntu-latestLessSpecificReturnStatement
Check failure on line 32 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.1 @ ubuntu-latestArgumentTypeCoercion
Check failure on line 32 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.1 @ ubuntu-latestLessSpecificReturnStatement
Check failure on line 32 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.2 @ ubuntu-latestArgumentTypeCoercion
Check failure on line 32 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.2 @ ubuntu-latestLessSpecificReturnStatement
Check failure on line 32 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.1 @ ubuntu-latestArgumentTypeCoercion
Check failure on line 32 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.1 @ ubuntu-latestLessSpecificReturnStatement
Check failure on line 32 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.3 @ ubuntu-latestArgumentTypeCoercion
Check failure on line 32 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.3 @ ubuntu-latestLessSpecificReturnStatement
Check failure on line 32 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.2 @ ubuntu-latestArgumentTypeCoercion
Check failure on line 32 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.2 @ ubuntu-latestLessSpecificReturnStatement
|
||
$this->to(...), | ||
$this->from(...) | ||
); | ||
} | ||
|
||
private function to(Soap12Fault $fault): string | ||
{ | ||
return Writer::inMemory() | ||
->write(children([ | ||
namespaced_element( | ||
self::ENV_NAMESPACE, | ||
'env', | ||
'Fault', | ||
children([ | ||
prefixed_element( | ||
'env', | ||
'Code', | ||
children([ | ||
prefixed_element( | ||
'env', | ||
'Value', | ||
value($fault->code) | ||
), | ||
...( | ||
$fault->subCode | ||
Check failure on line 57 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.3 @ ubuntu-latestRiskyTruthyFalsyComparison
Check failure on line 57 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.1 @ ubuntu-latestRiskyTruthyFalsyComparison
Check failure on line 57 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.2 @ ubuntu-latestRiskyTruthyFalsyComparison
Check failure on line 57 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.1 @ ubuntu-latestRiskyTruthyFalsyComparison
Check failure on line 57 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.3 @ ubuntu-latestRiskyTruthyFalsyComparison
Check failure on line 57 in src/Encoder/Fault/Soap12FaultEncoder.php GitHub Actions / PHP 8.2 @ ubuntu-latestRiskyTruthyFalsyComparison
|
||
? [ | ||
prefixed_element( | ||
'env', | ||
'Subcode', | ||
children([ | ||
prefixed_element( | ||
'env', | ||
'Value', | ||
value($fault->subCode) | ||
) | ||
]) | ||
) | ||
] | ||
: [] | ||
), | ||
|
||
]) | ||
), | ||
prefixed_element( | ||
'env', | ||
'Reason', | ||
children([ | ||
prefixed_element( | ||
'env', | ||
'Text', | ||
value($fault->reason) | ||
) | ||
]) | ||
), | ||
...( | ||
$fault->node | ||
? [ | ||
prefixed_element( | ||
'env', | ||
'Node', | ||
value($fault->node) | ||
) | ||
] | ||
: [] | ||
), | ||
...( | ||
$fault->role | ||
? [ | ||
prefixed_element( | ||
'env', | ||
'Role', | ||
value($fault->role) | ||
) | ||
] | ||
: [] | ||
), | ||
...($fault->detail ? [raw($fault->detail)] : []), | ||
]) | ||
) | ||
])) | ||
->map(memory_output()); | ||
} | ||
|
||
/** | ||
* @param non-empty-string $fault | ||
*/ | ||
private function from(string $fault): Soap12Fault | ||
{ | ||
$document = Document::fromXmlString($fault); | ||
$documentElement = $document->locateDocumentElement(); | ||
$xpath = $document->xpath(namespaces(['env' => $documentElement->namespaceURI])); | ||
|
||
$subCode = $xpath->query('//env:Code/env:Subcode/env:Value'); | ||
$node = $xpath->query('//env:Node'); | ||
$role = $xpath->query('//env:Role'); | ||
$detail = $xpath->query('//env:Detail'); | ||
|
||
return new Soap12Fault( | ||
code: $xpath->querySingle('//env:Code/env:Value')->textContent, | ||
reason: $xpath->querySingle('//env:Reason/env:Text')->textContent, | ||
subCode: $subCode->count() ? $subCode->first()->textContent : null, | ||
node: $node->count() ? $node->first()->textContent : null, | ||
role: $role->count() ? $role->first()->textContent : null, | ||
detail: $detail->count() ? Document::fromXmlNode($detail->first())->stringifyDocumentElement() : null, | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Soap\Encoding\Exception; | ||
|
||
use Psl\Str; | ||
use RuntimeException; | ||
use Soap\Encoding\Model\SoapFault; | ||
|
||
final class SoapFaultException extends RuntimeException implements ExceptionInterface | ||
{ | ||
public function __construct( | ||
private readonly SoapFault $fault | ||
) { | ||
parent::__construct( | ||
Str\format( | ||
'A SOAP Fault got triggered: %s (Code: %s)', | ||
$this->fault->reason(), | ||
$this->fault->code(), | ||
), | ||
); | ||
} | ||
|
||
public function fault(): SoapFault | ||
{ | ||
return $this->fault; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Soap\Encoding\Model; | ||
|
||
/** | ||
* @see https://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383507 | ||
*/ | ||
final class Soap11Fault implements SoapFault | ||
{ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Soap\Encoding\Model; | ||
|
||
/** | ||
* https://www.w3.org/TR/soap12-part1/#soapfault | ||
* | ||
* A mandatory Code element information item (see 5.4.1 SOAP Code Element). | ||
* A mandatory Reason element information item (see 5.4.2 SOAP Reason Element). | ||
* An optional Node element information item (see 5.4.3 SOAP Node Element). | ||
* An optional Role element information item (see 5.4.4 SOAP Role Element). | ||
* An optional Detail element information item (see 5.4.5 SOAP Detail Element). | ||
*/ | ||
final class Soap12Fault implements SoapFault | ||
{ | ||
public function __construct( | ||
public readonly string $code, | ||
public readonly string $reason, | ||
public readonly ?string $subCode = null, | ||
public readonly ?string $node = null, | ||
public readonly ?string $role = null, | ||
public readonly ?string $detail = null | ||
) { | ||
} | ||
|
||
public function code(): string | ||
{ | ||
return $this->code; | ||
} | ||
|
||
public function reason(): string | ||
{ | ||
return $this->reason; | ||
} | ||
|
||
public function detail(): ?string | ||
{ | ||
return $this->detail; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Soap\Encoding\Model; | ||
|
||
interface SoapFault | ||
{ | ||
public function code(): string; | ||
|
||
public function reason(): string; | ||
|
||
public function detail(): ?string; | ||
} |