DolConfigCollector.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. use \DebugBar\DataCollector\ConfigCollector;
  3. /**
  4. * DolConfigCollector class
  5. */
  6. class DolConfigCollector extends ConfigCollector
  7. {
  8. /**
  9. * Return widget settings
  10. *
  11. * @return array Array
  12. */
  13. public function getWidgets()
  14. {
  15. global $langs;
  16. return array(
  17. $langs->transnoentities('Config') => array(
  18. "icon" => "gear",
  19. "widget" => "PhpDebugBar.Widgets.VariableListWidget",
  20. "map" => $this->getName(),
  21. "default" => "{}"
  22. )
  23. );
  24. }
  25. /**
  26. * Return collected data
  27. *
  28. * @return array Array
  29. */
  30. public function collect()
  31. {
  32. $this->data = $this->getConfig();
  33. return parent::collect();
  34. }
  35. /**
  36. * Returns an array with config data
  37. *
  38. * @return array Array of config
  39. */
  40. protected function getConfig()
  41. {
  42. global $conf, $user;
  43. // Get constants
  44. $const = get_defined_constants(true);
  45. $config = array(
  46. 'Dolibarr' => array(
  47. 'const' => $const['user'],
  48. '$conf' => $this->objectToArray($conf),
  49. '$user' => $this->objectToArray($user)
  50. ),
  51. 'PHP' => array(
  52. 'version' => PHP_VERSION,
  53. 'interface' => PHP_SAPI,
  54. 'os' => PHP_OS
  55. )
  56. );
  57. return $config;
  58. }
  59. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  60. /**
  61. * Convert an object to array
  62. *
  63. * @param mixed $obj Object
  64. * @return array Array
  65. */
  66. protected function objectToArray($obj)
  67. {
  68. // phpcs:enable
  69. $arr = array();
  70. $_arr = is_object($obj) ? get_object_vars($obj) : $obj;
  71. foreach ($_arr as $key => $val) {
  72. $val = (is_array($val) || is_object($val)) ? $this->objectToArray($val) : $val;
  73. $arr[$key] = $val;
  74. }
  75. return $arr;
  76. }
  77. }