<?php
namespace App\Export\Builder;
use App\V4\Dev\Exporter\TraceableExporter;
use RuntimeException;
class ExportBuilder implements ExportBuilderInterface
{
/**
* @var ExporterInterface[]
*/
private $exporters;
/**
* @param ExporterInterface[] $exporters
*/
public function __construct(iterable $exporters)
{
$this->exporters = $exporters;
}
/**
* {@inheritdoc}
*/
public function getExporter($entity, string $field, string $exportType): ExporterInterface
{
foreach ($this->exporters as $exporter) {
if ($exporter instanceof TraceableExporter) {
continue;
}
if ($exporter->supports($entity, $field, $exportType)) {
return $exporter;
}
}
throw new RuntimeException(sprintf('Builder for field %s not found', $field));
}
}