start developing quiz challenge thingamabob site.

This commit is contained in:
Krzysztof Płaczek
2024-10-22 12:41:20 +02:00
parent 279a398467
commit a7dc813513
21 changed files with 1410 additions and 6 deletions

View File

@@ -0,0 +1,31 @@
<?php
namespace App\Service;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Yaml\Yaml;
class QuestionsService
{
public function __construct(private array $paths = [])
{
}
public function getQuestions(): array
{
$questions = [];
foreach ($this->getQuestionFiles() as $file) {
$yamlFile = Yaml::parseFile($file->getRealPath());
$questions = array_merge($questions, $yamlFile['questions']);
}
return $questions;
}
private function getQuestionFiles(): array
{
$finder = new Finder();
return iterator_to_array($finder->files()->in($this->paths)->name('*.yaml'));
}
}