Certificationy\Certification\Loader::prepareFromYaml PHP Method

prepareFromYaml() protected static method

Prepares data from Yaml files and returns an array of questions
protected static prepareFromYaml ( array $categories = [], $path ) : array
$categories array : List of categories which should be included, empty array = all
return array
    protected static function prepareFromYaml(array $categories = array(), $path)
    {
        $data = array();
        self::$count = 0;
        $paths = Yaml::parse(file_get_contents($path))['paths'];
        foreach ($paths as $path) {
            $files = Finder::create()->files()->in($path)->name('*.yml');
            foreach ($files as $file) {
                $fileData = Yaml::parse($file->getContents());
                $category = $fileData['category'];
                if (count($categories) == 0 || in_array($category, $categories)) {
                    array_walk($fileData['questions'], function (&$item, $key) use($category) {
                        $item['category'] = $category;
                    });
                    $data = array_merge($data, $fileData['questions']);
                }
            }
        }
        self::$count = count($data);
        return $data;
    }