Reader.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Database reader for the kohana config system
  4. *
  5. * @package Kohana/Database
  6. * @category Configuration
  7. * @author Kohana Team
  8. * @copyright (c) Kohana Team
  9. * @license https://koseven.ga/LICENSE.md
  10. */
  11. class Kohana_Config_Database_Reader implements Kohana_Config_Reader
  12. {
  13. protected $_db_instance;
  14. protected $_table_name = 'config';
  15. /**
  16. * Constructs the database reader object
  17. *
  18. * @param array Configuration for the reader
  19. */
  20. public function __construct(array $config = NULL)
  21. {
  22. if (isset($config['instance']))
  23. {
  24. $this->_db_instance = $config['instance'];
  25. }
  26. elseif ($this->_db_instance === NULL)
  27. {
  28. $this->_db_instance = Database::$default;
  29. }
  30. if (isset($config['table_name']))
  31. {
  32. $this->_table_name = $config['table_name'];
  33. }
  34. }
  35. /**
  36. * Tries to load the specificed configuration group
  37. *
  38. * Returns FALSE if group does not exist or an array if it does
  39. *
  40. * @param string $group Configuration group
  41. * @return boolean|array
  42. */
  43. public function load($group)
  44. {
  45. /**
  46. * Prevents the catch-22 scenario where the database config reader attempts to load the
  47. * database connections details from the database.
  48. *
  49. * @link http://dev.kohanaframework.org/issues/4316
  50. */
  51. if ($group === 'database')
  52. return FALSE;
  53. $query = DB::select('config_key', 'config_value')
  54. ->from($this->_table_name)
  55. ->where('group_name', '=', $group)
  56. ->execute($this->_db_instance);
  57. return count($query) ? array_map('unserialize', $query->as_array('config_key', 'config_value')) : FALSE;
  58. }
  59. }