Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Debugbar | by kevdev 1.0.0

   (0 reviews)    Find their other files

  29 743

10 Screenshots




  • +1 1

About This File

  

Невеликий інструмент який допоможе Вам дебажити ваш сайт.
Основні переваги:

  1. Легкий
  2. Відносно простий у встановленні
  3. Вносить зміни лише у 3 файли (header.php, loader.php, db.php)
  4. Дуже інформативний
  5. Працює лише при наявності активної сессії адміна
  6. Можливість переключатись між 10 останніми запитами

Недоліки:

  1. Модуль тестувався тільки на чистих Opencart та OcStore 3-ї версії, немає інформації щодо конфліктів з шаблонами, модулями і т.д. (але так як коду небагато то їх і не повинно бути)
  2. Підрахунок часу виконання запитів в бд не є реальним, підраховується різниця у часі перед початком виконання запиту та після.

Деталі:

  1. Longest - відображення усіх запитів в бд з сортуванням за приблизним часом виконання (наголошую що саме за приблизним часом а не точним)
  2. Duplicates - збирає всі задубльовані запити в бд
  3. Queries - відображення усіх запитів за реальним порядком виконання, та з вібораженням трейсів
  4. Controllers - відображення всіх контроллерів які приймали участь у відображенні сторінки
  5. Models - відображення всіх моделей які приймали участь у відображенні сторінки
  6. Views - відображення всіх темплейтів які приймали участь у відображенні сторінки
  7. Languages - відображення всіх файлів локалізації які приймали участь у відображенні сторінки
  8. Data - повний массив данних які були передані в фінальний темплейт

Встановлення:

  • рекомендую почати з бекапу папки system
  • встановлюємо модуль debugbar.ocmod.zip через адмін панель
  • оновлюємо модифікатори
  • відкриваємо файл system/framework.php та вносимо деякий код:
Прихований текст

Спочатку шукаємо строку з кодом:

$registry->set('log', $log)

Та після неї прописуємо наступний код:

if(file_exists(DIR_SYSTEM . 'library/debugbar.php')){
	require_once(DIR_SYSTEM . 'library/debugbar.php');
	$debugbar = new Debugbar($config);	
}else{
	$debugbar = null;
}
$registry->set('debugbar', $debugbar);


Далі шукаємо строку з кодом:

$db = new DB($config->get('db_engine'), $config->get('db_hostname'), $config->get('db_username'), $config->get('db_password'), $config->get('db_database'), $config->get('db_port'));

Та замінюємо її на:

$db = new DB($config->get('db_engine'), $config->get('db_hostname'), $config->get('db_username'), $config->get('db_password'), $config->get('db_database'), $config->get('db_port'), $debugbar);


Ну і останній крок, шукаємо строку:

$response->output();

Та перед нею прописуємо наступний код:
 

if(!is_null($debugbar)){
	$debugbar->end($registry);
}


На цьому все, та на всяк випадок прикріплю приклад повного файлу:

Прихований текст
<?php
// Registry
$registry = new Registry();

// Config
$config = new Config();
$config->load('default');
$config->load($application_config);
$registry->set('config', $config);

// Log
$log = new Log($config->get('error_filename'));
$registry->set('log', $log);

if(file_exists(DIR_SYSTEM . 'library/debugbar.php')){
	require_once(DIR_SYSTEM . 'library/debugbar.php');
	$debugbar = new Debugbar($config);	
}else{
	$debugbar = null;
}
$registry->set('debugbar', $debugbar);

date_default_timezone_set($config->get('date_timezone'));

