formatter = $formatter; } /** * {@inheritdoc} * @see FileInterface::load() */ public function load() { $raw = parent::load(); try { return $raw !== false ? $this->formatter->decode($raw) : false; } catch (RuntimeException $e) { throw new RuntimeException(sprintf("Failed to load file '%s': %s", $this->getFilePath(), $e->getMessage()), $e->getCode(), $e); } } /** * {@inheritdoc} * @see FileInterface::save() */ public function save($data): void { if (\is_string($data)) { // Make sure that the string is valid data. try { $this->formatter->decode($data); } catch (RuntimeException $e) { throw new RuntimeException(sprintf("Failed to save file '%s': %s", $this->getFilePath(), $e->getMessage()), $e->getCode(), $e); } $encoded = $data; } else { $encoded = $this->formatter->encode($data); } parent::save($encoded); } }