Languages.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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\Data\Data;
  10. use Grav\Common\Utils;
  11. /**
  12. * Class Languages
  13. * @package Grav\Common\Config
  14. */
  15. class Languages extends Data
  16. {
  17. /** @var string|null */
  18. protected $checksum;
  19. /** @var bool */
  20. protected $modified = false;
  21. /** @var int */
  22. protected $timestamp = 0;
  23. /**
  24. * @param string|null $checksum
  25. * @return string|null
  26. */
  27. public function checksum($checksum = null)
  28. {
  29. if ($checksum !== null) {
  30. $this->checksum = $checksum;
  31. }
  32. return $this->checksum;
  33. }
  34. /**
  35. * @param bool|null $modified
  36. * @return bool
  37. */
  38. public function modified($modified = null)
  39. {
  40. if ($modified !== null) {
  41. $this->modified = $modified;
  42. }
  43. return $this->modified;
  44. }
  45. /**
  46. * @param int|null $timestamp
  47. * @return int
  48. */
  49. public function timestamp($timestamp = null)
  50. {
  51. if ($timestamp !== null) {
  52. $this->timestamp = $timestamp;
  53. }
  54. return $this->timestamp;
  55. }
  56. /**
  57. * @return void
  58. */
  59. public function reformat()
  60. {
  61. if (isset($this->items['plugins'])) {
  62. $this->items = array_merge_recursive($this->items, $this->items['plugins']);
  63. unset($this->items['plugins']);
  64. }
  65. }
  66. /**
  67. * @param array $data
  68. * @return void
  69. */
  70. public function mergeRecursive(array $data)
  71. {
  72. $this->items = Utils::arrayMergeRecursiveUnique($this->items, $data);
  73. }
  74. /**
  75. * @param string $lang
  76. * @return array
  77. */
  78. public function flattenByLang($lang)
  79. {
  80. $language = $this->items[$lang];
  81. return Utils::arrayFlattenDotNotation($language);
  82. }
  83. /**
  84. * @param array $array
  85. * @return array
  86. */
  87. public function unflatten($array)
  88. {
  89. return Utils::arrayUnflattenDotNotation($array);
  90. }
  91. }