set_error_handler(function($code, $message, $file, $line) use($log, $config) {
	// error suppressed with @
	if (!(error_reporting() & $code)) {
		return false;
	}

	switch ($code) {
		case E_NOTICE:
		case E_USER_NOTICE:
			$error = 'Notice';
			break;
		case E_WARNING:
		case E_USER_WARNING:
			$error = 'Warning';
			break;
		case E_ERROR:
		case E_USER_ERROR:
			$error = 'Fatal Error';
			break;
		default:
			$error = 'Unknown';
			break;
	}

	if ($config->get('error_display')) {
		echo '<b>' . $error . '</b>: ' . $message . ' in <b>' . $file . '</b> on line <b>' . $line . '</b>';
	}

	if ($config->get('error_log')) {
		$log->write('PHP ' . $error . ':  ' . $message . ' in ' . $file . ' on line ' . $line);
	}

	return true;
});

// Event
$event = new Event($registry);
$registry->set('event', $event);

// Event Register
if ($config->has('action_event')) {
	foreach ($config->get('action_event') as $key => $value) {
		foreach ($value as $priority => $action) {
			$event->register($key, new Action($action), $priority);
		}
	}
}

// Loader
$loader = new Loader($registry);
$registry->set('load', $loader);

// Request
$registry->set('request', new Request());

// Response
$response = new Response();
$response->addHeader('Content-Type: text/html; charset=utf-8');
$response->setCompression($config->get('config_compression'));
$registry->set('response', $response);

// Database
if ($config->get('db_autostart')) {
	$db = new DB($config->get('db_engine'), $config->get('db_hostname'), $config->get('db_username'), $config->get('db_password'), $config->get('db_database'), $config->get('db_port'), $debugbar);
	$registry->set('db', $db);

	// Sync PHP and DB time zones
	$db->query("SET time_zone = '" . $db->escape(date('P')) . "'");
}

// Session
$session = new Session($config->get('session_engine'), $registry);
$registry->set('session', $session);

if ($config->get('session_autostart')) {
	/*
	We are adding the session cookie outside of the session class as I believe
	PHP messed up in a big way handling sessions. Why in the hell is it so hard to
	have more than one concurrent session using cookies!

	Is it not better to have multiple cookies when accessing parts of the system
	that requires different cookie sessions for security reasons.

	Also cookies can be accessed via the URL parameters. So why force only one cookie
	for all sessions!
	*/

	if (isset($_COOKIE[$config->get('session_name')])) {
		$session_id = $_COOKIE[$config->get('session_name')];
	} else {
		$session_id = '';
	}

	$session->start($session_id);

	setcookie($config->get('session_name'), $session->getId(), ini_get('session.cookie_lifetime'), ini_get('session.cookie_path'), ini_get('session.cookie_domain'));
}

// Cache
$registry->set('cache', new Cache($config->get('cache_engine'), $config->get('cache_expire')));

// Url
if ($config->get('url_autostart')) {
	$registry->set('url', new Url($config->get('site_url'), $config->get('site_ssl')));
}

// Language
$language = new Language($config->get('language_directory'));
$registry->set('language', $language);

// Document
$registry->set('document', new Document());

// Config Autoload
if ($config->has('config_autoload')) {
	foreach ($config->get('config_autoload') as $value) {
		$loader->config($value);
	}
}

// Language Autoload
if ($config->has('language_autoload')) {
	foreach ($config->get('language_autoload') as $value) {
		$loader->language($value);
	}
}

// Library Autoload
if ($config->has('library_autoload')) {
	foreach ($config->get('library_autoload') as $value) {
		$loader->library($value);
	}
}

// Model Autoload
if ($config->has('model_autoload')) {
	foreach ($config->get('model_autoload') as $value) {
		$loader->model($value);
	}
}

// Route
$route = new Router($registry);

// Pre Actions
if ($config->has('action_pre_action')) {
	foreach ($config->get('action_pre_action') as $value) {
		$route->addPreAction(new Action($value));
	}
}

// Dispatch
$route->dispatch(new Action($config->get('action_router')), new Action($config->get('action_error')));

// Output
if(!is_null($debugbar)){
	$debugbar->end($registry);
}
$response->output();

 

 


DEMO




User Feedback

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.