Skip to content

Commit

Permalink
Merge branch 'release/0.1.0'
Browse files Browse the repository at this point in the history
* release/0.1.0:
  Add methods to send messages
  Remove deprecated method
  Remove double "the"
  Add emojis to README
  Fix path to life cycle image in README
  Add Exception and Measuring logging support
  Modify the Configure image
  Add images and document the Life cycle, configuration and Database Pane
  Add badges
  Load the Image directly from Github
  Remove wrong text from README
  Add @throws doc
  Improve code
  Change the vendor
  Add missing Collectors to the README
  Add a README
  Add License from Github
  Add extension icon
  Add first working version of the TYPO3 DebugBar
  • Loading branch information
Konafets committed Feb 14, 2018
2 parents 1b7c831 + a132c07 commit c0b2797
Show file tree
Hide file tree
Showing 32 changed files with 7,663 additions and 0 deletions.
61 changes: 61 additions & 0 deletions Classes/DataCollectors/AuthCollector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php namespace Konafets\TYPO3DebugBar\DataCollectors;

use DebugBar\DataCollector\DataCollectorInterface;
use DebugBar\DataCollector\Renderable;

/**
* Class AuthCollector
*
* @package Konafets\TYPO3DebugBar\DataCollectors
* @author Stefano Kowalke <[email protected]>
*/
class AuthCollector extends BaseCollector implements DataCollectorInterface, Renderable
{

/**
* Called by the DebugBar when data needs to be collected
*
* @return string Collected data
*/
function collect()
{
return $this->getUserInformation();
}

/**
* Returns the unique name of the collector
*
* @return string
*/
function getName()
{
return 'auth';
}

/**
* Returns a hash where keys are control names and their values
* an array of options as defined in {@see DebugBar\JavascriptRenderer::addControl()}
*
* @return array
*/
function getWidgets()
{
$name = $this->getName();

return [
"{$name}" => [
'icon' => 'user',
'tooltip' => 'Auth status',
'map' => 'auth.name',
'default' => '',
],
];
}

private function getUserInformation()
{
return [
'name' => htmlspecialchars($this->getBackendUser()->user['username']),
];
}
}
94 changes: 94 additions & 0 deletions Classes/DataCollectors/BaseCollector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php namespace Konafets\TYPO3DebugBar\DataCollectors;

use DebugBar\DataCollector\DataCollector;
use DebugBar\DataCollector\Renderable;
use TYPO3\CMS\Core\TimeTracker\TimeTracker;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Class BaseCollector
*
* @package Konafets\TYPO3DebugBar\DataCollectors
* @author Stefano Kowalke <[email protected]>
*/
abstract class BaseCollector extends DataCollector implements Renderable
{

/**
* The constructor
*/
public function __construct()
{
$this->getLanguageService()->includeLLFile('EXT:lang/Resources/Private/Language/locallang_tsfe.xlf');
}

/**
* Returns the current BE user.
*
* @return \TYPO3\CMS\Backend\FrontendBackendUserAuthentication
*/
protected function getBackendUser()
{
return $GLOBALS['BE_USER'];
}

/**
* Returns LanguageService
*
* @return \TYPO3\CMS\Lang\LanguageService
*/
protected function getLanguageService()
{
return GeneralUtility::makeInstance(\TYPO3\CMS\Lang\LanguageService::class);
}

/**
* Translate given key
*
* @param string $key Key for a label in the $LOCAL_LANG array of "sysext/lang/Resources/Private/Language/locallang_tsfe.xlf
* @param bool $convertWithHtmlspecialchars If TRUE the language-label will be sent through htmlspecialchars
* @return string The value for the $key
*/
protected function extGetLL($key, $convertWithHtmlspecialchars = true)
{
$labelStr = $this->getLanguageService()->getLL($key);
if ($convertWithHtmlspecialchars) {
$labelStr = htmlspecialchars($labelStr);
}
return $labelStr;
}

/**
* @return TimeTracker
*/
protected function getTimeTracker()
{
return GeneralUtility::makeInstance(TimeTracker::class);
}

/**
* Returns the value for an Admin Panel setting.
*
* @param string $sectionName Module key
* @param string $val Setting key
* @return mixed The setting value
*/
public function extGetFeAdminValue($sectionName, $val = '')
{
$beUser = $this->getBackendUser();

// Override all settings with user TSconfig
if ($val && isset($beUser->extAdminConfig['override.'][$sectionName . '.'][$val])) {
return $beUser->extAdminConfig['override.'][$sectionName . '.'][$val];
}
if (!$val && isset($beUser->extAdminConfig['override.'][$sectionName])) {
return $beUser->extAdminConfig['override.'][$sectionName];
}

$returnValue = $val ? $beUser->uc['TSFE_adminConfig'][$sectionName . '_' . $val] : 1;

// Exception for preview
return !$val ? true : $returnValue;
}

}
94 changes: 94 additions & 0 deletions Classes/DataCollectors/InfoCollector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php namespace Konafets\TYPO3DebugBar\DataCollectors;

