Replies: 2 comments
-
So I found a couple ways to do this: class XeroInvoiceDTO extends AbstractInvoiceDTO
{
public function __construct(
#[MapInputName('Contact')]
public $contact,
) {
$this->contact = XeroContactDTO::from($this->contact);
} Or class XeroInvoiceDTO extends AbstractInvoiceDTO
{
public function __construct(
#[MapInputName('Contact'), WithCast(FromDataCaster::class, class: XeroContactDTO::class)]
public $contact,
) {
} With the FromDataCaster looking like this (probably a better name for it!) class FromDataCaster implements Cast
{
protected $class;
public function __construct($class)
{
$this->class = $class;
}
public function cast(DataProperty $property, mixed $value, array $context): mixed
{
return $this->class::from($value);
}
} I am surprised that this kind of caster does not already exist within the package unless I have missed it. I looked through catsers and transformers and could not find something suitable. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I see this is not what this package is designed for. Closing as irrelevant in this context. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have the following abstract base classes:
These are extended into:
With this setup, the Contact data is passed through the AbstractContactDTO and therefore does not work. We need to be passing it through the XeroContactDTO but we are unable to overwrite the property type, with the error:
Are there any workarounds for this within the package?
Beta Was this translation helpful? Give feedback.
All reactions