Reader.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * File-based configuration reader. Multiple configuration directories can be
  4. * used by attaching multiple instances of this class to [Kohana_Config].
  5. *
  6. * @package Kohana
  7. * @category Configuration
  8. * @author Kohana Team
  9. * @copyright (c) Kohana Team
  10. * @license https://koseven.ga/LICENSE.md
  11. */
  12. class Kohana_Config_File_Reader implements Kohana_Config_Reader {
  13. /**
  14. * The directory where config files are located
  15. * @var string
  16. */
  17. protected $_directory = '';
  18. /**
  19. * Creates a new file reader using the given directory as a config source
  20. *
  21. * @param string $directory Configuration directory to search
  22. */
  23. public function __construct($directory = 'config')
  24. {
  25. // Set the configuration directory name
  26. $this->_directory = trim($directory, '/');
  27. }
  28. /**
  29. * Load and merge all of the configuration files in this group.
  30. *
  31. * $config->load($name);
  32. *
  33. * @param string $group configuration group name
  34. * @return $this current object
  35. * @uses Kohana::load
  36. */
  37. public function load($group)
  38. {
  39. $config = [];
  40. if ($files = Kohana::find_file($this->_directory, $group, NULL, TRUE))
  41. {
  42. foreach ($files as $file)
  43. {
  44. // Merge each file to the configuration array
  45. $config = Arr::merge($config, Kohana::load($file));
  46. }
  47. }
  48. return $config;
  49. }
  50. }