Initial survey bundle import
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?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',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user