Anonymous 3D Imageboard http://cyberia.digital/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.3KB

  1. <?php
  2. namespace Lazer\Classes\Helpers;
  3. /**
  4. * Config managing class
  5. *
  6. * @category Helpers
  7. * @author Grzegorz Kuźnik
  8. * @copyright (c) 2013, Grzegorz Kuźnik
  9. * @license http://opensource.org/licenses/MIT The MIT License
  10. * @link https://github.com/Greg0/Lazer-Database GitHub Repository
  11. */
  12. class Config extends File {
  13. /**
  14. * Get key from returned config
  15. * @param string $field key
  16. * @param bool $assoc
  17. * @return mixed
  18. */
  19. public function getKey($field, $assoc = false)
  20. {
  21. return $assoc ? $this->get($assoc)[$field] : $this->get($assoc)->{$field};
  22. }
  23. public static function table($name)
  24. {
  25. $file = new Config;
  26. $file->name = $name;
  27. $file->setType('config');
  28. return $file;
  29. }
  30. /**
  31. * Return array with names of fields
  32. * @return array
  33. */
  34. public function fields()
  35. {
  36. return array_keys($this->getKey('schema', true));
  37. }
  38. /**
  39. * Return relations configure
  40. * @param mixed $tableName null-all tables;array-few tables;string-one table relation informations
  41. * @param boolean $assoc Object or associative array
  42. * @return array|object
  43. */
  44. public function relations($tableName = null, $assoc = false)
  45. {
  46. if (is_array($tableName))
  47. {
  48. $relations = $this->getKey('relations', $assoc);
  49. if ($assoc)
  50. {
  51. return array_intersect_key($relations, array_flip($tableName));
  52. }
  53. else
  54. {
  55. return (object) array_intersect_key((array) $relations, array_flip($tableName));
  56. }
  57. }
  58. elseif ($tableName !== null)
  59. {
  60. return $assoc ? $this->getKey('relations', $assoc)[$tableName] : $this->getKey('relations', $assoc)->{$tableName};
  61. }
  62. return $this->getKey('relations', $assoc);
  63. }
  64. /**
  65. * Returning assoc array with types of fields
  66. * @return array
  67. */
  68. public function schema()
  69. {
  70. return $this->getKey('schema', true);
  71. }
  72. /**
  73. * Returning last ID from table
  74. * @return integer
  75. */
  76. public function lastId()
  77. {
  78. return $this->getKey('last_id');
  79. }
  80. }