Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
463 changes: 9 additions & 454 deletions Controller/Component/ToolbarComponent.php

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions Lib/Log/Engine/DebugKitLogListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* A CakeLog listener which saves having to munge files or other configured loggers.
*
* @package debug_kit.components
*/

class DebugKitLogListener implements CakeLogInterface {

public $logs = array();

/**
* Makes the reverse link needed to get the logs later.
*
* @return void
*/
public function __construct($options) {
$options['panel']->logger = $this;
}

/**
* Captures log messages in memory
*
* @return void
*/
public function write($type, $message) {
if (!isset($this->logs[$type])) {
$this->logs[$type] = array();
}
$this->logs[$type][] = array(date('Y-m-d H:i:s'), $message);
}
}
71 changes: 71 additions & 0 deletions Lib/Panel/HistoryPanel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/**
* History Panel
*
* Provides debug information on previous requests.
*
* @package cake.debug_kit.panels
**/
class HistoryPanel extends DebugPanel {

/**
* Number of history elements to keep
*
* @var string
**/
public $history = 5;

/**
* Constructor
*
* @param array $settings Array of settings.
* @return void
**/
public function __construct($settings) {
if (isset($settings['history'])) {
$this->history = $settings['history'];
}
}

/**
* beforeRender callback function
*
* @return array contents for panel
**/
public function beforeRender(Controller $controller) {
$cacheKey = $controller->Toolbar->cacheKey;
$toolbarHistory = Cache::read($cacheKey, 'debug_kit');
$historyStates = array();
if (is_array($toolbarHistory) && !empty($toolbarHistory)) {
$prefix = array();
if (!empty($controller->request->params['prefix'])) {
$prefix[$controller->request->params['prefix']] = false;
}
foreach ($toolbarHistory as $i => $state) {
if (!isset($state['request']['content']['url'])) {
continue;
}
$title = $state['request']['content']['url'];
$query = @$state['request']['content']['query'];
if (isset($query['url'])) {
unset($query['url']);
}
if (!empty($query)) {
$title .= '?' . urldecode(http_build_query($query));
}
$historyStates[] = array(
'title' => $title,
'url' => array_merge($prefix, array(
'plugin' => 'debug_kit',
'controller' => 'toolbar_access',
'action' => 'history_state',
$i + 1))
);
}
}
if (count($historyStates) >= $this->history) {
array_pop($historyStates);
}
return $historyStates;
}
}
144 changes: 144 additions & 0 deletions Lib/Panel/IncludePanel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?php
/**
* Include Panel
*
* Provides a list of included files for the current request
*
* @package cake.debug_kit.panels
**/
class IncludePanel extends DebugPanel {

/**
* The list of plugins within the application
* @var <type>
*/
protected $_pluginPaths = array();

protected $_fileTypes = array(
'Cache', 'Config', 'Configure', 'Console', 'Component', 'Controller',
'Behavior', 'Datasource', 'Model', 'Plugin', 'Test', 'View', 'Utility',
'Network', 'Routing', 'I18n', 'Log', 'Error'
);

/**
* Get a list of plugins on construct for later use
*/
public function __construct() {
foreach(CakePlugin::loaded() as $plugin) {
$this->_pluginPaths[$plugin] = CakePlugin::path($plugin);
}

parent::__construct();
}

/**
* Get a list of files that were included and split them out into the various parts of the app
*
* @param Controller $controller
* @return void
*/
public function beforeRender(Controller $controller) {
$return = array('core' => array(), 'app' => array(), 'plugins' => array());

foreach(get_included_files() as $file) {
$pluginName = $this->_isPluginFile($file);

if($pluginName) {
$return['plugins'][$pluginName][$this->_getFileType($file)][] = $this->_niceFileName($file, $pluginName);
} else if($this->_isAppFile($file)) {
$return['app'][$this->_getFileType($file)][] = $this->_niceFileName($file, 'app');
} else if($this->_isCoreFile($file)) {
$return['core'][$this->_getFileType($file)][] = $this->_niceFileName($file, 'core');
}
}

$return['paths'] = $this->_includePaths();

ksort($return['core']);
ksort($return['plugins']);
ksort($return['app']);
return $return;
}

/**
* Get the possible include paths
* @return array
*/
protected function _includePaths() {
$split = (strstr(PHP_OS, 'win')) ? ';' : ':';
$paths = array_flip(array_merge(explode($split, get_include_path()), array(CAKE)));

unset($paths['.']);
return array_flip($paths);
}

/**
* Check if a path is part of cake core
* @param string $file
* @return bool
*/
protected function _isCoreFile($file) {
return strstr($file, CAKE);
}

/**
* Check if a path is from APP but not a plugin
* @param string $file
* @return bool
*/
protected function _isAppFile($file) {
return strstr($file, APP);
}

/**
* Check if a path is from a plugin
* @param string $file
* @return bool
*/
protected function _isPluginFile($file) {
foreach($this->_pluginPaths as $plugin => $path) {
if(strstr($file, $path)) {
return $plugin;
}
}

return false;
}

/**
* Replace the path with APP, CORE or the plugin name
* @param string $file
* @param string
* - app for app files
* - core for core files
* - PluginName for the name of a plugin
* @return bool
*/
protected function _niceFileName($file, $type) {
switch($type) {
case 'app':
return str_replace(APP, 'APP/', $file);

case 'core':
return str_replace(CAKE, 'CORE/', $file);

default:
return str_replace($this->_pluginPaths[$type], $type . '/', $file);
}
}

/**
* Get the type of file (model, controller etc)
* @param string $file
* @return string
*/
protected function _getFileType($file) {
foreach($this->_fileTypes as $type) {
if(preg_match(sprintf('/%s/i', $type), $file)) {
return $type;
}
}

return 'Other';
}
}
40 changes: 40 additions & 0 deletions Lib/Panel/LogPanel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
App::uses('DebugKitLogListener', 'DebugKit.Log/Engine');
class_exists('DebugKitLogListener');

