Repository navigation
Expand file tree
/
Copy pathEncoder.php
More file actions
45 lines (40 loc) · 1.54 KB
/
Copy pathEncoder.php
File metadata and controls
45 lines (40 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
declare(strict_types=1);
namespace Soap\Encoding;
use Soap\Encoding\Encoder\Method\MethodContext;
use Soap\Encoding\Encoder\Method\RequestEncoder;
use Soap\Engine\Encoder as SoapEncoder;
use Soap\Engine\HttpBinding\SoapRequest;
use Soap\Engine\Metadata\Metadata;
use Soap\WsdlReader\Model\Definitions\Namespaces;
use Soap\WsdlReader\Model\Definitions\SoapVersion;
use function Psl\Type\mixed_vec;
final class Encoder implements SoapEncoder
{
public function __construct(
private readonly Metadata $metadata,
private readonly Namespaces $namespaces,
private readonly EncoderRegistry $registry
) {
}
public function encode(string $method, array $arguments): SoapRequest
{
$methodInfo = $this->metadata->getMethods()->fetchByName($method);
$meta = $methodInfo->getMeta();
$methodContext = new MethodContext($methodInfo, $this->metadata, $this->registry, $this->namespaces);
$soapVersion = $meta->soapVersion()
->map(static fn ($version) => SoapVersion::from($version))
->unwrapOr(SoapVersion::SOAP_12);
$iso = (new RequestEncoder())->iso($methodContext);
return new SoapRequest(
$iso->to(mixed_vec()->assert($arguments)),
$meta->location()->unwrap(),
$meta->action()->unwrap(),
match($soapVersion) {
SoapVersion::SOAP_11 => SoapRequest::SOAP_1_1,
SoapVersion::SOAP_12 => SoapRequest::SOAP_1_2,
},
$meta->isOneWay()->unwrapOr(false)
);
}
}