CompiledLanguages.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * @package Grav\Common\Config
  4. *
  5. * @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
  6. * @license MIT License; see LICENSE file for details.
  7. */
  8. namespace Grav\Common\Config;
  9. use Grav\Common\File\CompiledYamlFile;
  10. class CompiledLanguages extends CompiledBase
  11. {
  12. public function __construct($cacheFolder, array $files, $path)
  13. {
  14. parent::__construct($cacheFolder, $files, $path);
  15. $this->version = 1;
  16. }
  17. /**
  18. * Create configuration object.
  19. *
  20. * @param array $data
  21. */
  22. protected function createObject(array $data = [])
  23. {
  24. $this->object = new Languages($data);
  25. }
  26. /**
  27. * Finalize configuration object.
  28. */
  29. protected function finalizeObject()
  30. {
  31. $this->object->checksum($this->checksum());
  32. $this->object->timestamp($this->timestamp());
  33. }
  34. /**
  35. * Function gets called when cached configuration is saved.
  36. */
  37. public function modified()
  38. {
  39. $this->object->modified(true);
  40. }
  41. /**
  42. * Load single configuration file and append it to the correct position.
  43. *
  44. * @param string $name Name of the position.
  45. * @param string $filename File to be loaded.
  46. */
  47. protected function loadFile($name, $filename)
  48. {
  49. $file = CompiledYamlFile::instance($filename);
  50. if (preg_match('|languages\.yaml$|', $filename)) {
  51. $this->object->mergeRecursive((array) $file->content());
  52. } else {
  53. $this->object->mergeRecursive([$name => $file->content()]);
  54. }
  55. $file->free();
  56. }
  57. }