dolibarr/htdocs/debugbar/class/DataCollector/DolConfigCollector.php

90 lines
1.6 KiB
PHP
Raw Normal View History

2019-03-16 16:27:14 +01:00
<?php
use \DebugBar\DataCollector\ConfigCollector;
/**
* DolConfigCollector class
*/
class DolConfigCollector extends ConfigCollector
{
/**
* Return widget settings
*
2019-03-16 19:37:54 +01:00
* @return array Array
2019-03-16 16:27:14 +01:00
*/
public function getWidgets()
{
global $langs;
return array(
$langs->transnoentities('Config') => array(
"icon" => "gear",
"widget" => "PhpDebugBar.Widgets.VariableListWidget",
"map" => $this->getName(),
"default" => "{}"
)
);
}
/**
* Return collected data
*
2019-03-16 19:37:54 +01:00
* @return array Array
2019-03-16 16:27:14 +01:00
*/
public function collect()
{
$this->data = $this->getConfig();
return parent::collect();
}
/**
* Returns an array with config data
*
2019-03-16 19:37:54 +01:00
* @return array Array of config
2019-03-16 16:27:14 +01:00
*/
protected function getConfig()
{
global $conf, $user;
// Get constants
$const = get_defined_constants(true);
$config = array(
'Dolibarr' => array(
'const' => $const['user'],
2019-03-16 20:30:57 +01:00
'$conf' => $this->objectToArray($conf),
'$user' => $this->objectToArray($user)
2019-03-16 16:27:14 +01:00
),
'PHP' => array(
'version' => PHP_VERSION,
'interface' => PHP_SAPI,
'os' => PHP_OS
)
);
return $config;
}
2019-03-16 23:31:48 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2019-03-16 16:27:14 +01:00
/**
* Convert an object to array
*
2019-03-16 23:17:23 +01:00
* @param mixed $obj Object
* @return array Array
2019-03-16 16:27:14 +01:00
*/
2019-03-16 20:30:57 +01:00
protected function objectToArray($obj)
2019-03-16 16:27:14 +01:00
{
// phpcs:enable
$arr = array();
2019-03-16 16:27:14 +01:00
$_arr = is_object($obj) ? get_object_vars($obj) : $obj;
foreach ($_arr as $key => $val) {
2019-03-16 20:30:57 +01:00
$val = (is_array($val) || is_object($val)) ? $this->objectToArray($val) : $val;
2019-03-16 16:27:14 +01:00
$arr[$key] = $val;
}
return $arr;
}
2019-03-16 23:17:23 +01:00
}