/**
* Log Panel - Reads log entries made this request.
*
* @package cake.debug_kit.panels
*/
class LogPanel extends DebugPanel {

/**
* Constructor - sets up the log listener.
*
* @return void
*/
public function __construct($settings) {
parent::__construct();
$existing = CakeLog::configured();
if (empty($existing)) {
CakeLog::config('default', array(
'engine' => 'FileLog'
));
}
CakeLog::config('debug_kit_log_panel', array(
'engine' => 'DebugKitLogListener',
'panel' => $this
));
}

/**
* beforeRender Callback
*
* @return array
*/
public function beforeRender(Controller $controller) {
$logger = $this->logger;
return $logger;
}
}
29 changes: 29 additions & 0 deletions Lib/Panel/RequestPanel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* Request Panel
*
* Provides debug information on the Current request params.
*
* @package cake.debug_kit.panels
**/
class RequestPanel extends DebugPanel {

/**
* beforeRender callback - grabs request params
*
* @return array
**/
public function beforeRender(Controller $controller) {
$out = array();
$out['params'] = $controller->request->params;
$out['url'] = $controller->request->url;
$out['query'] = $controller->request->query;
$out['data'] = $controller->request->data;
if (isset($controller->Cookie)) {
$out['cookie'] = $controller->Cookie->read();
}
$out['get'] = $_GET;
$out['currentRoute'] = Router::currentRoute();
return $out;
}
}
21 changes: 21 additions & 0 deletions Lib/Panel/SessionPanel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Session Panel
*
* Provides debug information on the Session contents.
*
* @package cake.debug_kit.panels
**/
class SessionPanel extends DebugPanel {

/**
* beforeRender callback
*
* @param object $controller
* @return array
*/
public function beforeRender(Controller $controller) {
$sessions = $controller->Toolbar->Session->read();
return $sessions;
}
}
Loading