-
I am trying to use DTOs with the SoapClient. With the new \SoapClient($wsdl, ['classmap' => 'User' => \App\DTOs\User::class]); The XSD of my soap server defines a property namespace App\DTOs;
use Spatie\LaravelData\Data;
class User extends Data
{
public ?\Illuminate\Support\Carbon $birthdate = null;
} But when I try that, I get an exception when doing my soap request:
I tried solve this with a |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I foud a solution, no need for any magic with getters or setters. You can pass a <?php
namespace Bka\AbsClient\Utility;
use Illuminate\Support\Carbon;
class XmlTypemap
{
public static array $typemap = [
[
"type_ns" => "http://www.w3.org/2001/XMLSchema",
"type_name" => "dateTime",
"from_xml" => [self::class, 'fromXSDDateTime'],
"to_xml" => [self::class, 'toXSDDateTime']
]
];
public static function fromXSDDateTime(string $xml): \DateTimeInterface
{
$sxe = simplexml_load_string($xml);
return new Carbon((string) $sxe);
}
public static function toXSDDateTime(null|string|\DateTimeInterface $value): ?string
{
if (is_null($value)) {
return null;
}
if (!is_string($value)) {
$value = $value->format(\DateTimeInterface::ATOM);
}
return '<value>' . $value . '</value>';
}
} Notice the |
Beta Was this translation helpful? Give feedback.
I foud a solution, no need for any magic with getters or setters. You can pass a
typemap
to the SoapClient to definefrom
andto
methods to handle type conversion between PHP and XML: