Working on export decoration

This commit is contained in:
David Bomba 2023-11-25 12:45:17 +11:00
parent 6d36f57d35
commit c35716f26e
4 changed files with 19 additions and 3 deletions

View File

@ -117,6 +117,8 @@ class PaymentExport extends BaseExport
} elseif (array_key_exists($key, $transformed_entity)) {
$entity[$key] = $transformed_entity[$key];
} else {
// $entity[$key] = $this->decorator->transform($key, $payment);
$entity[$key] = $this->resolveKey($key, $payment, $this->entity_transformer);
}

View File

@ -34,7 +34,7 @@ class Decorator implements DecoratorInterface{
{
}
public function transform(): string
public function transform(string $key, mixed $entity): string
{
return 'Decorator';
}
@ -110,4 +110,11 @@ class Decorator implements DecoratorInterface{
{
return $this->entity;
}
public function getKeyPart(int $index, string $key): string
{
$parts = explode('.', $key ?? '');
return $parts[$index];
}
}

View File

@ -12,5 +12,5 @@
namespace App\Export\Decorators;
interface DecoratorInterface {
public function transform(): string;
public function transform(string $key, mixed $entity): string;
}

View File

@ -15,9 +15,16 @@ use App\Models\Payment;
class PaymentDecorator extends Decorator implements DecoratorInterface{
public function transform(): string
private $key = 'payment';
public function transform(string $key, $payment): string
{
$index = $this->getKeyPart(0,$key);
// match($index)
return 'Payment Decorator';
}
}