start developing quiz challenge thingamabob site.
This commit is contained in:
31
src/Service/QuestionsService.php
Normal file
31
src/Service/QuestionsService.php
Normal 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'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user