Yml.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace ModulesGarden\Servers\ZimbraEmail\Core\FileReader\Reader;
  3. use Symfony\Component\Yaml\Yaml;
  4. use ModulesGarden\Servers\ZimbraEmail\Core\ServiceLocator;
  5. /**
  6. * Description of Yml
  7. *
  8. * @author Rafał Ossowski <rafal.os@modulesgarden.com>
  9. */
  10. class Yml extends AbstractType
  11. {
  12. protected function loadFile()
  13. {
  14. $return = [];
  15. try
  16. {
  17. if (file_exists($this->path . DS . $this->file))
  18. {
  19. $return = Yaml::parse(file_get_contents($this->path . DS . $this->file));
  20. $return = array_map(self::class . '::replaceBackslash', $return ? : []);
  21. }
  22. }
  23. catch (\Symfony\Component\Yaml\Exception\ParseException $e)
  24. {
  25. ServiceLocator::call('errorManager')->addError(self::class, $e->getMessage(), $e->getTrace());
  26. }
  27. $this->data = $return;
  28. }
  29. protected static function replaceBackslash($data)
  30. {
  31. if (is_array($data))
  32. {
  33. return array_map(self::class . '::replaceBackslash', $data);
  34. }
  35. else
  36. {
  37. return str_replace('\\\\', '\\', $data);
  38. }
  39. }
  40. }