CompiledLanguages.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * @package Grav\Common\Config
  4. *
  5. * @copyright Copyright (c) 2015 - 2022 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. /**
  11. * Class CompiledLanguages
  12. * @package Grav\Common\Config
  13. */
  14. class CompiledLanguages extends CompiledBase
  15. {
  16. /**
  17. * CompiledLanguages constructor.
  18. * @param string $cacheFolder
  19. * @param array $files
  20. * @param string $path
  21. */
  22. public function __construct($cacheFolder, array $files, $path)
  23. {
  24. parent::__construct($cacheFolder, $files, $path);
  25. $this->version = 1;
  26. }
  27. /**
  28. * Create configuration object.
  29. *
  30. * @param array $data
  31. * @return void
  32. */
  33. protected function createObject(array $data = [])
  34. {
  35. $this->object = new Languages($data);
  36. }
  37. /**
  38. * Finalize configuration object.
  39. *
  40. * @return void
  41. */
  42. protected function finalizeObject()
  43. {
  44. $this->object->checksum($this->checksum());
  45. $this->object->timestamp($this->timestamp());
  46. }
  47. /**
  48. * Function gets called when cached configuration is saved.
  49. *
  50. * @return void
  51. */
  52. public function modified()
  53. {
  54. $this->object->modified(true);
  55. }
  56. /**
  57. * Load single configuration file and append it to the correct position.
  58. *
  59. * @param string $name Name of the position.
  60. * @param string $filename File to be loaded.
  61. * @return void
  62. */
  63. protected function loadFile($name, $filename)
  64. {
  65. $file = CompiledYamlFile::instance($filename);
  66. if (preg_match('|languages\.yaml$|', $filename)) {
  67. $this->object->mergeRecursive((array) $file->content());
  68. } else {
  69. $this->object->mergeRecursive([$name => $file->content()]);
  70. }
  71. $file->free();
  72. }
  73. }