25 lines
580 B
PHP
25 lines
580 B
PHP
<?php
|
|
|
|
namespace Encoder;
|
|
|
|
use Domain\Normalizer\Normalizer;
|
|
use InvalidArgumentException;
|
|
|
|
class EncoderFactory
|
|
{
|
|
public function __construct(
|
|
private Normalizer $normalizer
|
|
)
|
|
{
|
|
}
|
|
|
|
public function getEncoder(string $type): StringEncoder
|
|
{
|
|
return match ($type) {
|
|
'csv', 'CSV' => new CsvEncoder($this->normalizer, columnSeparator: ',', rowSeparator: "\n"),
|
|
'json', 'JSON' => new JsonEncoder($this->normalizer),
|
|
default => throw new InvalidArgumentException('Invalid encoder: ' . $type)
|
|
};
|
|
}
|
|
}
|