Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

45 řádky
991B

  1. <?php
  2. namespace Framework\Support;
  3. use Framework\App;
  4. class Config
  5. {
  6. private array $loaded = [];
  7. public function get(string $key, mixed $default = null): mixed
  8. {
  9. $segments = explode('.', $key);
  10. $file = array_shift($segments);
  11. if (!isset($this->loaded[$file])) {
  12. $base = App::getInstance()->resolve('paths.base');
  13. $separator = DIRECTORY_SEPARATOR;
  14. $this->loaded[$file] = (array) require "{$base}{$separator}config{$separator}{$file}.php";
  15. }
  16. if ($value = $this->withDots($this->loaded[$file], $segments)) {
  17. return $value;
  18. }
  19. return $default;
  20. }
  21. private function withDots(array $array, array $segments): mixed
  22. {
  23. $current = $array;
  24. foreach ($segments as $segment) {
  25. if (!isset($current[$segment])) {
  26. return null;
  27. }
  28. $current = $current[$segment];
  29. }
  30. return $current;
  31. }
  32. }

Powered by TurnKey Linux.