Skip to content

Commit

Permalink
NEW: Add module debugbar
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Mar 16, 2019
1 parent 0ecdb24 commit c2badb5
Show file tree
Hide file tree
Showing 95 changed files with 11,459 additions and 4 deletions.
2 changes: 1 addition & 1 deletion htdocs/core/modules/modDav.class.php
Expand Up @@ -19,7 +19,7 @@
* \defgroup dav Module dav
* \brief dav module descriptor.
*
* \file htdocs/dav/core/modules/modDav.class.php
* \file htdocs/core/modules/modDav.class.php
* \ingroup dav
* \brief Description and activation file for module dav
*/
Expand Down
133 changes: 133 additions & 0 deletions htdocs/core/modules/modDebugBar.class.php
@@ -0,0 +1,133 @@
<?php
/* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* \defgroup debugbar Debug bar
* \brief debugbar module descriptor.
*
* \file htdocs/core/modules/modDebugBar.class.php
* \ingroup debugbar
* \brief Description and activation file for module debugbar
*/
include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';


/**
* Class to describe and enable module
*/
class modDebugBar extends DolibarrModules
{

/**
* Constructor. Define names, constants, directories, boxes, permissions
*
* @param DoliDB $db Database handler
*/
public function __construct($db)
{
$this->db = $db;

$this->numero = 43;

$this->rights_class = 'debugbar';

$this->family = "base";
$this->module_position = '75';

// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
$this->name = preg_replace('/^mod/i', '', get_class($this));
$this->description = "Debug bar";
// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
$this->version = 'dolibarr';
$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
$this->picto='technic';

$this->module_parts = array(
// Set here all hooks context managed by module. To find available hook context, make a "grep -r '>initHooks(' *" on source code. You can also set hook context 'all'
'hooks' => array(
'data' => array(
'main',
'login',
),
'entity' => '0',
),
// Set this to 1 if feature of module are opened to external users
'moduleforexternal' => 0,
);

// Data directories to create when module is enabled
$this->dirs = array();

// Dependencies
$this->depends = array(); // May be used for product or service or third party module
$this->requiredby = array();

// Config pages
$this->config_page_url = array();

// Constants
// Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',0),
// 1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0) );
$this->const = array(
0 => array('DEBUGBAR_LOGS_LINES_NUMBER', 'chaine', '100', 'Number of log lines to show in debug bar', 1)
);

// Boxes
$this->boxes = array();

// Permissions
$this->rights = array();

$this->rights[1][0] = 430; // id de la permission
$this->rights[1][1] = 'Use Debug Bar'; // libelle de la permission
$this->rights[1][2] = 'u'; // type de la permission (deprecie a ce jour)
$this->rights[1][3] = 1; // La permission est-elle une permission par defaut
$this->rights[1][4] = 'read';
}


/**
* Function called when module is enabled.
* The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
* It also creates data directories.
*
* @param string $options Options when enabling module ('', 'noboxes')
* @return int 1 if OK, 0 if KO
*/
public function init($options = '')
{
// Permissions
$this->remove($options);

$sql = array(
);

return $this->_init($sql, $options);
}

/**
* Function called after module configuration.
*
*/
public function loadSettings()
{
$this->addPermission("use", "UseDebugBar", "u");

$this->enableHooks(array(
'main',
'login'
));
}
}
81 changes: 81 additions & 0 deletions htdocs/debugbar/class/DataCollector/DolConfigCollector.php
@@ -0,0 +1,81 @@
<?php

use \DebugBar\DataCollector\ConfigCollector;

/**
* DolConfigCollector class
*/

class DolConfigCollector extends ConfigCollector
{
/**
* Return widget settings
*
*/
public function getWidgets()
{
global $langs;

return array(
$langs->transnoentities('Config') => array(
"icon" => "gear",
"widget" => "PhpDebugBar.Widgets.VariableListWidget",
"map" => $this->getName(),
"default" => "{}"
)
);
}

/**
* Return collected data
*
*/
public function collect()
{
$this->data = $this->getConfig();

return parent::collect();
}

/**
* Returns an array with config data
*
*/
protected function getConfig()
{
global $conf, $user;

// Get constants
$const = get_defined_constants(true);

$config = array(
'Dolibarr' => array(
'const' => $const['user'],
'$conf' => $this->object_to_array($conf),
'$user' => $this->object_to_array($user)
),
'PHP' => array(
'version' => PHP_VERSION,
'interface' => PHP_SAPI,
'os' => PHP_OS
)
);

return $config;
}

/**
* Convert an object to array
*
*/
protected function object_to_array($obj)
{
$_arr = is_object($obj) ? get_object_vars($obj) : $obj;
foreach ($_arr as $key => $val) {
$val = (is_array($val) || is_object($val)) ? $this->object_to_array($val) : $val;
$arr[$key] = $val;
}

return $arr;
}
}
34 changes: 34 additions & 0 deletions htdocs/debugbar/class/DataCollector/DolExceptionsCollector.php
@@ -0,0 +1,34 @@
<?php

use \DebugBar\DataCollector\ExceptionsCollector;

/**
* DolExceptionsCollector class
*/

class DolExceptionsCollector extends ExceptionsCollector
{
/**
* Return widget settings
*
*/
public function getWidgets()
{
global $langs;

$title = $langs->transnoentities('Exceptions');

return array(
"$title" => array(
'icon' => 'bug',
'widget' => 'PhpDebugBar.Widgets.ExceptionsWidget',
'map' => 'exceptions.exceptions',
'default' => '[]'
),
"$title:badge" => array(
'map' => 'exceptions.count',
'default' => 'null'
)
);
}
}

0 comments on commit c2badb5

Please sign in to comment.