use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Class InfoCollector
*
* @package Konafets\TYPO3DebugBar\DataCollectors
* @author Stefano Kowalke <[email protected]>
*/
class InfoCollector extends BaseCollector
{

/**
* Called by the DebugBar when data needs to be collected
*
* @return array Collected data
*/
function collect()
{
$output = [];
$frontendController = $this->getTypoScriptFrontendController();
if ($this->extGetFeAdminValue('cache', 'noCache')) {
$theBytes = 0;
$count = 0;
if (!empty($frontendController->imagesOnPage)) {
$tableArr[] = [$this->extGetLL('info_imagesOnPage'), count($frontendController->imagesOnPage), true];
foreach ($GLOBALS['TSFE']->imagesOnPage as $file) {
$fs = @filesize($file);
$tableArr[] = [TAB . $file, GeneralUtility::formatSize($fs)];
$theBytes += $fs;
$count++;
}
}
// Add an empty line
$output[$this->extGetLL('info_imagesSize')] = GeneralUtility::formatSize($theBytes);
$output[$this->extGetLL('info_DocumentSize')] = GeneralUtility::formatSize(strlen($frontendController->content));
$output[''] = '';
}

$output[$this->extGetLL('info_id')] = $frontendController->id;
$output[$this->extGetLL('info_type')] = $frontendController->type;
$output[$this->extGetLL('info_groupList')] = $frontendController->gr_list;
$output[$this->extGetLL('info_noCache')] = $this->extGetLL('info_noCache_' . ($frontendController->no_cache ? 'no' : 'yes'));
$output[$this->extGetLL('info_countUserInt')] = count($frontendController->config['INTincScript']);

if (!empty($frontendController->fe_user->user['uid'])) {
$output[$this->extGetLL('info_feuserName')] = htmlspecialchars($frontendController->fe_user->user['username']);
$output[$this->extGetLL('info_feuserId')] = htmlspecialchars($frontendController->fe_user->user['uid']);
}

$output[$this->extGetLL('info_totalParsetime')] = $this->getTimeTracker()->getParseTime() . ' ms';

return $output;
}

/**
* Returns the unique name of the collector
*
* @return string
*/
function getName()
{
return 'info';
}

/**
* Returns a hash where keys are control names and their values
* an array of options as defined in {@see DebugBar\JavascriptRenderer::addControl()}
*
* @return array
*/
function getWidgets()
{
$name = $this->getName();

return [
"$name" => [
'icon' => 'info',
'widget' => 'PhpDebugBar.Widgets.VariableListWidget',
'map' => 'info',
"default" => '[]',
],
];
}

/**
* @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
*/
protected function getTypoScriptFrontendController()
{
return $GLOBALS['TSFE'];
}
}
122 changes: 122 additions & 0 deletions Classes/DataCollectors/MySqliCollector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?php namespace Konafets\TYPO3DebugBar\DataCollectors;

use DebugBar\DataCollector\DataCollectorInterface;
use DebugBar\DataCollector\Renderable;
use DebugBar\DataCollector\TimeDataCollector;
use Doctrine\DBAL\Logging\DebugStack;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Class MySqliCollector
*
* @package Konafets\TYPO3DebugBar\DataCollectors
* @author Stefano Kowalke <[email protected]>
*/
class MySqliCollector extends BaseCollector implements DataCollectorInterface, Renderable
{

protected $connections = [];

protected $renderSqlWithParams = false;

protected $sqlQuotationChar = '<>';

/** @var DebugStack $sqlLogger */
protected $sqlLogger;

/**
* The constructor
*
* @param null $mysqli
* @param TimeDataCollector|null $timeDataCollector
*/
public function __construct($mysqli = null, TimeDataCollector $timeDataCollector = null)
{
parent::__construct();

$this->sqlLogger = $this->getSqlLoggerFromDatabaseConfiguration();
}

/**
* Called by the DebugBar when data needs to be collected
*
* @return array Collected data
*/
function collect()
{
$totalTime = 0;
$queries = $this->sqlLogger->queries;
$statements = [];

foreach ($queries as $query) {
$totalTime += $query['executionMS'];

$statements[] = [
'sql' => $query['sql'],
'params' => $query['params'],
'duration' => $query['executionMS'],
'duration_str' => $this->formatDuration($query['executionMS']),
'connection' => key($this->connections),
];
}

$data = [
'nb_statements' => count($queries),
'nb_failed_statements' => 0,
'accumulated_duration' => $totalTime,
'accumulated_duration_str' => $this->formatDuration($totalTime),
'statements' => $statements,
];

return $data;
}

/**
* Returns the unique name of the collector
*
* @return string
*/
function getName()
{
return 'mysqli';
}

/**
* Returns a hash where keys are control names and their values
* an array of options as defined in {@see DebugBar\JavascriptRenderer::addControl()}
*
* @return array
*/
function getWidgets()
{
return [
'database' => [
'icon' => 'database',
'widget' => 'PhpDebugBar.Widgets.SQLQueriesWidget',
'map' => 'mysqli',
'default' => '[]',
],
'database:badge' => [
'map' => 'mysqli.nb_statements',
'default' => 0,
],
];
}

private function getSqlLoggerFromDatabaseConfiguration()
{
$this->getConnections();

return $this->connections['Default']->getConfiguration()->getSQLLogger();
}

private function getConnections()
{
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);

foreach ($connectionPool->getConnectionNames() as $connectionName) {
$this->connections[$connectionName] = $connectionPool->getConnectionByName($connectionName);
}
}
}
Loading

0 comments on commit c0b2797

Please sign in to comment.