Files
survey-bundle/src/QuestionType/QuestionTypeRegistry.php
T
2026-05-17 17:31:28 +02:00

46 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Mummert\SurveyBundle\QuestionType;
final class QuestionTypeRegistry
{
/**
* @var array<string, QuestionTypeInterface>
*/
private array $questionTypes = [];
public function __construct(iterable $questionTypes)
{
foreach ($questionTypes as $questionType) {
if (!$questionType instanceof QuestionTypeInterface) {
continue;
}
$this->questionTypes[$questionType->getName()] = $questionType;
}
}
public function get(string $type): QuestionTypeInterface
{
if (!isset($this->questionTypes[$type])) {
throw new \InvalidArgumentException(sprintf('Unbekannter Fragetyp "%s".', $type));
}
return $this->questionTypes[$type];
}
/**
* @return array<string, string>
*/
public function getChoices(): array
{
return [
'Ja-Nein-Frage' => 'yes_no_maybe',
'Offene Frage' => 'text',
'Bewertungsfrage' => 'range',
'Single/Multiple-Choice' => 'choice',
];
}
}