Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge remote-tracking branch 'euromark/cake2.x' into lib-cleanup

  • Loading branch information...
commit 5f7fde24fe0f5212326aba66ed534c770b4f60cd 2 parents fe55cc1 + 147d2dd
@markstory markstory authored
View
463 Controller/Component/ToolbarComponent.php
@@ -59,7 +59,7 @@ class ToolbarComponent extends Component {
*
* @var array
*/
- protected $_defaultPanels = array('history', 'session', 'request', 'sqlLog', 'timer', 'log', 'variables', 'include');
+ protected $_defaultPanels = array('DebugKit.History', 'DebugKit.Session', 'DebugKit.Request', 'DebugKit.SqlLog', 'DebugKit.Timer', 'DebugKit.Log', 'DebugKit.Variables', 'DebugKit.Include');
/**
* Loaded panel objects.
@@ -108,7 +108,7 @@ class ToolbarComponent extends Component {
* @return bool
**/
public function __construct(ComponentCollection $collection, $settings = array()) {
-
+ $settings = array_merge((array)Configure::read('DebugKit'), $settings);
$panels = $this->_defaultPanels;
if (isset($settings['panels'])) {
$panels = $this->_makePanelList($settings['panels']);
@@ -273,7 +273,7 @@ protected function _createCacheConfig() {
*
* @return array Array of all panel beforeRender()
**/
- protected function _gatherVars($controller) {
+ protected function _gatherVars(Controller $controller) {
$vars = array();
$panels = array_keys($this->panels);
@@ -300,10 +300,10 @@ protected function _gatherVars($controller) {
**/
protected function _loadPanels($panels, $settings) {
foreach ($panels as $panel) {
- $className = $panel . 'Panel';
+ $className = ucfirst($panel) . 'Panel';
list($plugin, $className) = pluginSplit($className, true);
- App::uses($className, $plugin . 'vendors');
+ App::uses($className, $plugin . 'Panel');
if (!class_exists($className)) {
trigger_error(__d('debug_kit', 'Could not load DebugToolbar panel %s', $panel), E_USER_WARNING);
continue;
@@ -353,7 +353,7 @@ protected function _eval($code) {
* @param array $vars Vars to save.
* @return void
**/
- protected function _saveState($controller, $vars) {
+ protected function _saveState(Controller $controller, $vars) {
$config = Cache::config('debug_kit');
if (empty($config) || !isset($this->panels['history'])) {
return;
@@ -384,7 +384,7 @@ class DebugPanel extends Object {
*
* @var string
*/
- public $plugin = null;
+ public $plugin = 'DebugKit';
/**
* Defines the title for displaying on the toolbar. If null, the class name will be used.
@@ -410,7 +410,7 @@ class DebugPanel extends Object {
* @param object $controller Controller reference.
* @return void
**/
- public function startup($controller) { }
+ public function startup(Controller $controller) { }
/**
* Prepare output vars before Controller Rendering.
@@ -418,451 +418,6 @@ public function startup($controller) { }
* @param object $controller Controller reference.
* @return void
**/
- public function beforeRender($controller) { }
-}
-
-/**
- * History Panel
- *
- * Provides debug information on previous requests.
- *
- * @package cake.debug_kit.panels
- **/
-class HistoryPanel extends DebugPanel {
-
- public $plugin = 'debug_kit';
-
-/**
- * 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) {
- $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;
- }
-}
-
-/**
- * Variables Panel
- *
- * Provides debug information on the View variables.
- *
- * @package cake.debug_kit.panels
- **/
-class VariablesPanel extends DebugPanel {
-
- public $plugin = 'debug_kit';
-
-/**
- * beforeRender callback
- *
- * @return array
- **/
- public function beforeRender($controller) {
- return array_merge($controller->viewVars, array('$request->data' => $controller->request->data));
- }
-}
-
-/**
- * Session Panel
- *
- * Provides debug information on the Session contents.
- *
- * @package cake.debug_kit.panels
- **/
-class SessionPanel extends DebugPanel {
-
- public $plugin = 'debug_kit';
-
-/**
- * beforeRender callback
- *
- * @param object $controller
- * @return array
- */
- public function beforeRender($controller) {
- $sessions = $controller->Toolbar->Session->read();
- return $sessions;
- }
-}
-
-/**
- * Request Panel
- *
- * Provides debug information on the Current request params.
- *
- * @package cake.debug_kit.panels
- **/
-class RequestPanel extends DebugPanel {
-
- public $plugin = 'debug_kit';
-
-/**
- * beforeRender callback - grabs request params
- *
- * @return array
- **/
- public function beforeRender($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;
- }
-}
-
-/**
- * Timer Panel
- *
- * Provides debug information on all timers used in a request.
- *
- * @package cake.debug_kit.panels
- **/
-class TimerPanel extends DebugPanel {
-
- public $plugin = 'debug_kit';
+ public function beforeRender(Controller $controller) { }
-/**
- * startup - add in necessary helpers
- *
- * @return void
- **/
- public function startup($controller) {
- if (!in_array('Number', array_keys(HelperCollection::normalizeObjectArray($controller->helpers)))) {
- $controller->helpers[] = 'Number';
- }
- if (!in_array('SimpleGraph', array_keys(HelperCollection::normalizeObjectArray($controller->helpers)))) {
- $controller->helpers[] = 'DebugKit.SimpleGraph';
- }
- }
-}
-
-/**
- * SqlLog Panel
- *
- * Provides debug information on the SQL logs and provides links to an ajax explain interface.
- *
- * @package cake.debug_kit.panels
- **/
-class SqlLogPanel extends DebugPanel {
-
- public $plugin = 'debug_kit';
-
-/**
- * Minimum number of Rows Per Millisecond that must be returned by a query before an explain
- * is done.
- *
- * @var int
- **/
- public $slowRate = 20;
-
-/**
- * Gets the connection names that should have logs + dumps generated.
- *
- * @param string $controller
- * @return void
- */
- public function beforeRender($controller) {
- if (!class_exists('ConnectionManager')) {
- return array();
- }
- $connections = array();
-
- $dbConfigs = ConnectionManager::sourceList();
- foreach ($dbConfigs as $configName) {
- $driver = null;
- $db = ConnectionManager::getDataSource($configName);
- if (
- (empty($db->config['driver']) && empty($db->config['datasource'])) ||
- !method_exists($db, 'getLog')
- ) {
- continue;
- }
- if (isset($db->config['datasource'])) {
- $driver = $db->config['datasource'];
- }
- $explain = false;
- $isExplainable = (preg_match('/(Mysql|Postgres)$/', $driver));
- if ($isExplainable) {
- $explain = true;
- }
- $connections[$configName] = $explain;
- }
- return array('connections' => $connections, 'threshold' => $this->slowRate);
- }
-}
-
-/**
- * Log Panel - Reads log entries made this request.
- *
- * @package cake.debug_kit.panels
- */
-class LogPanel extends DebugPanel {
-
- public $plugin = 'debug_kit';
-
-/**
- * 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) {
- $logger = $this->logger;
- return $logger;
- }
-}
-
-/**
- * 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);
- }
-}
-
-/**
- * Include Panel
- *
- * Provides a list of included files for the current request
- *
- * @package cake.debug_kit.panels
- **/
-class IncludePanel extends DebugPanel {
-
- public $plugin = 'debug_kit';
-
-/**
- * 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) {
- $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';
- }
}
View
32 Lib/Log/Engine/DebugKitLogListener.php
@@ -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);
+ }
+}
View
71 Lib/Panel/HistoryPanel.php
@@ -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;
+ }
+}
View
144 Lib/Panel/IncludePanel.php
@@ -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';
+ }
+}
View
40 Lib/Panel/LogPanel.php
@@ -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;
+ }
+}
View
29 Lib/Panel/RequestPanel.php
@@ -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;
+ }
+}
View
21 Lib/Panel/SessionPanel.php
@@ -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;
+ }
+}
View
53 Lib/Panel/SqlLogPanel.php
@@ -0,0 +1,53 @@
+<?php
+/**
+ * SqlLog Panel
+ *
+ * Provides debug information on the SQL logs and provides links to an ajax explain interface.
+ *
+ * @package cake.debug_kit.panels
+ **/
+class SqlLogPanel extends DebugPanel {
+
+/**
+ * Minimum number of Rows Per Millisecond that must be returned by a query before an explain
+ * is done.
+ *
+ * @var int
+ **/
+ public $slowRate = 20;
+
+/**
+ * Gets the connection names that should have logs + dumps generated.
+ *
+ * @param string $controller
+ * @return void
+ */
+ public function beforeRender(Controller $controller) {
+ if (!class_exists('ConnectionManager')) {
+ return array();
+ }
+ $connections = array();
+
+ $dbConfigs = ConnectionManager::sourceList();
+ foreach ($dbConfigs as $configName) {
+ $driver = null;
+ $db = ConnectionManager::getDataSource($configName);
+ if (
+ (empty($db->config['driver']) && empty($db->config['datasource'])) ||
+ !method_exists($db, 'getLog')
+ ) {
+ continue;
+ }
+ if (isset($db->config['datasource'])) {
+ $driver = $db->config['datasource'];
+ }
+ $explain = false;
+ $isExplainable = (preg_match('/(Mysql|Postgres)$/', $driver));
+ if ($isExplainable) {
+ $explain = true;
+ }
+ $connections[$configName] = $explain;
+ }
+ return array('connections' => $connections, 'threshold' => $this->slowRate);
+ }
+}
View
63 Lib/Panel/TidyPanel.php
@@ -0,0 +1,63 @@
+<?php
+/**
+ * Show (x)html validation errors in a tidy panel
+ *
+ * PHP version 4 and 5
+ *
+ * Copyright (c) 2009, Andy Dawson
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright Copyright (c) 2009, Andy Dawson
+ * @link www.ad7six.com
+ * @package debug_kit
+ * @subpackage debug_kit.vendors
+ * @since v 1.0 (22-Jun-2009)
+ * @license http://www.opensource.org/licenses/mit-license.php The MIT License
+ */
+
+/**
+ * TidyPanel class
+ *
+ * @uses DebugPanel
+ * @package debug_kit
+ * @subpackage debug_kit.panel
+ */
+class TidyPanel extends DebugPanel {
+
+/**
+ * title property
+ *
+ * @var string 'Tidy'
+ * @access public
+ */
+ public $title = 'Tidy';
+
+/**
+ * elementName property
+ *
+ * @var string 'tidy'
+ * @access public
+ */
+ public $elementName = 'tidy_panel';
+
+/**
+ * startup method
+ *
+ * @param mixed $controller
+ * @return void
+ * @access public
+ */
+ public function startup(Controller $controller) {
+ $isHtml = (
+ !isset($controller->params['ext']) ||
+ (isset($controller->params['ext']) && $controller->params['ext'] == 'html')
+ );
+ if ($controller->Toolbar->RequestHandler->isAjax() || !$isHtml) {
+ $this->enabled = false;
+ unset($controller->Toolbar->panels['Tidy']);
+ }
+ $controller->helpers[] = 'DebugKit.Tidy';
+ }
+}
View
24 Lib/Panel/TimerPanel.php
@@ -0,0 +1,24 @@
+<?php
+/**
+ * Timer Panel
+ *
+ * Provides debug information on all timers used in a request.
+ *
+ * @package cake.debug_kit.panels
+ **/
+class TimerPanel extends DebugPanel {
+
+/**
+ * startup - add in necessary helpers
+ *
+ * @return void
+ **/
+ public function startup(Controller $controller) {
+ if (!in_array('Number', array_keys(HelperCollection::normalizeObjectArray($controller->helpers)))) {
+ $controller->helpers[] = 'Number';
+ }
+ if (!in_array('SimpleGraph', array_keys(HelperCollection::normalizeObjectArray($controller->helpers)))) {
+ $controller->helpers[] = 'DebugKit.SimpleGraph';
+ }
+ }
+}
View
20 Lib/Panel/VariablesPanel.php
@@ -0,0 +1,20 @@
+<?php
+/**
+ * Variables Panel
+ *
+ * Provides debug information on the View variables.
+ *
+ * @package cake.debug_kit.panels
+ **/
+class VariablesPanel extends DebugPanel {
+
+/**
+ * beforeRender callback
+ *
+ * @return array
+ **/
+ public function beforeRender(Controller $controller) {
+ return array_merge($controller->viewVars, array('$request->data' => $controller->request->data));
+ }
+}
+
View
43 Test/Case/AllDebugKitTest.php
@@ -0,0 +1,43 @@
+<?php
+
+require_once dirname(__FILE__) . DS . 'DebugkitGroupTestCase.php';
+
+/**
+ * View Group Test for debugkit
+ *
+ * PHP versions 5
+ *
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link http://cakephp.org
+ * @package debug_kit
+ * @subpackage debug_kit.tests.groups
+ * @since DebugKit 1.0
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ **/
+/**
+ * DebugKitViewTestSuite class
+ *
+ * @package cake
+ * @subpackage cake.tests.cases
+ */
+
+class AllDebugKitTest extends DebugkitGroupTestCase {
+/**
+ *
+ *
+ * @return PHPUnit_Framework_TestSuite the instance of PHPUnit_Framework_TestSuite
+ */
+ public static function suite() {
+ $suite = new self;
+ $files = $suite->getTestFiles();
+ $suite->addTestFiles($files);
+
+ return $suite;
+ }
+}
View
5 View/Elements/tidy_panel.ctp
@@ -0,0 +1,5 @@
+<?php
+if (!empty($this->request->params['isAjax'])) {
+ return;
+}
+echo $this->Tidy->report($this->output);
View
6 View/Helper/HtmlToolbarHelper.php
@@ -44,7 +44,7 @@ class HtmlToolbarHelper extends ToolbarHelper {
* @param int $currentDepth current depth.
* @return string
**/
- public function makeNeatArray($values, $openDepth = 0, $currentDepth = 0) {
+ public function makeNeatArray($values, $openDepth = 0, $currentDepth = 0, $doubleEncode = false) {
$className ="neat-array depth-$currentDepth";
if ($openDepth > $currentDepth) {
$className .= ' expanded';
@@ -82,9 +82,9 @@ public function makeNeatArray($values, $openDepth = 0, $currentDepth = 0) {
}
if (is_array($value) && !empty($value)) {
- $out .= $this->makeNeatArray($value, $openDepth, $nextDepth);
+ $out .= $this->makeNeatArray($value, $openDepth, $nextDepth, $doubleEncode);
} else {
- $out .= h($value);
+ $out .= h($value, $doubleEncode);
}
$out .= '</li>';
}
View
4 View/Helper/SimpleGraphHelper.php
@@ -41,7 +41,7 @@ class SimpleGraphHelper extends AppHelper {
*
* @var array
*/
- private $__defaultSettings = array(
+ protected $_defaultSettings = array(
'max' => 100,
'width' => 350,
'valueType' => 'value',
@@ -55,7 +55,7 @@ class SimpleGraphHelper extends AppHelper {
* @return string Html graph
*/
public function bar($value, $offset, $options = array()) {
- $settings = array_merge($this->__defaultSettings, $options);
+ $settings = array_merge($this->_defaultSettings, $options);
extract($settings);
$graphValue = ($value / $max) * $width;
View
184 View/Helper/TidyHelper.php
@@ -0,0 +1,184 @@
+<?php
+App::uses('File', 'Utility');
+
+/**
+ * Tidy helper - passes html through tidy on the command line, and reports markup errors
+ *
+ * PHP version 4 and 5
+ *
+ * Copyright (c) 2009, Andy Dawson
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright Copyright (c) 2009, Andy Dawson
+ * @link www.ad7six.com
+ * @package debug_kit
+ * @subpackage debug_kit.views.helpers
+ * @since v 1.0 (22-Jun-2009)
+ * @license http://www.opensource.org/licenses/mit-license.php The MIT License
+ */
+
+/**
+ * TidyHelper class
+ *
+ * @uses AppHelper
+ * @package debug_kit
+ * @subpackage debug_kit.views.helpers
+ */
+class TidyHelper extends AppHelper {
+
+/**
+ * helpers property
+ *
+ * @var array
+ * @access public
+ */
+ public $helpers = array('DebugKit.Toolbar');
+
+/**
+ * results property
+ *
+ * @var mixed null
+ * @access public
+ */
+ public $results = null;
+
+/**
+ * Return a nested array of errors for the passed html string
+ * Fudge the markup slightly so that the tag which is invalid is highlighted
+ *
+ * @param string $html ''
+ * @param string $out ''
+ * @return array
+ * @access public
+ */
+ public function process($html = '', &$out = '') {
+ $errors = $this->tidyErrors($html, $out);
+
+
+ if (!$errors) {
+ return;
+ }
+ $result = array('Error' => array(), 'Warning' => array(), 'Misc' => array());
+ $errors = explode("\n", $errors);
+ $markup = explode("\n", $out);
+ foreach ($errors as $error) {
+ preg_match('@line (\d+) column (\d+) - (\w+): (.*)@', $error, $matches);
+ if ($matches) {
+ list($original, $line, $column, $type, $message) = $matches;
+ $line = $line - 1;
+
+ $string = '</strong>';
+ if (isset($markup[$line - 1])) {
+ $string .= h($markup[$line - 1]);
+ }
+ $string .= '<strong>' . h(@$markup[$line]) . '</strong>';
+ if (isset($markup[$line + 1])) {
+ $string .= h($markup[$line + 1]);
+ }
+ $string .= '</strong>';
+
+ $result[$type][$string][] = h($message);
+ } elseif ($error) {
+ $message = $error;
+ $result['Misc'][h($message)][] = h($message);
+ }
+ }
+ $this->results = $result;
+ return $result;
+ }
+
+/**
+ * report method
+ *
+ * Call process if a string is passed, or no prior results exist - and return the results using
+ * the toolbar helper to generate a nested navigatable array
+ *
+ * @param mixed $html null
+ * @return string
+ * @access public
+ */
+ public function report($html = null) {
+ if ($html) {
+ $this->process($html);
+ } elseif ($this->results === null) {
+ $this->process($this->_View->output);
+ }
+ if (!$this->results) {
+ return '<p>' . __d('debug_kit', 'No markup errors found') . '</p>';
+ }
+ foreach ($this->results as &$results) {
+ foreach ($results as $type => &$messages) {
+ foreach ($messages as &$message) {
+ $message = html_entity_decode($message, ENT_COMPAT, Configure::read('App.encoding'));
+ }
+ }
+ }
+ return $this->Toolbar->makeNeatArray(array_filter($this->results), 0, 0, false);
+ }
+
+/**
+ * Run the html string through tidy, and return the (raw) errors. pass back a reference to the
+ * normalized string so that the error messages can be linked to the line that caused them.
+ *
+ * @param string $in ''
+ * @param string $out ''
+ * @return string
+ * @access public
+ */
+ public function tidyErrors($in = '', &$out = '') {
+ $out = preg_replace('@>\s*<@s', ">\n<", $in);
+
+ // direct access? windows etc
+ if (function_exists('tidy_parse_string')) {
+ $tidy = tidy_parse_string($out, array(), 'UTF8');
+ $tidy->cleanRepair();
+ $errors = $tidy->errorBuffer. "\n";
+ return $errors;
+ }
+
+ // cli
+ $File = new File(rtrim(TMP, DS) . DS . rand() . '.html', true);
+ $File->write($out);
+ $path = $File->pwd();
+ $errors = $path . '.err';
+ $this->_exec("tidy -eq -utf8 -f $errors $path");
+ $File->delete();
+
+ if (!file_exists($errors)) {
+ return;
+ }
+ $Error = new File($errors);
+ $errors = $Error->read();
+ $Error->delete();
+ return $errors;
+ }
+
+/**
+ * exec method
+ *
+ * @param mixed $cmd
+ * @param mixed $out null
+ * @return void
+ * @access protected
+ */
+ protected function _exec($cmd, &$out = null) {
+ if (DS === '/') {
+ $_out = exec($cmd . ' 2>&1', $out, $return);
+ } else {
+ $_out = exec($cmd, $out, $return);
+ }
+
+ if (Configure::read('debug')) {
+ $source = Debugger::trace(array('depth' => 1, 'start' => 2)) . "\n";
+ //CakeLog::write('system_calls_' . date('Y-m-d'), "\n" . $source . Debugger::exportVar(compact('cmd','out','return')));
+ //CakeLog::write('system_calls', "\n" . $source . Debugger::exportVar(compact('cmd','out','return')));
+ }
+ if ($return) {
+ return false;
+ }
+ return $_out ? $_out : true;
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.