Answer the question
In order to leave comments, you need to log in
Symfony - how to read yaml File and get certain data?
Hello everyone, how can I read data from a yaml file?
according to the documentation, it works like this:
https://symfony.com/doc/current/components/yaml.html#reading-yaml-files
use Symfony\Component\Yaml\Yaml;
$value = Yaml::parseFile('/path/to/file.yaml');
profileData:
Fields:
- { property: 'name', label: 'name', type: 'string' }
- { property: 'firstname', label: 'firstname', type: 'string' }
- { property: 'street', label: 'street' }
Answer the question
In order to leave comments, you need to log in
$yaml = Yaml::parse('/path/to/file.yaml');
$data = array_map(function ($field) {
$item = [];
if (isset($field['label'])) {
$item['label'] = $field['label'];
}
if (isset($field['type'])) {
$item['type'] = $field['type'];
}
return $item;
}, $yaml['profileData']['Fields']);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question