2 declare(strict_types = 1);
20 use Symfony\Component\Yaml\Exception\ParseException;
21 use Symfony\Component\Yaml\Yaml;
63 public function load(array $filesToLoad): array
66 foreach ($filesToLoad as $fileToLoad) {
67 if ($fileToLoad instanceof
File) {
68 $fileIdentifier = $fileToLoad->getIdentifier();
69 $rawYamlContent = $fileToLoad->getContents();
70 if ($rawYamlContent ===
false) {
72 'The file "' . $fileIdentifier .
'" does not exist.',
77 $fileIdentifier = $fileToLoad;
78 $fileToLoad = GeneralUtility::getFileAbsFileName($fileToLoad);
79 if (is_file($fileToLoad)) {
80 $rawYamlContent = file_get_contents($fileToLoad);
83 'The file "' . $fileToLoad .
'" does not exist.',
90 $loadedConfiguration = Yaml::parse($rawYamlContent);
92 if (is_array($loadedConfiguration)) {
93 $configuration = array_replace_recursive($configuration, $loadedConfiguration);
95 }
catch (ParseException $exception) {
97 'An error occurred while parsing file "' . $fileIdentifier .
'": ' . $exception->getMessage(),
104 return $configuration;
116 public function save($fileToSave, array $configuration)
124 $yaml = Yaml::dump($configuration, 99, 2);
126 if ($fileToSave instanceof
File) {
128 $this->filePersistenceSlot->allowInvocation(
131 $fileToSave->getParentFolder(),
132 $fileToSave->getName()
134 $this->filePersistenceSlot->getContentSignature(
138 $fileToSave->setContents($header . LF . $yaml);
143 $byteCount = @file_put_contents($fileToSave, $header . LF . $yaml);
145 if ($byteCount ===
false) {
146 $error = error_get_last();
164 if ($file instanceof
File) {
165 $fileLines = explode(LF, $file->getContents());
166 } elseif (is_file($file)) {
167 $fileLines = file($file);
172 foreach ($fileLines as $line) {
173 if (preg_match(
'/^#/', $line)) {