Added the debug toolkit plugin, found on the bakery website.
git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@92 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
*/
|
||||
class AppController extends Controller {
|
||||
var $helpers = array('Html', 'Format', 'Time');
|
||||
var $components = array('DebugKit.Toolbar');
|
||||
|
||||
function sideMenuLinks() {
|
||||
return array(
|
||||
|
||||
5
plugins/debug_kit/README
Normal file
5
plugins/debug_kit/README
Normal file
@@ -0,0 +1,5 @@
|
||||
To install copy the debug_kit directory to the plugins folder and include the toolbar component in your app_controller.php:
|
||||
|
||||
$components = array('DebugKit.Toolbar');
|
||||
|
||||
+ Set debug mode to at least 1.
|
||||
0
plugins/debug_kit/controllers/components/empty
Normal file
0
plugins/debug_kit/controllers/components/empty
Normal file
471
plugins/debug_kit/controllers/components/toolbar.php
Normal file
471
plugins/debug_kit/controllers/components/toolbar.php
Normal file
@@ -0,0 +1,471 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* DebugKit DebugToolbar Component
|
||||
*
|
||||
*
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.
|
||||
* @since CakePHP v 1.2.0.4487
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
class ToolbarComponent extends Object {
|
||||
/**
|
||||
* Controller instance reference
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
var $controller;
|
||||
/**
|
||||
* Components used by DebugToolbar
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $components = array('RequestHandler');
|
||||
/**
|
||||
* The default panels the toolbar uses.
|
||||
* which panels are used can be configured when attaching the component
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $_defaultPanels = array('session', 'request', 'sqlLog', 'timer', 'log', 'memory', 'variables');
|
||||
/**
|
||||
* Loaded panel objects.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $panels = array();
|
||||
|
||||
/**
|
||||
* fallback for javascript settings
|
||||
*
|
||||
* @var array
|
||||
**/
|
||||
var $_defaultJavascript = array(
|
||||
'behavior' => '/debug_kit/js/js_debug_toolbar'
|
||||
);
|
||||
/**
|
||||
* javascript files component will be using.
|
||||
*
|
||||
* @var array
|
||||
**/
|
||||
var $javascript = array();
|
||||
/**
|
||||
* initialize
|
||||
*
|
||||
* If debug is off the component will be disabled and not do any further time tracking
|
||||
* or load the toolbar helper.
|
||||
*
|
||||
* @return bool
|
||||
**/
|
||||
function initialize(&$controller, $settings) {
|
||||
if (Configure::read('debug') == 0) {
|
||||
$this->enabled = false;
|
||||
return false;
|
||||
}
|
||||
App::import('Vendor', 'DebugKit.DebugKitDebugger');
|
||||
|
||||
DebugKitDebugger::startTimer('componentInit', __('Component initialization and startup', true));
|
||||
if (!isset($settings['panels'])) {
|
||||
$settings['panels'] = $this->_defaultPanels;
|
||||
}
|
||||
|
||||
if (isset($settings['javascript'])) {
|
||||
$settings['javascript'] = $this->_setJavascript($settings['javascript']);
|
||||
} else {
|
||||
$settings['javascript'] = $this->_defaultJavascript;
|
||||
}
|
||||
$this->_loadPanels($settings['panels']);
|
||||
unset($settings['panels']);
|
||||
|
||||
$this->_set($settings);
|
||||
$this->controller =& $controller;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Component Startup
|
||||
*
|
||||
* @return bool
|
||||
**/
|
||||
function startup(&$controller) {
|
||||
$currentViewClass = $controller->view;
|
||||
$this->_makeViewClass($currentViewClass);
|
||||
$controller->view = 'DebugKit.Debug';
|
||||
if (!isset($controller->params['url']['ext']) || (isset($controller->params['url']['ext']) && $controller->params['url']['ext'] == 'html')) {
|
||||
$format = 'Html';
|
||||
} else {
|
||||
$format = 'FirePhp';
|
||||
}
|
||||
$controller->helpers['DebugKit.Toolbar'] = array('output' => sprintf('DebugKit.%sToolbar', $format));
|
||||
$panels = array_keys($this->panels);
|
||||
foreach ($panels as $panelName) {
|
||||
$this->panels[$panelName]->startup($controller);
|
||||
}
|
||||
DebugKitDebugger::stopTimer('componentInit');
|
||||
DebugKitDebugger::startTimer('controllerAction', __('Controller Action', true));
|
||||
}
|
||||
/**
|
||||
* beforeRender callback
|
||||
*
|
||||
* Calls beforeRender on all the panels and set the aggregate to the controller.
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function beforeRender(&$controller) {
|
||||
DebugKitDebugger::stopTimer('controllerAction');
|
||||
$vars = array();
|
||||
$panels = array_keys($this->panels);
|
||||
|
||||
foreach ($panels as $panelName) {
|
||||
$panel =& $this->panels[$panelName];
|
||||
$vars[$panelName]['content'] = $panel->beforeRender($controller);
|
||||
$elementName = Inflector::underscore($panelName) . '_panel';
|
||||
if (isset($panel->elementName)) {
|
||||
$elementName = $panel->elementName;
|
||||
}
|
||||
$vars[$panelName]['elementName'] = $elementName;
|
||||
$vars[$panelName]['plugin'] = $panel->plugin;
|
||||
$vars[$panelName]['disableTimer'] = true;
|
||||
}
|
||||
|
||||
$controller->set(array('debugToolbarPanels' => $vars, 'debugToolbarJavascript' => $this->javascript));
|
||||
DebugKitDebugger::startTimer('controllerRender', __('Render Controller Action', true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Panels used in the debug toolbar
|
||||
*
|
||||
* @return void
|
||||
* @access protected
|
||||
**/
|
||||
function _loadPanels($panels) {
|
||||
foreach ($panels as $panel) {
|
||||
$className = $panel . 'Panel';
|
||||
if (!class_exists($className) && !App::import('Vendor', $className)) {
|
||||
trigger_error(sprintf(__('Could not load DebugToolbar panel %s', true), $panel), E_USER_WARNING);
|
||||
continue;
|
||||
}
|
||||
$panelObj =& new $className();
|
||||
if (is_subclass_of($panelObj, 'DebugPanel') || is_subclass_of($panelObj, 'debugpanel')) {
|
||||
$this->panels[$panel] =& $panelObj;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the javascript to user scripts.
|
||||
*
|
||||
* Set either script key to false to exclude it from the rendered layout.
|
||||
*
|
||||
* @param array $scripts Javascript config information
|
||||
* @return array
|
||||
* @access protected
|
||||
**/
|
||||
function _setJavascript($scripts) {
|
||||
$behavior = false;
|
||||
if (!is_array($scripts)) {
|
||||
$scripts = (array)$scripts;
|
||||
}
|
||||
if (isset($scripts[0])) {
|
||||
$behavior = $scripts[0];
|
||||
}
|
||||
if (isset($scripts['behavior'])) {
|
||||
$behavior = $scripts['behavior'];
|
||||
}
|
||||
if (!$behavior) {
|
||||
return array();
|
||||
} elseif ($behavior === true) {
|
||||
$behavior = 'js';
|
||||
}
|
||||
if (strpos($behavior, '/') !== 0) {
|
||||
$behavior .= '_debug_toolbar';
|
||||
}
|
||||
$pluginFile = APP . 'plugins' . DS . 'debug_kit' . DS . 'vendors' . DS . 'js' . DS . $behavior . '.js';
|
||||
if (file_exists($pluginFile)) {
|
||||
$behavior = '/debug_kit/js/' . $behavior . '.js';
|
||||
}
|
||||
return compact('behavior');
|
||||
}
|
||||
/**
|
||||
* Makes the DoppleGangerView class if it doesn't already exist.
|
||||
* This allows DebugView to be compatible with all view classes.
|
||||
*
|
||||
* @param string $baseClassName
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
function _makeViewClass($baseClassName) {
|
||||
if (!class_exists('DoppelGangerView')) {
|
||||
App::import('View', $baseClassName);
|
||||
if (strpos('View', $baseClassName) === false) {
|
||||
$baseClassName .= 'View';
|
||||
}
|
||||
$class = "class DoppelGangerView extends $baseClassName {}";
|
||||
eval($class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug Panel
|
||||
*
|
||||
* Abstract class for debug panels.
|
||||
*
|
||||
* @package cake.debug_kit
|
||||
*/
|
||||
class DebugPanel extends Object {
|
||||
/**
|
||||
* Defines which plugin this panel is from so the element can be located.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $plugin = null;
|
||||
/**
|
||||
* startup the panel
|
||||
*
|
||||
* Pull information from the controller / request
|
||||
*
|
||||
* @param object $controller Controller reference.
|
||||
* @return void
|
||||
**/
|
||||
function startup(&$controller) { }
|
||||
|
||||
/**
|
||||
* Prepare output vars before Controller Rendering.
|
||||
*
|
||||
* @param object $controller Controller reference.
|
||||
* @return void
|
||||
**/
|
||||
function beforeRender(&$controller) { }
|
||||
}
|
||||
|
||||
/**
|
||||
* Variables Panel
|
||||
*
|
||||
* Provides debug information on the View variables.
|
||||
*
|
||||
* @package cake.debug_kit.panels
|
||||
**/
|
||||
class VariablesPanel extends DebugPanel {
|
||||
var $plugin = 'debug_kit';
|
||||
}
|
||||
|
||||
/**
|
||||
* Session Panel
|
||||
*
|
||||
* Provides debug information on the Session contents.
|
||||
*
|
||||
* @package cake.debug_kit.panels
|
||||
**/
|
||||
class SessionPanel extends DebugPanel {
|
||||
var $plugin = 'debug_kit';
|
||||
/**
|
||||
* beforeRender callback
|
||||
*
|
||||
* @param object $controller
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
function beforeRender(&$controller) {
|
||||
return $controller->Session->read();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Request Panel
|
||||
*
|
||||
* Provides debug information on the Current request params.
|
||||
*
|
||||
* @package cake.debug_kit.panels
|
||||
**/
|
||||
class RequestPanel extends DebugPanel {
|
||||
var $plugin = 'debug_kit';
|
||||
/**
|
||||
* beforeRender callback - grabs request params
|
||||
*
|
||||
* @return array
|
||||
**/
|
||||
function beforeRender(&$controller) {
|
||||
$out = array();
|
||||
$out['params'] = $controller->params;
|
||||
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 {
|
||||
var $plugin = 'debug_kit';
|
||||
/**
|
||||
* startup - add in necessary helpers
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function startup(&$controller) {
|
||||
if (!in_array('Number', $controller->helpers)) {
|
||||
$controller->helpers[] = 'Number';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Memory Panel
|
||||
*
|
||||
* Provides debug information on the memory consumption.
|
||||
*
|
||||
* @package cake.debug_kit.panels
|
||||
**/
|
||||
class MemoryPanel extends DebugPanel {
|
||||
var $plugin = 'debug_kit';
|
||||
/**
|
||||
* startup - add in necessary helpers
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function startup(&$controller) {
|
||||
if (!in_array('Number', $controller->helpers)) {
|
||||
$controller->helpers[] = 'Number';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
var $plugin = 'debug_kit';
|
||||
|
||||
var $dbConfigs = array();
|
||||
/**
|
||||
* get db configs.
|
||||
*
|
||||
* @param string $controller
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function startUp(&$controller) {
|
||||
if (!class_exists('ConnectionManager')) {
|
||||
$this->dbConfigs = array();
|
||||
return false;
|
||||
}
|
||||
$this->dbConfigs = ConnectionManager::sourceList();
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Get Sql Logs for each DB config
|
||||
*
|
||||
* @param string $controller
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function beforeRender(&$controller) {
|
||||
$queryLogs = array();
|
||||
if (!class_exists('ConnectionManager')) {
|
||||
return array();
|
||||
}
|
||||
foreach ($this->dbConfigs as $configName) {
|
||||
$db =& ConnectionManager::getDataSource($configName);
|
||||
if ($db->isInterfaceSupported('showLog')) {
|
||||
ob_start();
|
||||
$db->showLog();
|
||||
$queryLogs[$configName] = ob_get_clean();
|
||||
}
|
||||
}
|
||||
return $queryLogs;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log Panel - Reads log entries made this request.
|
||||
*
|
||||
* @package cake.debug_kit.panels
|
||||
*/
|
||||
class LogPanel extends DebugPanel {
|
||||
var $plugin = 'debug_kit';
|
||||
/**
|
||||
* Log files to scan
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $logFiles = array('error.log', 'debug.log');
|
||||
/**
|
||||
* startup
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function startup(&$controller) {
|
||||
if (!class_exists('CakeLog')) {
|
||||
App::import('Core', 'Log');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* beforeRender Callback
|
||||
*
|
||||
* @return array
|
||||
**/
|
||||
function beforeRender(&$controller) {
|
||||
$this->startTime = DebugKitDebugger::requestStartTime();
|
||||
$this->currentTime = DebugKitDebugger::requestTime();
|
||||
$out = array();
|
||||
foreach ($this->logFiles as $log) {
|
||||
$file = LOGS . $log;
|
||||
if (!file_exists($file)) {
|
||||
continue;
|
||||
}
|
||||
$out[$log] = $this->_parseFile($file);
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
/**
|
||||
* parse a log file and find the relevant entries
|
||||
*
|
||||
* @param string $filename Name of file to read
|
||||
* @access protected
|
||||
* @return array
|
||||
*/
|
||||
function _parseFile($filename) {
|
||||
$file =& new File($filename);
|
||||
$contents = $file->read();
|
||||
$timePattern = '/(\d{4}-\d{2}\-\d{2}\s\d{1,2}\:\d{1,2}\:\d{1,2})/';
|
||||
$chunks = preg_split($timePattern, $contents, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
|
||||
for ($i = 0, $len = count($chunks); $i < $len; $i += 2) {
|
||||
if (strtotime($chunks[$i]) < $this->startTime) {
|
||||
unset($chunks[$i], $chunks[$i + 1]);
|
||||
}
|
||||
}
|
||||
return array_values($chunks);
|
||||
}
|
||||
}
|
||||
?>
|
||||
32
plugins/debug_kit/debug_kit_app_controller.php
Normal file
32
plugins/debug_kit/debug_kit_app_controller.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* Debug Kit App Controller
|
||||
*
|
||||
*
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.
|
||||
* @since CakePHP v 1.2.0.4487
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
class DebugKitAppController extends AppController {
|
||||
|
||||
}
|
||||
?>
|
||||
32
plugins/debug_kit/debug_kit_app_model.php
Normal file
32
plugins/debug_kit/debug_kit_app_model.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* Debug Kit App Model
|
||||
*
|
||||
*
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.
|
||||
* @since CakePHP v 1.2.0.4487
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
class DebugKitAppModel extends AppModel {
|
||||
|
||||
}
|
||||
?>
|
||||
0
plugins/debug_kit/models/empty
Normal file
0
plugins/debug_kit/models/empty
Normal file
@@ -0,0 +1,323 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* DebugToolbar Test
|
||||
*
|
||||
*
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.
|
||||
* @since CakePHP v 1.2.0.4487
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
App::import('Component', 'DebugKit.Toolbar');
|
||||
|
||||
class TestToolbarComponent extends ToolbarComponent {
|
||||
|
||||
function loadPanels($panels) {
|
||||
$this->_loadPanels($panels);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Mock::generate('DebugPanel');
|
||||
|
||||
/**
|
||||
* DebugToolbar Test case
|
||||
*/
|
||||
class DebugToolbarTestCase extends CakeTestCase {
|
||||
|
||||
function setUp() {
|
||||
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
|
||||
Router::parse('/');
|
||||
$this->Controller =& ClassRegistry::init('Controller');
|
||||
$this->Controller->Component =& ClassRegistry::init('Component');
|
||||
$this->Controller->Toolbar =& ClassRegistry::init('TestToolBarComponent', 'Component');
|
||||
}
|
||||
|
||||
/**
|
||||
* test Loading of panel classes
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testLoadPanels() {
|
||||
$this->Controller->Toolbar->loadPanels(array('session', 'request'));
|
||||
$this->assertTrue(is_a($this->Controller->Toolbar->panels['session'], 'SessionPanel'));
|
||||
$this->assertTrue(is_a($this->Controller->Toolbar->panels['request'], 'RequestPanel'));
|
||||
|
||||
$this->expectError();
|
||||
$this->Controller->Toolbar->loadPanels(array('randomNonExisting', 'request'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test loading of vendor panels from test_app folder
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testVendorPanels() {
|
||||
$_back = Configure::read('vendorPaths');
|
||||
Configure::write('vendorPaths', array(APP . 'plugins' . DS . 'debug_kit' . DS . 'tests' . DS . 'test_app' . DS . 'vendors' . DS));
|
||||
$this->Controller->components = array(
|
||||
'DebugKit.Toolbar' => array(
|
||||
'panels' => array('test'),
|
||||
)
|
||||
);
|
||||
$this->Controller->Component->init($this->Controller);
|
||||
$this->Controller->Component->initialize($this->Controller);
|
||||
$this->Controller->Component->startup($this->Controller);
|
||||
$this->assertTrue(isset($this->Controller->Toolbar->panels['test']));
|
||||
$this->assertTrue(is_a($this->Controller->Toolbar->panels['test'], 'TestPanel'));
|
||||
|
||||
Configure::write('vendorPaths', $_back);
|
||||
}
|
||||
|
||||
/**
|
||||
* test initialize
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
**/
|
||||
function testInitialize() {
|
||||
$this->Controller->components = array('DebugKit.Toolbar');
|
||||
$this->Controller->Component->init($this->Controller);
|
||||
$this->Controller->Component->initialize($this->Controller);
|
||||
|
||||
$this->assertFalse(empty($this->Controller->Toolbar->panels));
|
||||
|
||||
$timers = DebugKitDebugger::getTimers();
|
||||
$this->assertTrue(isset($timers['componentInit']));
|
||||
}
|
||||
|
||||
/**
|
||||
* test startup
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testStartup() {
|
||||
$this->Controller->components = array(
|
||||
'DebugKit.Toolbar' => array(
|
||||
'panels' => array('MockDebug')
|
||||
)
|
||||
);
|
||||
$this->Controller->Component->init($this->Controller);
|
||||
$this->Controller->Component->initialize($this->Controller);
|
||||
$this->Controller->Toolbar->panels['MockDebug']->expectOnce('startup');
|
||||
$this->Controller->Toolbar->startup($this->Controller);
|
||||
|
||||
$this->assertEqual(count($this->Controller->Toolbar->panels), 1);
|
||||
$this->assertTrue(isset($this->Controller->helpers['DebugKit.Toolbar']));
|
||||
$this->assertEqual($this->Controller->helpers['DebugKit.Toolbar'], array('output' => 'DebugKit.HtmlToolbar'));
|
||||
|
||||
$timers = DebugKitDebugger::getTimers();
|
||||
$this->assertTrue(isset($timers['controllerAction']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Before Render callback
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testBeforeRender() {
|
||||
$this->Controller->components = array(
|
||||
'DebugKit.Toolbar' => array(
|
||||
'panels' => array('MockDebug', 'session')
|
||||
)
|
||||
);
|
||||
$this->Controller->Component->init($this->Controller);
|
||||
$this->Controller->Component->initialize($this->Controller);
|
||||
$this->Controller->Toolbar->panels['MockDebug']->expectOnce('beforeRender');
|
||||
$this->Controller->Toolbar->beforeRender($this->Controller);
|
||||
|
||||
$this->assertTrue(isset($this->Controller->viewVars['debugToolbarPanels']));
|
||||
$vars = $this->Controller->viewVars['debugToolbarPanels'];
|
||||
|
||||
$expected = array(
|
||||
'plugin' => 'debug_kit',
|
||||
'elementName' => 'session_panel',
|
||||
'content' => $this->Controller->Session->read(),
|
||||
'disableTimer' => true,
|
||||
);
|
||||
$this->assertEqual($expected, $vars['session']);
|
||||
}
|
||||
|
||||
/**
|
||||
* test alternate javascript library use
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testAlternateJavascript() {
|
||||
$this->Controller->components = array(
|
||||
'DebugKit.Toolbar'
|
||||
);
|
||||
$this->Controller->Component->init($this->Controller);
|
||||
$this->Controller->Component->initialize($this->Controller);
|
||||
$this->Controller->Component->startup($this->Controller);
|
||||
$this->Controller->Component->beforeRender($this->Controller);
|
||||
$this->assertTrue(isset($this->Controller->viewVars['debugToolbarJavascript']));
|
||||
$expected = array(
|
||||
'behavior' => '/debug_kit/js/js_debug_toolbar',
|
||||
);
|
||||
$this->assertEqual($this->Controller->viewVars['debugToolbarJavascript'], $expected);
|
||||
|
||||
$this->Controller->components = array(
|
||||
'DebugKit.Toolbar' => array(
|
||||
'javascript' => 'jquery',
|
||||
),
|
||||
);
|
||||
$this->Controller->Component->init($this->Controller);
|
||||
$this->Controller->Component->initialize($this->Controller);
|
||||
$this->Controller->Component->startup($this->Controller);
|
||||
$this->Controller->Component->beforeRender($this->Controller);
|
||||
$this->assertTrue(isset($this->Controller->viewVars['debugToolbarJavascript']));
|
||||
$expected = array(
|
||||
'behavior' => '/debug_kit/js/jquery_debug_toolbar.js',
|
||||
);
|
||||
$this->assertEqual($this->Controller->viewVars['debugToolbarJavascript'], $expected);
|
||||
|
||||
|
||||
$this->Controller->components = array(
|
||||
'DebugKit.Toolbar' => array(
|
||||
'javascript' => false
|
||||
)
|
||||
);
|
||||
$this->Controller->Component->init($this->Controller);
|
||||
$this->Controller->Component->initialize($this->Controller);
|
||||
$this->Controller->Component->startup($this->Controller);
|
||||
$this->Controller->Component->beforeRender($this->Controller);
|
||||
$this->assertTrue(isset($this->Controller->viewVars['debugToolbarJavascript']));
|
||||
$expected = array();
|
||||
$this->assertEqual($this->Controller->viewVars['debugToolbarJavascript'], $expected);
|
||||
|
||||
|
||||
$this->Controller->components = array(
|
||||
'DebugKit.Toolbar' => array(
|
||||
'javascript' => array('my_library'),
|
||||
),
|
||||
);
|
||||
$this->Controller->Component->init($this->Controller);
|
||||
$this->Controller->Component->initialize($this->Controller);
|
||||
$this->Controller->Component->startup($this->Controller);
|
||||
$this->Controller->Component->beforeRender($this->Controller);
|
||||
$this->assertTrue(isset($this->Controller->viewVars['debugToolbarJavascript']));
|
||||
$expected = array(
|
||||
'behavior' => 'my_library_debug_toolbar'
|
||||
);
|
||||
$this->assertEqual($this->Controller->viewVars['debugToolbarJavascript'], $expected);
|
||||
|
||||
$this->Controller->components = array(
|
||||
'DebugKit.Toolbar' => array(
|
||||
'javascript' => array('/my/path/to/file')
|
||||
),
|
||||
);
|
||||
$this->Controller->Component->init($this->Controller);
|
||||
$this->Controller->Component->initialize($this->Controller);
|
||||
$this->Controller->Component->startup($this->Controller);
|
||||
$this->Controller->Component->beforeRender($this->Controller);
|
||||
$this->assertTrue(isset($this->Controller->viewVars['debugToolbarJavascript']));
|
||||
$expected = array(
|
||||
'behavior' => '/my/path/to/file',
|
||||
);
|
||||
$this->assertEqual($this->Controller->viewVars['debugToolbarJavascript'], $expected);
|
||||
|
||||
$this->Controller->components = array(
|
||||
'DebugKit.Toolbar' => array(
|
||||
'javascript' => '/js/custom_behavior',
|
||||
),
|
||||
);
|
||||
$this->Controller->Component->init($this->Controller);
|
||||
$this->Controller->Component->initialize($this->Controller);
|
||||
$this->Controller->Component->startup($this->Controller);
|
||||
$this->Controller->Component->beforeRender($this->Controller);
|
||||
$this->assertTrue(isset($this->Controller->viewVars['debugToolbarJavascript']));
|
||||
$expected = array(
|
||||
'behavior' => '/js/custom_behavior',
|
||||
);
|
||||
$this->assertEqual($this->Controller->viewVars['debugToolbarJavascript'], $expected);
|
||||
}
|
||||
/**
|
||||
* Test alternate javascript existing in the plugin.
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testExistingAlterateJavascript() {
|
||||
$filename = APP . 'plugins' . DS . 'debug_kit' . DS . 'vendors' . DS . 'js' . DS . 'test_alternate_debug_toolbar.js';
|
||||
$this->skipIf(!is_writable(dirname($filename)), 'Skipping existing javascript test, debug_kit/vendors/js must be writable');
|
||||
|
||||
@touch($filename);
|
||||
$this->Controller->components = array(
|
||||
'DebugKit.Toolbar' => array(
|
||||
'javascript' => 'test_alternate',
|
||||
),
|
||||
);
|
||||
$this->Controller->Component->init($this->Controller);
|
||||
$this->Controller->Component->initialize($this->Controller);
|
||||
$this->Controller->Component->startup($this->Controller);
|
||||
$this->Controller->Component->beforeRender($this->Controller);
|
||||
$this->assertTrue(isset($this->Controller->viewVars['debugToolbarJavascript']));
|
||||
$expected = array(
|
||||
'behavior' => '/debug_kit/js/test_alternate_debug_toolbar.js',
|
||||
);
|
||||
$this->assertEqual($this->Controller->viewVars['debugToolbarJavascript'], $expected);
|
||||
@unlink($filename);
|
||||
}
|
||||
/**
|
||||
* test the Log panel log reading.
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testLogPanel() {
|
||||
usleep(20);
|
||||
$this->Controller->log('This is a log I made this request');
|
||||
$this->Controller->log('This is the second log I made this request');
|
||||
$this->Controller->log('This time in the debug log!', LOG_DEBUG);
|
||||
|
||||
$this->Controller->components = array(
|
||||
'DebugKit.Toolbar' => array(
|
||||
'panels' => array('log', 'session')
|
||||
)
|
||||
);
|
||||
$this->Controller->Component->init($this->Controller);
|
||||
$this->Controller->Component->initialize($this->Controller);
|
||||
$this->Controller->Component->startup($this->Controller);
|
||||
$this->Controller->Component->beforeRender($this->Controller);
|
||||
$result = $this->Controller->viewVars['debugToolbarPanels']['log'];
|
||||
|
||||
$this->assertEqual(count($result['content']), 2);
|
||||
$this->assertEqual(count($result['content']['error.log']), 4);
|
||||
$this->assertEqual(count($result['content']['debug.log']), 2);
|
||||
|
||||
$this->assertEqual(trim($result['content']['debug.log'][1]), 'Debug: This time in the debug log!');
|
||||
$this->assertEqual(trim($result['content']['error.log'][1]), 'Error: This is a log I made this request');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* teardown
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function tearDown() {
|
||||
unset($this->Controller);
|
||||
if (class_exists('DebugKitDebugger')) {
|
||||
DebugKitDebugger::clearTimers();
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
0
plugins/debug_kit/tests/cases/empty
Normal file
0
plugins/debug_kit/tests/cases/empty
Normal file
62
plugins/debug_kit/tests/cases/test_objects.php
Normal file
62
plugins/debug_kit/tests/cases/test_objects.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* Common test objects used in DebugKit tests
|
||||
*
|
||||
* Long description for file
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
||||
* Copyright 2005-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The Open Group Test Suite License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
|
||||
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
||||
* @package cake.tests
|
||||
* @subpackage cake.tests.cases.libs
|
||||
* @since CakePHP(tm) v 1.2.0.5432
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
/**
|
||||
* TestFireCake class allows for testing of FireCake
|
||||
*
|
||||
* @package debug_kit.tests.
|
||||
*/
|
||||
class TestFireCake extends FireCake {
|
||||
var $sentHeaders = array();
|
||||
|
||||
function _sendHeader($name, $value) {
|
||||
$_this = FireCake::getInstance();
|
||||
$_this->sentHeaders[$name] = $value;
|
||||
}
|
||||
/**
|
||||
* skip client detection as headers are not being sent.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function detectClientExtension() {
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Reset the fireCake
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function reset() {
|
||||
$_this = FireCake::getInstance();
|
||||
$_this->sentHeaders = array();
|
||||
$_this->_messageIndex = 1;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
157
plugins/debug_kit/tests/cases/vendors/debug_kit_debugger.test.php
vendored
Normal file
157
plugins/debug_kit/tests/cases/vendors/debug_kit_debugger.test.php
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* DebugKit Debugger Test Case File
|
||||
*
|
||||
* Long description for file
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
||||
* Copyright 2005-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The Open Group Test Suite License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
|
||||
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
||||
* @package cake.tests
|
||||
* @subpackage cake.tests.cases.libs
|
||||
* @since CakePHP(tm) v 1.2.0.5432
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
App::import('Core', 'Debugger');
|
||||
App::import('Vendor', 'DebugKit.DebugKitDebugger');
|
||||
|
||||
require_once APP . 'plugins' . DS . 'debug_kit' . DS . 'tests' . DS . 'cases' . DS . 'test_objects.php';
|
||||
|
||||
/**
|
||||
* Short description for class.
|
||||
*
|
||||
* @package cake.tests
|
||||
* @subpackage cake.tests.cases.libs
|
||||
*/
|
||||
class DebugKitDebuggerTest extends CakeTestCase {
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setUp() {
|
||||
Configure::write('log', false);
|
||||
if (!defined('SIMPLETESTVENDORPATH')) {
|
||||
if (file_exists(APP . DS . 'vendors' . DS . 'simpletest' . DS . 'reporter.php')) {
|
||||
define('SIMPLETESTVENDORPATH', 'APP' . DS . 'vendors');
|
||||
} else {
|
||||
define('SIMPLETESTVENDORPATH', 'CORE' . DS . 'vendors');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start Timer test
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testTimers() {
|
||||
$this->assertTrue(DebugKitDebugger::startTimer('test1', 'this is my first test'));
|
||||
usleep(5000);
|
||||
$this->assertTrue(DebugKitDebugger::stopTimer('test1'));
|
||||
$elapsed = DebugKitDebugger::elapsedTime('test1');
|
||||
$this->assertTrue($elapsed > 0.0050);
|
||||
|
||||
$this->assertTrue(DebugKitDebugger::startTimer('test2', 'this is my second test'));
|
||||
sleep(1);
|
||||
$this->assertTrue(DebugKitDebugger::stopTimer('test2'));
|
||||
$elapsed = DebugKitDebugger::elapsedTime('test2');
|
||||
$this->assertTrue($elapsed > 1);
|
||||
|
||||
DebugKitDebugger::startTimer('test3');
|
||||
$this->assertFalse(DebugKitDebugger::elapsedTime('test3'));
|
||||
$this->assertFalse(DebugKitDebugger::stopTimer('wrong'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testRequestTime
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testRequestTime() {
|
||||
$result1 = DebugKitDebugger::requestTime();
|
||||
usleep(50);
|
||||
$result2 = DebugKitDebugger::requestTime();
|
||||
$this->assertTrue($result1 < $result2);
|
||||
}
|
||||
|
||||
/**
|
||||
* test getting all the set timers.
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testGetTimers() {
|
||||
DebugKitDebugger::clearTimers();
|
||||
DebugKitDebugger::startTimer('test1', 'this is my first test');
|
||||
DebugKitDebugger::stopTimer('test1');
|
||||
usleep(50);
|
||||
DebugKitDebugger::startTimer('test2');
|
||||
DebugKitDebugger::stopTimer('test2');
|
||||
$timers = DebugKitDebugger::getTimers();
|
||||
|
||||
$this->assertEqual(count($timers), 2);
|
||||
$this->assertTrue(is_float($timers['test1']['time']));
|
||||
$this->assertTrue(isset($timers['test1']['message']));
|
||||
$this->assertTrue(isset($timers['test2']['message']));
|
||||
}
|
||||
|
||||
/**
|
||||
* test memory usage
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testMemoryUsage() {
|
||||
$result = DebugKitDebugger::getMemoryUse();
|
||||
$this->assertTrue(is_int($result));
|
||||
|
||||
$result = DebugKitDebugger::getPeakMemoryUse();
|
||||
$this->assertTrue(is_int($result));
|
||||
}
|
||||
/**
|
||||
* test _output switch to firePHP
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testOutput() {
|
||||
$firecake =& FireCake::getInstance('TestFireCake');
|
||||
Debugger::invoke(DebugKitDebugger::getInstance('DebugKitDebugger'));
|
||||
Debugger::output('fb');
|
||||
$foo .= '';
|
||||
$result = $firecake->sentHeaders;
|
||||
|
||||
$this->assertPattern('/GROUP_START/', $result['X-Wf-1-1-1-1']);
|
||||
$this->assertPattern('/ERROR/', $result['X-Wf-1-1-1-2']);
|
||||
$this->assertPattern('/GROUP_END/', $result['X-Wf-1-1-1-5']);
|
||||
|
||||
Debugger::invoke(Debugger::getInstance('Debugger'));
|
||||
Debugger::output();
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function tearDown() {
|
||||
Configure::write('log', true);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
336
plugins/debug_kit/tests/cases/vendors/fire_cake.test.php
vendored
Normal file
336
plugins/debug_kit/tests/cases/vendors/fire_cake.test.php
vendored
Normal file
@@ -0,0 +1,336 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* CakeFirePHP test case
|
||||
*
|
||||
*
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package debug_kit
|
||||
* @subpackage cake.debug_kit.tests
|
||||
* @since CakePHP v 1.2.0.4487
|
||||
* @version
|
||||
* @modifiedby
|
||||
* @lastmodified
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
App::import('Vendor', 'DebugKit.FireCake');
|
||||
|
||||
require_once APP . 'plugins' . DS . 'debug_kit' . DS . 'tests' . DS . 'cases' . DS . 'test_objects.php';
|
||||
/**
|
||||
* Test Case For FireCake
|
||||
*
|
||||
* @package debug_kit.tests
|
||||
*/
|
||||
class FireCakeTestCase extends CakeTestCase {
|
||||
/**
|
||||
* setup test
|
||||
*
|
||||
* Fill FireCake with TestFireCake instance.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function setUp() {
|
||||
$this->firecake =& FireCake::getInstance('TestFireCake');
|
||||
}
|
||||
/**
|
||||
* test getInstance cheat.
|
||||
*
|
||||
* If this fails the rest of the test is going to fail too.
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testGetInstanceOverride() {
|
||||
$instance =& FireCake::getInstance();
|
||||
$instance2 =& FireCake::getInstance();
|
||||
$this->assertReference($instance, $instance2);
|
||||
$this->assertIsA($instance, 'FireCake');
|
||||
$this->assertIsA($instance, 'TestFireCake', 'Stored instance is not a copy of TestFireCake, test case is broken.');
|
||||
}
|
||||
/**
|
||||
* testsetoption
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testSetOptions() {
|
||||
FireCake::setOptions(array('includeLineNumbers' => false));
|
||||
$this->assertEqual($this->firecake->options['includeLineNumbers'], false);
|
||||
}
|
||||
/**
|
||||
* test Log()
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testLog() {
|
||||
FireCake::setOptions(array('includeLineNumbers' => false));
|
||||
FireCake::log('Testing');
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-Protocol-1']));
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Plugin-1']));
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Structure-1']));
|
||||
$this->assertEqual($this->firecake->sentHeaders['X-Wf-1-Index'], 1);
|
||||
$this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-1'], '26|[{"Type":"LOG"},"Testing"]|');
|
||||
|
||||
FireCake::log('Testing', 'log-info');
|
||||
$this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-2'], '45|[{"Type":"LOG","Label":"log-info"},"Testing"]|');
|
||||
}
|
||||
/**
|
||||
* test info()
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testInfo() {
|
||||
FireCake::setOptions(array('includeLineNumbers' => false));
|
||||
FireCake::info('I have information');
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-Protocol-1']));
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Plugin-1']));
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Structure-1']));
|
||||
$this->assertEqual($this->firecake->sentHeaders['X-Wf-1-Index'], 1);
|
||||
$this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-1'], '38|[{"Type":"INFO"},"I have information"]|');
|
||||
|
||||
FireCake::info('I have information', 'info-label');
|
||||
$this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-2'], '59|[{"Type":"INFO","Label":"info-label"},"I have information"]|');
|
||||
}
|
||||
/**
|
||||
* test info()
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testWarn() {
|
||||
FireCake::setOptions(array('includeLineNumbers' => false));
|
||||
FireCake::warn('A Warning');
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-Protocol-1']));
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Plugin-1']));
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Structure-1']));
|
||||
$this->assertEqual($this->firecake->sentHeaders['X-Wf-1-Index'], 1);
|
||||
$this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-1'], '29|[{"Type":"WARN"},"A Warning"]|');
|
||||
|
||||
FireCake::warn('A Warning', 'Bzzz');
|
||||
$this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-2'], '44|[{"Type":"WARN","Label":"Bzzz"},"A Warning"]|');
|
||||
}
|
||||
/**
|
||||
* test error()
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
**/
|
||||
function testError() {
|
||||
FireCake::setOptions(array('includeLineNumbers' => false));
|
||||
FireCake::error('An error');
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-Protocol-1']));
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Plugin-1']));
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Structure-1']));
|
||||
$this->assertEqual($this->firecake->sentHeaders['X-Wf-1-Index'], 1);
|
||||
$this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-1'], '29|[{"Type":"ERROR"},"An error"]|');
|
||||
|
||||
FireCake::error('An error', 'wonky');
|
||||
$this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-2'], '45|[{"Type":"ERROR","Label":"wonky"},"An error"]|');
|
||||
}
|
||||
/**
|
||||
* test dump()
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testDump() {
|
||||
FireCake::dump('mydump', array('one' => 1, 'two' => 2));
|
||||
$this->assertEqual($this->firecake->sentHeaders['X-Wf-1-2-1-1'], '28|{"mydump":{"one":1,"two":2}}|');
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Structure-2']));
|
||||
}
|
||||
/**
|
||||
* test table() generation
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testTable() {
|
||||
$table[] = array('Col 1 Heading','Col 2 Heading');
|
||||
$table[] = array('Row 1 Col 1','Row 1 Col 2');
|
||||
$table[] = array('Row 2 Col 1','Row 2 Col 2');
|
||||
$table[] = array('Row 3 Col 1','Row 3 Col 2');
|
||||
FireCake::table('myTrace', $table);
|
||||
$expected = '162|[{"Type":"TABLE","Label":"myTrace"},[["Col 1 Heading","Col 2 Heading"],["Row 1 Col 1","Row 1 Col 2"],["Row 2 Col 1","Row 2 Col 2"],["Row 3 Col 1","Row 3 Col 2"]]]|';
|
||||
$this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-1'], $expected);
|
||||
}
|
||||
/**
|
||||
* testStringEncoding
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testStringEncode() {
|
||||
$result = $this->firecake->stringEncode(array(1,2,3));
|
||||
$this->assertEqual($result, array(1,2,3));
|
||||
|
||||
$this->firecake->setOptions(array('maxArrayDepth' => 3));
|
||||
$deep = array(1 => array(2 => array(3)));
|
||||
$result = $this->firecake->stringEncode($deep);
|
||||
$this->assertEqual($result, array(1 => array(2 => '** Max Array Depth (3) **')));
|
||||
|
||||
$obj =& FireCake::getInstance();
|
||||
$result = $this->firecake->stringEncode($obj);
|
||||
$this->assertTrue(is_array($result));
|
||||
$this->assertEqual($result['_defaultOptions']['useNativeJsonEncode'], true);
|
||||
$this->assertEqual($result['_log'], null);
|
||||
$this->assertEqual($result['_encodedObjects'][0], '** Recursion (TestFireCake) **');
|
||||
}
|
||||
/**
|
||||
* test trace()
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testTrace() {
|
||||
FireCake::trace('myTrace');
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-Protocol-1']));
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Plugin-1']));
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Structure-1']));
|
||||
$dump = $this->firecake->sentHeaders['X-Wf-1-1-1-1'];
|
||||
$this->assertPattern('/"Message":"myTrace"/', $dump);
|
||||
$this->assertPattern('/"Trace":\[/', $dump);
|
||||
}
|
||||
/**
|
||||
* test enabling and disabling of FireCake output
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testEnableDisable() {
|
||||
FireCake::disable();
|
||||
FireCake::trace('myTrace');
|
||||
$this->assertTrue(empty($this->firecake->sentHeaders));
|
||||
|
||||
FireCake::enable();
|
||||
FireCake::trace('myTrace');
|
||||
$this->assertFalse(empty($this->firecake->sentHeaders));
|
||||
}
|
||||
/**
|
||||
* test correct line continuation markers on multi line headers.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testMultiLineOutput() {
|
||||
FireCake::trace('myTrace');
|
||||
$this->assertEqual($this->firecake->sentHeaders['X-Wf-1-Index'], 3);
|
||||
$header = $this->firecake->sentHeaders['X-Wf-1-1-1-1'];
|
||||
$this->assertEqual(substr($header, -2), '|\\');
|
||||
|
||||
$header = $this->firecake->sentHeaders['X-Wf-1-1-1-2'];
|
||||
$this->assertEqual(substr($header, -2), '|\\');
|
||||
|
||||
$header = $this->firecake->sentHeaders['X-Wf-1-1-1-3'];
|
||||
$this->assertEqual(substr($header, -1), '|');
|
||||
}
|
||||
|
||||
/**
|
||||
* test inclusion of line numbers
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testIncludeLineNumbers() {
|
||||
FireCake::setOptions(array('includeLineNumbers' => true));
|
||||
FireCake::info('Testing');
|
||||
$result = $this->firecake->sentHeaders['X-Wf-1-1-1-1'];
|
||||
$this->assertPattern('/"File"\:"APP.*fire_cake.test.php/', $result);
|
||||
$this->assertPattern('/"Line"\:\d+/', $result);
|
||||
}
|
||||
/**
|
||||
* test Group messages
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testGroup() {
|
||||
FireCake::setOptions(array('includeLineNumbers' => false));
|
||||
FireCake::group('test');
|
||||
FireCake::info('my info');
|
||||
FireCake::groupEnd();
|
||||
$this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-1'], '44|[{"Type":"GROUP_START","Label":"test"},null]|');
|
||||
$this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-3'], '27|[{"Type":"GROUP_END"},null]|');
|
||||
$this->assertEqual($this->firecake->sentHeaders['X-Wf-1-Index'], 3);
|
||||
}
|
||||
/**
|
||||
* test fb() parameter parsing
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testFbParameterParsing() {
|
||||
FireCake::setOptions(array('includeLineNumbers' => false));
|
||||
FireCake::fb('Test');
|
||||
$this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-1'], '23|[{"Type":"LOG"},"Test"]|');
|
||||
|
||||
FireCake::fb('Test', 'warn');
|
||||
$this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-2'], '24|[{"Type":"WARN"},"Test"]|');
|
||||
|
||||
FireCake::fb('Test', 'Custom label', 'warn');
|
||||
$this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-3'], '47|[{"Type":"WARN","Label":"Custom label"},"Test"]|');
|
||||
|
||||
$this->expectError();
|
||||
$this->assertFalse(FireCake::fb('Test', 'Custom label', 'warn', 'more parameters'));
|
||||
|
||||
$this->assertEqual($this->firecake->sentHeaders['X-Wf-1-Index'], 3);
|
||||
}
|
||||
/**
|
||||
* Test defaulting to log if incorrect message type is used
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testIncorrectMessageType() {
|
||||
FireCake::setOptions(array('includeLineNumbers' => false));
|
||||
FireCake::fb('Hello World', 'foobared');
|
||||
$this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-1'], '30|[{"Type":"LOG"},"Hello World"]|');
|
||||
}
|
||||
/**
|
||||
* testClientExtensionDetection.
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testDetectClientExtension() {
|
||||
$back = env('HTTP_USER_AGENT');
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4 FirePHP/0.2.1';
|
||||
$this->assertTrue(FireCake::detectClientExtension());
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4 FirePHP/0.0.4';
|
||||
$this->assertFalse(FireCake::detectClientExtension());
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4';
|
||||
$this->assertFalse(FireCake::detectClientExtension());
|
||||
$_SERVER['HTTP_USER_AGENT'] = $back;
|
||||
}
|
||||
/**
|
||||
* test of Non Native JSON encoding.
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testNonNativeEncoding() {
|
||||
FireCake::setOptions(array('useNativeJsonEncode' => false));
|
||||
$json = FireCake::jsonEncode(array('one' => 1, 'two' => 2));
|
||||
$this->assertEqual($json, '{"one":1,"two":2}');
|
||||
|
||||
$json = FireCake::jsonEncode(array(1,2,3));
|
||||
$this->assertEqual($json, '[1,2,3]');
|
||||
|
||||
$json = FireCake::jsonEncode(FireCake::getInstance());
|
||||
$this->assertPattern('/"options"\:\{"maxObjectDepth"\:\d*,/', $json);
|
||||
}
|
||||
/**
|
||||
* reset the FireCake counters and headers.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function tearDown() {
|
||||
TestFireCake::reset();
|
||||
}
|
||||
}
|
||||
?>
|
||||
144
plugins/debug_kit/tests/cases/views/debug.test.php
Normal file
144
plugins/debug_kit/tests/cases/views/debug.test.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* DebugView test Case
|
||||
*
|
||||
*
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.
|
||||
* @since CakePHP v 1.2.0.4487
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
App::import('Core', 'View');
|
||||
|
||||
if (!class_exists('DoppelGangerView')) {
|
||||
class DoppelGangerView extends View {}
|
||||
}
|
||||
|
||||
App::import('View', 'DebugKit.Debug');
|
||||
App::import('Vendor', 'DebugKit.DebugKitDebugger');
|
||||
/**
|
||||
* Debug View Test Case
|
||||
*
|
||||
* @package debug_kit.tests
|
||||
*/
|
||||
class DebugViewTestCase extends CakeTestCase {
|
||||
/**
|
||||
* set Up test case
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function setUp() {
|
||||
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
|
||||
Router::parse('/');
|
||||
$this->Controller =& ClassRegistry::init('Controller');
|
||||
$this->View =& new DebugView($this->Controller, false);
|
||||
$this->_debug = Configure::read('debug');
|
||||
}
|
||||
|
||||
/**
|
||||
* start Case - switch view paths
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function startCase() {
|
||||
$this->_viewPaths = Configure::read('viewPaths');
|
||||
Configure::write('viewPaths', array(
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS,
|
||||
APP . 'plugins' . DS . 'debug_kit' . DS . 'views'. DS,
|
||||
ROOT . DS . LIBS . 'view' . DS
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* test that element timers are working
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testElementTimers() {
|
||||
$result = $this->View->element('test_element');
|
||||
$this->assertPattern('/^this is the test element$/', $result);
|
||||
|
||||
$result = DebugKitDebugger::getTimers();
|
||||
$this->assertTrue(isset($result['render_test_element.ctp']));
|
||||
}
|
||||
|
||||
/**
|
||||
* test rendering and ensure that timers are being set.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testRenderTimers() {
|
||||
$this->Controller->viewPath = 'posts';
|
||||
$this->Controller->action = 'index';
|
||||
$this->Controller->params = array(
|
||||
'action' => 'index',
|
||||
'controller' => 'posts',
|
||||
'plugin' => null,
|
||||
'url' => array('url' => 'posts/index'),
|
||||
'base' => null,
|
||||
'here' => '/posts/index',
|
||||
);
|
||||
$this->Controller->layout = 'default';
|
||||
$View =& new DebugView($this->Controller, false);
|
||||
$View->render('index');
|
||||
|
||||
$result = DebugKitDebugger::getTimers();
|
||||
$this->assertEqual(count($result), 3);
|
||||
$this->assertTrue(isset($result['viewRender']));
|
||||
$this->assertTrue(isset($result['render_default.ctp']));
|
||||
$this->assertTrue(isset($result['render_index.ctp']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for correct loading of helpers into custom view
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testLoadHelpers() {
|
||||
$loaded = array();
|
||||
$result = $this->View->_loadHelpers($loaded, array('Html', 'Javascript', 'Number'));
|
||||
$this->assertTrue(is_object($result['Html']));
|
||||
$this->assertTrue(is_object($result['Javascript']));
|
||||
$this->assertTrue(is_object($result['Number']));
|
||||
}
|
||||
|
||||
/**
|
||||
* reset the view paths
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function endCase() {
|
||||
Configure::write('viewPaths', $this->_viewPaths);
|
||||
}
|
||||
|
||||
/**
|
||||
* tear down function
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function tearDown() {
|
||||
unset($this->View, $this->Controller);
|
||||
DebugKitDebugger::clearTimers();
|
||||
Configure::write('debug', $this->_debug);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* Toolbar Abstract Helper Test Case
|
||||
*
|
||||
*
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage debug_kit.tests.views.helpers
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
App::import('Helper', 'DebugKit.FirePhpToolbar');
|
||||
App::import('Core', array('View', 'Controller'));
|
||||
require_once APP . 'plugins' . DS . 'debug_kit' . DS . 'tests' . DS . 'cases' . DS . 'test_objects.php';
|
||||
|
||||
FireCake::getInstance('TestFireCake');
|
||||
|
||||
class FirePhpToolbarHelperTestCase extends CakeTestCase {
|
||||
/**
|
||||
* setUp
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function setUp() {
|
||||
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
|
||||
Router::parse('/');
|
||||
|
||||
$this->Toolbar =& new ToolbarHelper(array('output' => 'DebugKit.FirePhpToolbar'));
|
||||
$this->Toolbar->FirePhpToolbar =& new FirePhpToolbarHelper();
|
||||
|
||||
$this->Controller =& ClassRegistry::init('Controller');
|
||||
if (isset($this->_debug)) {
|
||||
Configure::write('debug', $this->_debug);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* start Case - switch view paths
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function startCase() {
|
||||
$this->_viewPaths = Configure::read('viewPaths');
|
||||
Configure::write('viewPaths', array(
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS,
|
||||
APP . 'plugins' . DS . 'debug_kit' . DS . 'views'. DS,
|
||||
ROOT . DS . LIBS . 'view' . DS
|
||||
));
|
||||
$this->_debug = Configure::read('debug');
|
||||
$this->firecake =& FireCake::getInstance();
|
||||
}
|
||||
/**
|
||||
* test neat array (dump)creation
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testMakeNeatArray() {
|
||||
$this->Toolbar->makeNeatArray(array(1,2,3));
|
||||
$result = $this->firecake->sentHeaders;
|
||||
$this->assertTrue(isset($result['X-Wf-1-1-1-1']));
|
||||
$this->assertPattern('/\[1,2,3\]/', $result['X-Wf-1-1-1-1']);
|
||||
}
|
||||
/**
|
||||
* testAfterlayout element rendering
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testAfterLayout(){
|
||||
$this->Controller->viewPath = 'posts';
|
||||
$this->Controller->action = 'index';
|
||||
$this->Controller->params = array(
|
||||
'action' => 'index',
|
||||
'controller' => 'posts',
|
||||
'plugin' => null,
|
||||
'url' => array('url' => 'posts/index', 'ext' => 'xml'),
|
||||
'base' => null,
|
||||
'here' => '/posts/index',
|
||||
);
|
||||
$this->Controller->layout = 'default';
|
||||
$this->Controller->uses = null;
|
||||
$this->Controller->components = array('DebugKit.Toolbar');
|
||||
$this->Controller->constructClasses();
|
||||
$this->Controller->Component->initialize($this->Controller);
|
||||
$this->Controller->Component->startup($this->Controller);
|
||||
$this->Controller->Component->beforeRender($this->Controller);
|
||||
$result = $this->Controller->render();
|
||||
$this->assertNoPattern('/debug-toolbar/', $result);
|
||||
$result = $this->firecake->sentHeaders;
|
||||
$this->assertTrue(is_array($result));
|
||||
|
||||
}
|
||||
/**
|
||||
* endTest()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function endTest() {
|
||||
TestFireCake::reset();
|
||||
}
|
||||
/**
|
||||
* reset the view paths
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function endCase() {
|
||||
Configure::write('viewPaths', $this->_viewPaths);
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function tearDown() {
|
||||
unset($this->Toolbar, $this->Controller);
|
||||
ClassRegistry::removeObject('view');
|
||||
ClassRegistry::flush();
|
||||
Router::reload();
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,358 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* Toolbar HTML Helper Test Case
|
||||
*
|
||||
*
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage debug_kit.tests.views.helpers
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
App::import('Helper', array('DebugKit.HtmlToolbar', 'Html', 'Javascript'));
|
||||
App::import('Core', array('View', 'Controller'));
|
||||
|
||||
class HtmlToolbarHelperTestCase extends CakeTestCase {
|
||||
/**
|
||||
* setUp
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function setUp() {
|
||||
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
|
||||
Router::parse('/');
|
||||
|
||||
$this->Toolbar =& new ToolbarHelper(array('output' => 'DebugKit.HtmlToolbar'));
|
||||
$this->Toolbar->HtmlToolbar =& new HtmlToolbarHelper();
|
||||
$this->Toolbar->HtmlToolbar->Html =& new HtmlHelper();
|
||||
$this->Toolbar->HtmlToolbar->Javascript =& new JavascriptHelper();
|
||||
|
||||
$this->Controller =& ClassRegistry::init('Controller');
|
||||
if (isset($this->_debug)) {
|
||||
Configure::write('debug', $this->_debug);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* start Case - switch view paths
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function startCase() {
|
||||
$this->_viewPaths = Configure::read('viewPaths');
|
||||
Configure::write('viewPaths', array(
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS,
|
||||
APP . 'plugins' . DS . 'debug_kit' . DS . 'views'. DS,
|
||||
ROOT . DS . LIBS . 'view' . DS
|
||||
));
|
||||
$this->_debug = Configure::read('debug');
|
||||
}
|
||||
|
||||
/**
|
||||
* test Neat Array formatting
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testMakeNeatArray() {
|
||||
$in = false;
|
||||
$result = $this->Toolbar->makeNeatArray($in);
|
||||
$expected = array(
|
||||
'ul' => array('class' => 'neat-array depth-0'),
|
||||
'<li', '<strong', '0' , '/strong', '(false)', '/li',
|
||||
'/ul'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$in = null;
|
||||
$result = $this->Toolbar->makeNeatArray($in);
|
||||
$expected = array(
|
||||
'ul' => array('class' => 'neat-array depth-0'),
|
||||
'<li', '<strong', '0' , '/strong', '(null)', '/li',
|
||||
'/ul'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$in = true;
|
||||
$result = $this->Toolbar->makeNeatArray($in);
|
||||
$expected = array(
|
||||
'ul' => array('class' => 'neat-array depth-0'),
|
||||
'<li', '<strong', '0' , '/strong', '(true)', '/li',
|
||||
'/ul'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$in = array('key' => 'value');
|
||||
$result = $this->Toolbar->makeNeatArray($in);
|
||||
$expected = array(
|
||||
'ul' => array('class' => 'neat-array depth-0'),
|
||||
'<li', '<strong', 'key', '/strong', 'value', '/li',
|
||||
'/ul'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$in = array('key' => null);
|
||||
$result = $this->Toolbar->makeNeatArray($in);
|
||||
$expected = array(
|
||||
'ul' => array('class' => 'neat-array depth-0'),
|
||||
'<li', '<strong', 'key', '/strong', '(null)', '/li',
|
||||
'/ul'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$in = array('key' => 'value', 'foo' => 'bar');
|
||||
$result = $this->Toolbar->makeNeatArray($in);
|
||||
$expected = array(
|
||||
'ul' => array('class' => 'neat-array depth-0'),
|
||||
'<li', '<strong', 'key', '/strong', 'value', '/li',
|
||||
'<li', '<strong', 'foo', '/strong', 'bar', '/li',
|
||||
'/ul'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$in = array(
|
||||
'key' => 'value',
|
||||
'foo' => array(
|
||||
'this' => 'deep',
|
||||
'another' => 'value'
|
||||
)
|
||||
);
|
||||
$result = $this->Toolbar->makeNeatArray($in);
|
||||
$expected = array(
|
||||
'ul' => array('class' => 'neat-array depth-0'),
|
||||
'<li', '<strong', 'key', '/strong', 'value', '/li',
|
||||
'<li', '<strong', 'foo', '/strong',
|
||||
array('ul' => array('class' => 'neat-array depth-1')),
|
||||
'<li', '<strong', 'this', '/strong', 'deep', '/li',
|
||||
'<li', '<strong', 'another', '/strong', 'value', '/li',
|
||||
'/ul',
|
||||
'/li',
|
||||
'/ul'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$in = array(
|
||||
'key' => 'value',
|
||||
'foo' => array(
|
||||
'this' => 'deep',
|
||||
'another' => 'value'
|
||||
),
|
||||
'lotr' => array(
|
||||
'gandalf' => 'wizard',
|
||||
'bilbo' => 'hobbit'
|
||||
)
|
||||
);
|
||||
$result = $this->Toolbar->makeNeatArray($in, 1);
|
||||
$expected = array(
|
||||
'ul' => array('class' => 'neat-array depth-0 expanded'),
|
||||
'<li', '<strong', 'key', '/strong', 'value', '/li',
|
||||
'<li', '<strong', 'foo', '/strong',
|
||||
array('ul' => array('class' => 'neat-array depth-1')),
|
||||
'<li', '<strong', 'this', '/strong', 'deep', '/li',
|
||||
'<li', '<strong', 'another', '/strong', 'value', '/li',
|
||||
'/ul',
|
||||
'/li',
|
||||
'<li', '<strong', 'lotr', '/strong',
|
||||
array('ul' => array('class' => 'neat-array depth-1')),
|
||||
'<li', '<strong', 'gandalf', '/strong', 'wizard', '/li',
|
||||
'<li', '<strong', 'bilbo', '/strong', 'hobbit', '/li',
|
||||
'/ul',
|
||||
'/li',
|
||||
'/ul'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Toolbar->makeNeatArray($in, 2);
|
||||
$expected = array(
|
||||
'ul' => array('class' => 'neat-array depth-0 expanded'),
|
||||
'<li', '<strong', 'key', '/strong', 'value', '/li',
|
||||
'<li', '<strong', 'foo', '/strong',
|
||||
array('ul' => array('class' => 'neat-array depth-1 expanded')),
|
||||
'<li', '<strong', 'this', '/strong', 'deep', '/li',
|
||||
'<li', '<strong', 'another', '/strong', 'value', '/li',
|
||||
'/ul',
|
||||
'/li',
|
||||
'<li', '<strong', 'lotr', '/strong',
|
||||
array('ul' => array('class' => 'neat-array depth-1 expanded')),
|
||||
'<li', '<strong', 'gandalf', '/strong', 'wizard', '/li',
|
||||
'<li', '<strong', 'bilbo', '/strong', 'hobbit', '/li',
|
||||
'/ul',
|
||||
'/li',
|
||||
'/ul'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$in = array('key' => 'value', 'array' => array());
|
||||
$result = $this->Toolbar->makeNeatArray($in);
|
||||
$expected = array(
|
||||
'ul' => array('class' => 'neat-array depth-0'),
|
||||
'<li', '<strong', 'key', '/strong', 'value', '/li',
|
||||
'<li', '<strong', 'array', '/strong', '(empty)', '/li',
|
||||
'/ul'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test injection of toolbar
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testInjectToolbar() {
|
||||
$this->Controller->viewPath = 'posts';
|
||||
$this->Controller->action = 'index';
|
||||
$this->Controller->params = array(
|
||||
'action' => 'index',
|
||||
'controller' => 'posts',
|
||||
'plugin' => null,
|
||||
'url' => array('url' => 'posts/index'),
|
||||
'base' => null,
|
||||
'here' => '/posts/index',
|
||||
);
|
||||
$this->Controller->helpers = array('Html', 'Javascript', 'DebugKit.Toolbar');
|
||||
$this->Controller->layout = 'default';
|
||||
$this->Controller->uses = null;
|
||||
$this->Controller->components = array('DebugKit.Toolbar');
|
||||
$this->Controller->constructClasses();
|
||||
$this->Controller->Component->initialize($this->Controller);
|
||||
$this->Controller->Component->startup($this->Controller);
|
||||
$this->Controller->Component->beforeRender($this->Controller);
|
||||
$result = $this->Controller->render();
|
||||
$result = str_replace(array("\n", "\r"), '', $result);
|
||||
$this->assertPattern('#<div id\="debug-kit-toolbar">.+</div></body>#', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test injection of javascript
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testJavascriptInjection() {
|
||||
$this->Controller->viewPath = 'posts';
|
||||
$this->Controller->uses = null;
|
||||
$this->Controller->action = 'index';
|
||||
$this->Controller->params = array(
|
||||
'action' => 'index',
|
||||
'controller' => 'posts',
|
||||
'plugin' => null,
|
||||
'url' => array('url' => 'posts/index'),
|
||||
'base' => '/',
|
||||
'here' => '/posts/index',
|
||||
);
|
||||
$this->Controller->helpers = array('Javascript', 'Html');
|
||||
$this->Controller->components = array('DebugKit.Toolbar');
|
||||
$this->Controller->layout = 'default';
|
||||
$this->Controller->constructClasses();
|
||||
$this->Controller->Component->initialize($this->Controller);
|
||||
$this->Controller->Component->startup($this->Controller);
|
||||
$this->Controller->Component->beforeRender($this->Controller);
|
||||
$result = $this->Controller->render();
|
||||
$result = str_replace(array("\n", "\r"), '', $result);
|
||||
$this->assertPattern('#<script\s*type="text/javascript"\s*src="/debug_kit/js/js_debug_toolbar.js"\s*>\s?</script>#', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test Injection of user defined javascript
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testCustomJavascriptInjection() {
|
||||
$this->Controller->viewPath = 'posts';
|
||||
$this->Controller->uses = null;
|
||||
$this->Controller->action = 'index';
|
||||
$this->Controller->params = array(
|
||||
'action' => 'index',
|
||||
'controller' => 'posts',
|
||||
'plugin' => null,
|
||||
'url' => array('url' => 'posts/index'),
|
||||
'base' => '/',
|
||||
'here' => '/posts/index',
|
||||
);
|
||||
$this->Controller->helpers = array('Javascript', 'Html');
|
||||
$this->Controller->components = array('DebugKit.Toolbar' => array('javascript' => array('my_custom')));
|
||||
$this->Controller->layout = 'default';
|
||||
$this->Controller->constructClasses();
|
||||
$this->Controller->Component->initialize($this->Controller);
|
||||
$this->Controller->Component->startup($this->Controller);
|
||||
$this->Controller->Component->beforeRender($this->Controller);
|
||||
$result = $this->Controller->render();
|
||||
$result = str_replace(array("\n", "\r"), '', $result);
|
||||
$this->assertPattern('#<script\s*type="text/javascript"\s*src="js/my_custom_debug_toolbar.js"\s*>\s?</script>#', $result);
|
||||
}
|
||||
/**
|
||||
* test message creation
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testMessage() {
|
||||
$result = $this->Toolbar->message('test', 'one, two');
|
||||
$expected = array(
|
||||
'<p',
|
||||
'<strong', 'test', '/strong',
|
||||
' one, two',
|
||||
'/p',
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
}
|
||||
/**
|
||||
* Test Table generation
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testTable() {
|
||||
$rows = array(
|
||||
array(1,2),
|
||||
array(3,4),
|
||||
);
|
||||
$result = $this->Toolbar->table($rows);
|
||||
$expected = array(
|
||||
'table' => array('class' =>'debug-table'),
|
||||
array('tr' => array('class' => 'odd')),
|
||||
'<td', '1', '/td',
|
||||
'<td', '2', '/td',
|
||||
'/tr',
|
||||
array('tr' => array('class' => 'even')),
|
||||
'<td', '3', '/td',
|
||||
'<td', '4', '/td',
|
||||
'/tr',
|
||||
'/table'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
}
|
||||
/**
|
||||
* reset the view paths
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function endCase() {
|
||||
Configure::write('viewPaths', $this->_viewPaths);
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function tearDown() {
|
||||
unset($this->Toolbar, $this->Controller);
|
||||
ClassRegistry::removeObject('view');
|
||||
ClassRegistry::flush();
|
||||
}
|
||||
}
|
||||
?>
|
||||
0
plugins/debug_kit/tests/fixtures/empty
vendored
Normal file
0
plugins/debug_kit/tests/fixtures/empty
vendored
Normal file
0
plugins/debug_kit/tests/groups/empty
Normal file
0
plugins/debug_kit/tests/groups/empty
Normal file
33
plugins/debug_kit/tests/test_app/vendors/test_panel.php
vendored
Normal file
33
plugins/debug_kit/tests/test_app/vendors/test_panel.php
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* Test Panel
|
||||
*
|
||||
*
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake.debug_kit
|
||||
* @subpackage cake.debug_kit.tests
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
class TestPanel extends DebugPanel {
|
||||
function startup(&$controller) {
|
||||
$controller->testPanel = true;
|
||||
}
|
||||
}
|
||||
?>
|
||||
165
plugins/debug_kit/vendors/css/debug_toolbar.css
vendored
Normal file
165
plugins/debug_kit/vendors/css/debug_toolbar.css
vendored
Normal file
@@ -0,0 +1,165 @@
|
||||
/* @override http://localhost/cake_debug_kit/debug_kit/css/debug_toolbar.css */
|
||||
#debug-kit-toolbar {
|
||||
position: fixed;
|
||||
top: 0px;
|
||||
right:0px;
|
||||
width: 100%;
|
||||
height: 1%;
|
||||
overflow: visible;
|
||||
z-index:10000;
|
||||
}
|
||||
/* panel tabs */
|
||||
#debug-kit-toolbar #panel-tabs {
|
||||
float: right;
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
}
|
||||
#debug-kit-toolbar .panel-tab {
|
||||
clear: none;
|
||||
float: left;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
#debug-kit-toolbar .panel-tab a {
|
||||
float: left;
|
||||
clear: none;
|
||||
background: #efefef;
|
||||
color: #222;
|
||||
padding: 6px;
|
||||
border-right: 1px solid #ccc;
|
||||
font-size: 12px;
|
||||
line-height: 16px;
|
||||
margin: 0;
|
||||
display: block;
|
||||
}
|
||||
#debug-kit-toolbar .panel-tab .active,
|
||||
#debug-kit-toolbar .panel-tab a:hover {
|
||||
background: #fff;
|
||||
}
|
||||
#debug-kit-toolbar .panel-tab.icon a {
|
||||
padding: 4px;
|
||||
}
|
||||
|
||||
/* Hovering over link shows tab, useful for no js */
|
||||
#debug-kit-toolbar .panel-tab a:hover + .panel-content,
|
||||
#debug-kit-toolbar .panel-tab a + .panel-content:hover {
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* panel content */
|
||||
#debug-kit-toolbar .panel-content {
|
||||
position: absolute;
|
||||
text-align: left;
|
||||
width: auto;
|
||||
top:28px;
|
||||
right:0px;
|
||||
background: #fff;
|
||||
color: #000;
|
||||
width:96%;
|
||||
padding:20px 2%;
|
||||
max-height: 550px;
|
||||
overflow:auto;
|
||||
border-bottom: 3px solid #333;
|
||||
}
|
||||
|
||||
/* Hide panel content by default */
|
||||
.panel-content {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.panel-content p {
|
||||
margin: 1em 0;
|
||||
}
|
||||
.panel-content h2 {
|
||||
padding: 0;
|
||||
margin-top:0;
|
||||
}
|
||||
.panel-content h3 {
|
||||
padding: 0;
|
||||
margin-top: 1em;
|
||||
}
|
||||
.panel-content .info {
|
||||
padding: 4px;
|
||||
border-top: 1px dashed #6c6cff;
|
||||
border-bottom: 1px dashed #6c6cff;
|
||||
}
|
||||
|
||||
/* panel tables */
|
||||
table.debug-table {
|
||||
width: auto;
|
||||
border: 0;
|
||||
}
|
||||
table.debug-table td,
|
||||
table.debug-table th {
|
||||
text-align: left;
|
||||
border: 0;
|
||||
padding: 3px;
|
||||
}
|
||||
table.debug-table th {
|
||||
border-bottom: 1px solid #222;
|
||||
background: 0;;
|
||||
}
|
||||
table.debug-table tr.even td {
|
||||
background:#efefef;
|
||||
}
|
||||
|
||||
/** code tables **/
|
||||
#debug-kit-toolbar .code-table td {
|
||||
white-space: pre;
|
||||
font-family: monaco, corsiva, "courier new", courier, monospaced;
|
||||
}
|
||||
#debug-kit-toolbar .code-table td:first-child {
|
||||
width: 15%;
|
||||
}
|
||||
#debug-kit-toolbar .code-table td:last-child {
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
|
||||
.panel-content.request {
|
||||
display: block;
|
||||
}
|
||||
|
||||
|
||||
/** Neat Array styles **/
|
||||
.neat-array {
|
||||
padding: 1px 2px 1px 20px;
|
||||
background: #CE9E23;
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
}
|
||||
.neat-array .neat-array {
|
||||
padding: 0 0 0 20px;
|
||||
}
|
||||
.neat-array li {
|
||||
background: #FEF6E5;
|
||||
border-top: 1px solid #CE9E23;
|
||||
border-bottom: 1px solid #CE9E23;
|
||||
margin: 0;
|
||||
line-height: 1.5em;
|
||||
}
|
||||
.neat-array li:hover {
|
||||
background: #fff;
|
||||
}
|
||||
.neat-array li strong {
|
||||
padding: 0 8px;
|
||||
}
|
||||
|
||||
/* expandable sections */
|
||||
.neat-array li.expandable {
|
||||
cursor: pointer;
|
||||
}
|
||||
.neat-array li.expandable.expanded > strong:before {
|
||||
content: 'v ';
|
||||
}
|
||||
.neat-array li.expandable.collapsed > strong:before,
|
||||
.neat-array li.expandable.expanded .expandable.collapsed > strong:before {
|
||||
content: '> ';
|
||||
}
|
||||
|
||||
.neat-array li {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
226
plugins/debug_kit/vendors/debug_kit_debugger.php
vendored
Normal file
226
plugins/debug_kit/vendors/debug_kit_debugger.php
vendored
Normal file
@@ -0,0 +1,226 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* DebugKit Debugger class. Extends and enhances core
|
||||
* debugger. Adds benchmarking and timing functionality.
|
||||
*
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.
|
||||
* @since CakePHP v 1.2.0.4487
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
App::import('Core', 'Debugger');
|
||||
App::import('Vendor', 'DebugKit.FireCake');
|
||||
/**
|
||||
* Debug Kit Temporary Debugger Class
|
||||
*
|
||||
* Provides the future features that are planned. Yet not implemented in the 1.2 code base
|
||||
*
|
||||
* This file will not be needed in future version of CakePHP.
|
||||
* @todo merge these changes with core Debugger
|
||||
*/
|
||||
class DebugKitDebugger extends Debugger {
|
||||
|
||||
/**
|
||||
* Start an benchmarking timer.
|
||||
*
|
||||
* @param string $name The name of the timer to start.
|
||||
* @param string $message A message for your timer
|
||||
* @return bool true
|
||||
* @static
|
||||
**/
|
||||
function startTimer($name = 'default', $message = '') {
|
||||
$now = getMicrotime();
|
||||
$_this = DebugKitDebugger::getInstance();
|
||||
$_this->__benchmarks[$name] = array(
|
||||
'start' => $now,
|
||||
'message' => $message,
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop a benchmarking timer.
|
||||
*
|
||||
* $name should be the same as the $name used in startTimer().
|
||||
*
|
||||
* @param string $name The name of the timer to end.
|
||||
* @access public
|
||||
* @return boolean true if timer was ended, false if timer was not started.
|
||||
* @static
|
||||
*/
|
||||
function stopTimer($name = 'default') {
|
||||
$now = getMicrotime();
|
||||
$_this = DebugKitDebugger::getInstance();
|
||||
if (!isset($_this->__benchmarks[$name])) {
|
||||
return false;
|
||||
}
|
||||
$_this->__benchmarks[$name]['end'] = $now;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all timers that have been started and stopped.
|
||||
* Calculates elapsed time for each timer.
|
||||
*
|
||||
* @return array
|
||||
**/
|
||||
function getTimers() {
|
||||
$_this =& DebugKitDebugger::getInstance();
|
||||
$times = array();
|
||||
foreach ($_this->__benchmarks as $name => $timer) {
|
||||
$times[$name]['time'] = DebugKitDebugger::elapsedTime($name);
|
||||
$times[$name]['message'] = $timer['message'];
|
||||
}
|
||||
return $times;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all existing timers
|
||||
*
|
||||
* @return bool true
|
||||
**/
|
||||
function clearTimers() {
|
||||
$_this =& DebugKitDebugger::getInstance();
|
||||
$_this->__benchmarks = array();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the difference in time between the timer start and timer end.
|
||||
*
|
||||
* @param $name string the name of the timer you want elapsed time for.
|
||||
* @param $precision int the number of decimal places to return, defaults to 5.
|
||||
* @return float number of seconds elapsed for timer name, 0 on missing key
|
||||
* @static
|
||||
**/
|
||||
function elapsedTime($name = 'default', $precision = 5) {
|
||||
$_this =& DebugKitDebugger::getInstance();
|
||||
if (!isset($_this->__benchmarks[$name]['start']) || !isset($_this->__benchmarks[$name]['end'])) {
|
||||
return 0;
|
||||
}
|
||||
return round($_this->__benchmarks[$name]['end'] - $_this->__benchmarks[$name]['start'], $precision);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total execution time until this point
|
||||
*
|
||||
* @access public
|
||||
* @return float elapsed time in seconds since script start.
|
||||
* @static
|
||||
*/
|
||||
function requestTime() {
|
||||
$start = DebugKitDebugger::requestStartTime();
|
||||
$now = getMicroTime();
|
||||
return ($now - $start);
|
||||
}
|
||||
/**
|
||||
* get the time the current request started.
|
||||
*
|
||||
* @access public
|
||||
* @return float time of request start
|
||||
* @static
|
||||
*/
|
||||
function requestStartTime() {
|
||||
if (defined('TIME_START')) {
|
||||
$startTime = TIME_START;
|
||||
} else if (isset($_GLOBALS['TIME_START'])) {
|
||||
$startTime = $_GLOBALS['TIME_START'];
|
||||
} else {
|
||||
$startTime = env('REQUEST_TIME');
|
||||
}
|
||||
return $startTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* get current memory usage
|
||||
*
|
||||
* @return integer number of bytes ram currently in use. 0 if memory_get_usage() is not available.
|
||||
* @static
|
||||
**/
|
||||
function getMemoryUse() {
|
||||
if (!function_exists('memory_get_usage')) {
|
||||
return 0;
|
||||
}
|
||||
return memory_get_usage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get peak memory use
|
||||
*
|
||||
* @return integer peak memory use (in bytes). Returns 0 if memory_get_peak_usage() is not available
|
||||
* @static
|
||||
**/
|
||||
function getPeakMemoryUse() {
|
||||
if (!function_exists('memory_get_peak_usage')) {
|
||||
return 0;
|
||||
}
|
||||
return memory_get_peak_usage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles object conversion to debug string.
|
||||
*
|
||||
* @param string $var Object to convert
|
||||
* @access protected
|
||||
*/
|
||||
function _output($level, $error, $code, $helpCode, $description, $file, $line, $kontext) {
|
||||
$files = $this->trace(array('start' => 2, 'format' => 'points'));
|
||||
$listing = $this->excerpt($files[0]['file'], $files[0]['line'] - 1, 1);
|
||||
$trace = $this->trace(array('start' => 2, 'depth' => '20'));
|
||||
$context = array();
|
||||
|
||||
foreach ((array)$kontext as $var => $value) {
|
||||
$context[] = "\${$var}\t=\t" . $this->exportVar($value, 1);
|
||||
}
|
||||
if ($this->_outputFormat == 'fb') {
|
||||
$this->_fireError($error, $code, $description, $file, $line, $trace, $context);
|
||||
} else {
|
||||
echo parent::_output($level, $error, $code, $helpCode, $description, $file, $line, $kontext);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Create a FirePHP error message
|
||||
*
|
||||
* @param string $error Name of error
|
||||
* @param string $code Code of error
|
||||
* @param string $description Description of error
|
||||
* @param string $file File error occured in
|
||||
* @param string $line Line error occured on
|
||||
* @param string $trace Stack trace at time of error
|
||||
* @param string $context context of error
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
function _fireError($error, $code, $description, $file, $line, $trace, $context) {
|
||||
$name = $error . ' - ' . $description;
|
||||
$message = "$error $code $description on line: $line in file: $file";
|
||||
FireCake::group($name);
|
||||
FireCake::error($message, $name);
|
||||
FireCake::log($context, 'Context');
|
||||
FireCake::log($trace, 'Trace');
|
||||
FireCake::groupEnd();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Debugger::invoke(DebugKitDebugger::getInstance());
|
||||
Debugger::getInstance('DebugKitDebugger');
|
||||
?>
|
||||
539
plugins/debug_kit/vendors/fire_cake.php
vendored
Normal file
539
plugins/debug_kit/vendors/fire_cake.php
vendored
Normal file
@@ -0,0 +1,539 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* FirePHP Class for CakePHP
|
||||
*
|
||||
* Provides most of the functionality offered by FirePHPCore
|
||||
* Interoperates with FirePHP extension for firefox
|
||||
*
|
||||
* For more information see: http://www.firephp.org/
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package debug_kit.
|
||||
* @subpackage debug_kit.vendors
|
||||
* @since
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
App::import('Core', 'Debugger');
|
||||
|
||||
class FireCake extends Object {
|
||||
/**
|
||||
* Options for FireCake.
|
||||
*
|
||||
* @see _defaultOptions and setOptions();
|
||||
* @var string
|
||||
*/
|
||||
var $options = array();
|
||||
/**
|
||||
* Default Options used in CakeFirePhp
|
||||
*
|
||||
* @var string
|
||||
* @access protected
|
||||
*/
|
||||
var $_defaultOptions = array(
|
||||
'maxObjectDepth' => 10,
|
||||
'maxArrayDepth' => 20,
|
||||
'useNativeJsonEncode' => true,
|
||||
'includeLineNumbers' => true,
|
||||
);
|
||||
/**
|
||||
* Message Levels for messages sent via FirePHP
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $_levels = array(
|
||||
'log' => 'LOG',
|
||||
'info' => 'INFO',
|
||||
'warn' => 'WARN',
|
||||
'error' => 'ERROR',
|
||||
'dump' => 'DUMP',
|
||||
'trace' => 'TRACE',
|
||||
'exception' => 'EXCEPTION',
|
||||
'table' => 'TABLE',
|
||||
'groupStart' => 'GROUP_START',
|
||||
'groupEnd' => 'GROUP_END',
|
||||
);
|
||||
|
||||
var $_version = '0.2.1';
|
||||
/**
|
||||
* internal messageIndex counter
|
||||
*
|
||||
* @var int
|
||||
* @access protected
|
||||
*/
|
||||
var $_messageIndex = 1;
|
||||
/**
|
||||
* stack of objects encoded by stringEncode()
|
||||
*
|
||||
* @var array
|
||||
**/
|
||||
var $_encodedObjects = array();
|
||||
/**
|
||||
* methodIndex to include in tracebacks when using includeLineNumbers
|
||||
*
|
||||
* @var array
|
||||
**/
|
||||
var $_methodIndex = array('info', 'log', 'warn', 'error', 'table', 'trace');
|
||||
/**
|
||||
* FireCake output status
|
||||
*
|
||||
* @var bool
|
||||
**/
|
||||
var $_enabled = true;
|
||||
/**
|
||||
* get Instance of the singleton
|
||||
*
|
||||
* @param string $class Class instance to store in the singleton. Used with subclasses and Tests.
|
||||
* @access public
|
||||
* @static
|
||||
* @return void
|
||||
*/
|
||||
function &getInstance($class = null) {
|
||||
static $instance = array();
|
||||
if (!empty($class)) {
|
||||
if (!$instance || strtolower($class) != strtolower(get_class($instance[0]))) {
|
||||
$instance[0] = new $class();
|
||||
$instance[0]->setOptions();
|
||||
}
|
||||
}
|
||||
if (!isset($instance[0]) || !$instance[0]) {
|
||||
$instance[0] = new FireCake();
|
||||
$instance[0]->setOptions();
|
||||
}
|
||||
return $instance[0];
|
||||
}
|
||||
/**
|
||||
* setOptions
|
||||
*
|
||||
* @param array $options Array of options to set.
|
||||
* @access public
|
||||
* @static
|
||||
* @return void
|
||||
*/
|
||||
function setOptions($options = array()) {
|
||||
$_this = FireCake::getInstance();
|
||||
if (empty($_this->options)) {
|
||||
$_this->options = array_merge($_this->_defaultOptions, $options);
|
||||
} else {
|
||||
$_this->options = array_merge($_this->options, $options);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Return boolean based on presence of FirePHP extension
|
||||
*
|
||||
* @access public
|
||||
* @return boolean
|
||||
**/
|
||||
function detectClientExtension() {
|
||||
$ua = FireCake::getUserAgent();
|
||||
if (!preg_match('/\sFirePHP\/([\.|\d]*)\s?/si', $ua, $match) || !version_compare($match[1], '0.0.6', '>=')) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Get the Current UserAgent
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
* @return string UserAgent string of active client connection
|
||||
**/
|
||||
function getUserAgent() {
|
||||
return env('HTTP_USER_AGENT');
|
||||
}
|
||||
/**
|
||||
* Disable FireCake output
|
||||
* All subsequent output calls will not be run.
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function disable() {
|
||||
$_this = FireCake::getInstance();
|
||||
$_this->_enabled = false;
|
||||
}
|
||||
/**
|
||||
* Enable FireCake output
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function enable() {
|
||||
$_this = FireCake::getInstance();
|
||||
$_this->_enabled = true;
|
||||
}
|
||||
/**
|
||||
* Convenience wrapper for LOG messages
|
||||
*
|
||||
* @param string $message Message to log
|
||||
* @param string $label Label for message (optional)
|
||||
* @access public
|
||||
* @static
|
||||
* @return void
|
||||
*/
|
||||
function log($message, $label = null) {
|
||||
FireCake::fb($message, $label, 'log');
|
||||
}
|
||||
/**
|
||||
* Convenience wrapper for WARN messages
|
||||
*
|
||||
* @param string $message Message to log
|
||||
* @param string $label Label for message (optional)
|
||||
* @access public
|
||||
* @static
|
||||
* @return void
|
||||
*/
|
||||
function warn($message, $label = null) {
|
||||
FireCake::fb($message, $label, 'warn');
|
||||
}
|
||||
/**
|
||||
* Convenience wrapper for INFO messages
|
||||
*
|
||||
* @param string $message Message to log
|
||||
* @param string $label Label for message (optional)
|
||||
* @access public
|
||||
* @static
|
||||
* @return void
|
||||
*/
|
||||
function info($message, $label = null) {
|
||||
FireCake::fb($message, $label, 'info');
|
||||
}
|
||||
/**
|
||||
* Convenience wrapper for ERROR messages
|
||||
*
|
||||
* @param string $message Message to log
|
||||
* @param string $label Label for message (optional)
|
||||
* @access public
|
||||
* @static
|
||||
* @return void
|
||||
*/
|
||||
function error($message, $label = null) {
|
||||
FireCake::fb($message, $label, 'error');
|
||||
}
|
||||
/**
|
||||
* Convenience wrapper for TABLE messages
|
||||
*
|
||||
* @param string $message Message to log
|
||||
* @param string $label Label for message (optional)
|
||||
* @access public
|
||||
* @static
|
||||
* @return void
|
||||
*/
|
||||
function table($label, $message) {
|
||||
FireCake::fb($message, $label, 'table');
|
||||
}
|
||||
/**
|
||||
* Convenience wrapper for DUMP messages
|
||||
*
|
||||
* @param string $message Message to log
|
||||
* @param string $label Unique label for message
|
||||
* @access public
|
||||
* @static
|
||||
* @return void
|
||||
*/
|
||||
function dump($label, $message) {
|
||||
FireCake::fb($message, $label, 'dump');
|
||||
}
|
||||
/**
|
||||
* Convenience wrapper for TRACE messages
|
||||
*
|
||||
* @param string $label Label for message (optional)
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function trace($label) {
|
||||
FireCake::fb($label, 'trace');
|
||||
}
|
||||
/**
|
||||
* Convenience wrapper for GROUP messages
|
||||
* Messages following the group call will be nested in a group block
|
||||
*
|
||||
* @param string $label Label for group (optional)
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function group($label) {
|
||||
FireCake::fb(null, $label, 'groupStart');
|
||||
}
|
||||
/**
|
||||
* Convenience wrapper for GROUPEND messages
|
||||
* Closes a group block
|
||||
*
|
||||
* @param string $label Label for group (optional)
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function groupEnd() {
|
||||
FireCake::fb(null, null, 'groupEnd');
|
||||
}
|
||||
/**
|
||||
* fb - Send messages with FireCake to FirePHP
|
||||
*
|
||||
* Much like FirePHP's fb() this method can be called with various parameter counts
|
||||
* fb($message) - Just send a message defaults to LOG type
|
||||
* fb($message, $type) - Send a message with a specific type
|
||||
* fb($message, $label, $type) - Send a message with a custom label and type.
|
||||
*
|
||||
* @param mixed $message Message to output. For other parameters see usage above.
|
||||
* @static
|
||||
* @return void
|
||||
**/
|
||||
function fb($message) {
|
||||
$_this = FireCake::getInstance();
|
||||
|
||||
if (headers_sent($filename, $linenum)) {
|
||||
trigger_error(sprintf(__('Headers already sent in %s on line %s. Cannot send log data to FirePHP.', true), $filename, $linenum), E_USER_WARNING);
|
||||
return false;
|
||||
}
|
||||
if (!$_this->_enabled || !$_this->detectClientExtension()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$args = func_get_args();
|
||||
$type = $label = null;
|
||||
switch (count($args)) {
|
||||
case 1:
|
||||
$type = $_this->_levels['log'];
|
||||
break;
|
||||
case 2:
|
||||
$type = $args[1];
|
||||
break;
|
||||
case 3:
|
||||
$type = $args[2];
|
||||
$label = $args[1];
|
||||
break;
|
||||
default:
|
||||
trigger_error(__('Incorrect parameter count for FireCake::fb()', true), E_USER_WARNING);
|
||||
return false;
|
||||
}
|
||||
if (isset($_this->_levels[$type])) {
|
||||
$type = $_this->_levels[$type];
|
||||
} else {
|
||||
$type = $_this->_levels['log'];
|
||||
}
|
||||
|
||||
$meta = array();
|
||||
$skipFinalObjectEncode = false;
|
||||
if ($type == $_this->_levels['trace']) {
|
||||
$trace = debug_backtrace();
|
||||
if (!$trace) {
|
||||
return false;
|
||||
}
|
||||
$message = $_this->_parseTrace($trace, $args[0]);
|
||||
$skipFinalObjectEncode = true;
|
||||
}
|
||||
|
||||
if ($_this->options['includeLineNumbers']) {
|
||||
if (!isset($meta['file']) || !isset($meta['line'])) {
|
||||
$trace = debug_backtrace();
|
||||
for ($i = 0, $len = count($trace); $i < $len ; $i++) {
|
||||
$keySet = (isset($trace[$i]['class']) && isset($trace[$i]['function']));
|
||||
$selfCall = ($keySet && $trace[$i]['class'] == 'FireCake' && in_array($trace[$i]['function'], $_this->_methodIndex));
|
||||
if ($selfCall) {
|
||||
$meta['File'] = isset($trace[$i]['file']) ? Debugger::trimPath($trace[$i]['file']) : '';
|
||||
$meta['Line'] = isset($trace[$i]['line']) ? $trace[$i]['line'] : '';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$structureIndex = 1;
|
||||
if ($type == $_this->_levels['dump']) {
|
||||
$structureIndex = 2;
|
||||
$_this->_sendHeader('X-Wf-1-Structure-2','http://meta.firephp.org/Wildfire/Structure/FirePHP/Dump/0.1');
|
||||
} else {
|
||||
$_this->_sendHeader('X-Wf-1-Structure-1','http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1');
|
||||
}
|
||||
|
||||
$_this->_sendHeader('X-Wf-Protocol-1', 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2');
|
||||
$_this->_sendHeader('X-Wf-1-Plugin-1', 'http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/'. $_this->_version);
|
||||
|
||||
if ($type == $_this->_levels['dump']) {
|
||||
$dump = $_this->jsonEncode($message);
|
||||
$msg = '{"' . $label .'":' . $dump .'}';
|
||||
} else {
|
||||
$meta['Type'] = $type;
|
||||
if ($label !== null) {
|
||||
$meta['Label'] = $label;
|
||||
}
|
||||
$msg = '[' . $_this->jsonEncode($meta) . ',' . $_this->jsonEncode($message, $skipFinalObjectEncode).']';
|
||||
}
|
||||
|
||||
$lines = explode("\n", chunk_split($msg, 5000, "\n"));
|
||||
foreach ($lines as $i => $line) {
|
||||
if (empty($line)) {
|
||||
continue;
|
||||
}
|
||||
$header = 'X-Wf-1-' . $structureIndex . '-1-' . $_this->_messageIndex;
|
||||
if (count($lines) > 2) {
|
||||
$first = ($i == 0) ? strlen($msg) : '';
|
||||
$end = ($i < count($lines) - 2) ? '\\' : '';
|
||||
$message = $first . '|' . $line . '|' . $end;
|
||||
$_this->_sendHeader($header, $message);
|
||||
} else {
|
||||
$_this->_sendHeader($header, strlen($line) . '|' . $line . '|');
|
||||
}
|
||||
$_this->_messageIndex++;
|
||||
if ($_this->_messageIndex > 99999) {
|
||||
trigger_error(__('Maximum number (99,999) of messages reached!', true), E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
$_this->_sendHeader('X-Wf-1-Index', $_this->_messageIndex - 1);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Parse a debug backtrace
|
||||
*
|
||||
* @param array $trace Debug backtrace output
|
||||
* @access protected
|
||||
* @return array
|
||||
**/
|
||||
function _parseTrace($trace, $messageName) {
|
||||
$message = array();
|
||||
for ($i = 0, $len = count($trace); $i < $len ; $i++) {
|
||||
$keySet = (isset($trace[$i]['class']) && isset($trace[$i]['function']));
|
||||
$selfCall = ($keySet && $trace[$i]['class'] == 'FireCake');
|
||||
if (!$selfCall) {
|
||||
$message = array(
|
||||
'Class' => isset($trace[$i]['class']) ? $trace[$i]['class'] : '',
|
||||
'Type' => isset($trace[$i]['type']) ? $trace[$i]['type'] : '',
|
||||
'Function' => isset($trace[$i]['function']) ? $trace[$i]['function'] : '',
|
||||
'Message' => $messageName,
|
||||
'File' => isset($trace[$i]['file']) ? Debugger::trimPath($trace[$i]['file']) : '',
|
||||
'Line' => isset($trace[$i]['line']) ? $trace[$i]['line'] : '',
|
||||
'Args' => isset($trace[$i]['args']) ? $this->stringEncode($trace[$i]['args']) : '',
|
||||
'Trace' => $this->_escapeTrace(array_splice($trace, $i + 1))
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $message;
|
||||
}
|
||||
/**
|
||||
* Fix a trace for use in output
|
||||
*
|
||||
* @param mixed $trace Trace to fix
|
||||
* @access protected
|
||||
* @static
|
||||
* @return string
|
||||
**/
|
||||
function _escapeTrace($trace) {
|
||||
for ($i = 0, $len = count($trace); $i < $len; $i++) {
|
||||
if (isset($trace[$i]['file'])) {
|
||||
$trace[$i]['file'] = Debugger::trimPath($trace[$i]['file']);
|
||||
}
|
||||
if (isset($trace[$i]['args'])) {
|
||||
$trace[$i]['args'] = $this->stringEncode($trace[$i]['args']);
|
||||
}
|
||||
}
|
||||
return $trace;
|
||||
}
|
||||
/**
|
||||
* Encode non string objects to string.
|
||||
* Filter out recursion, so no errors are raised by json_encode or $javascript->object()
|
||||
*
|
||||
* @param mixed $object Object or variable to encode to string.
|
||||
* @param int $objectDepth Current Depth in object chains.
|
||||
* @param int $arrayDepth Current Depth in array chains.
|
||||
* @static
|
||||
* @return void
|
||||
**/
|
||||
function stringEncode($object, $objectDepth = 1, $arrayDepth = 1) {
|
||||
$_this = FireCake::getInstance();
|
||||
$return = array();
|
||||
if (is_resource($object)) {
|
||||
return '** ' . (string)$object . '**';
|
||||
}
|
||||
if (is_object($object)) {
|
||||
if ($objectDepth == $_this->options['maxObjectDepth']) {
|
||||
return '** Max Object Depth (' . $_this->options['maxObjectDepth'] . ') **';
|
||||
}
|
||||
foreach ($_this->_encodedObjects as $encoded) {
|
||||
if ($encoded === $object) {
|
||||
return '** Recursion (' . get_class($object) . ') **';
|
||||
}
|
||||
}
|
||||
$_this->_encodedObjects[] = $object;
|
||||
|
||||
$return['__className'] = $class = get_class($object);
|
||||
$properties = (array) $object;
|
||||
foreach ($properties as $name => $property) {
|
||||
$return[$name] = FireCake::stringEncode($property, 1, $objectDepth + 1);
|
||||
}
|
||||
array_pop($_this->_encodedObjects);
|
||||
}
|
||||
if (is_array($object)) {
|
||||
if ($arrayDepth == $_this->options['maxArrayDepth']) {
|
||||
return '** Max Array Depth ('. $_this->options['maxArrayDepth'] . ') **';
|
||||
}
|
||||
foreach ($object as $key => $value) {
|
||||
$return[$key] = FireCake::stringEncode($value, 1, $arrayDepth + 1);
|
||||
}
|
||||
}
|
||||
if (is_string($object) || is_numeric($object) || is_bool($object) || is_null($object)) {
|
||||
return $object;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
/**
|
||||
* Encode an object into JSON
|
||||
*
|
||||
* @param mixed $object Object or array to json encode
|
||||
* @param boolean $doIt
|
||||
* @access public
|
||||
* @static
|
||||
* @return string
|
||||
**/
|
||||
function jsonEncode($object, $skipEncode = false) {
|
||||
$_this = FireCake::getInstance();
|
||||
if (!$skipEncode) {
|
||||
$object = FireCake::stringEncode($object);
|
||||
}
|
||||
|
||||
if (function_exists('json_encode') && $_this->options['useNativeJsonEncode']) {
|
||||
return json_encode($object);
|
||||
} else {
|
||||
return FireCake::_jsonEncode($object);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* jsonEncode Helper method for PHP4 compatibility
|
||||
*
|
||||
* @param mixed $object Something to encode
|
||||
* @access protected
|
||||
* @static
|
||||
* @return string
|
||||
**/
|
||||
function _jsonEncode($object) {
|
||||
if (!class_exists('JavascriptHelper')) {
|
||||
App::import('Helper', 'Javascript');
|
||||
}
|
||||
$javascript = new JavascriptHelper();
|
||||
$javascript->useNative = false;
|
||||
return $javascript->object($object);
|
||||
}
|
||||
/**
|
||||
* Send Headers - write headers.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
**/
|
||||
function _sendHeader($name, $value) {
|
||||
header($name . ': ' . $value);
|
||||
}
|
||||
}
|
||||
?>
|
||||
BIN
plugins/debug_kit/vendors/img/cake.icon.png
vendored
Normal file
BIN
plugins/debug_kit/vendors/img/cake.icon.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
84
plugins/debug_kit/vendors/js/jquery_debug_toolbar.js
vendored
Normal file
84
plugins/debug_kit/vendors/js/jquery_debug_toolbar.js
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* Debug Toolbar Javascript. jQuery 1.2.x compatible.
|
||||
*
|
||||
* Long description here.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.
|
||||
* @since CakePHP v 1.2.0.4487
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
|
||||
(function($) {
|
||||
$(document).ready(function(){
|
||||
DebugKit.Toolbar();
|
||||
DebugKit.NeatArray();
|
||||
});
|
||||
|
||||
var DebugKit = {};
|
||||
/**
|
||||
* Create all behaviors for neat array elements
|
||||
*
|
||||
*/
|
||||
DebugKit.NeatArray = function() {
|
||||
$('.neat-array').find('li:has(ul)').toggle(
|
||||
function() {
|
||||
$(this).toggleClass('expanded').removeClass('collapsed').find('ul:first').show();
|
||||
},
|
||||
function() {
|
||||
$(this).toggleClass('expanded').addClass('collapsed').find('ul:first').hide();
|
||||
}
|
||||
).addClass('expandable').addClass('collapsed').find('ul').hide();
|
||||
}
|
||||
/**
|
||||
* Add behavior for toolbar buttons
|
||||
*
|
||||
*/
|
||||
DebugKit.Toolbar = function() {
|
||||
var tabCollection = $('#debug-kit-toolbar li > div');
|
||||
|
||||
$('#debug-kit-toolbar .panel-tab > a').click(
|
||||
function(e){
|
||||
e.preventDefault();
|
||||
var targetPanel = $(this.hash + '-tab');
|
||||
if (targetPanel.hasClass('active')) {
|
||||
tabCollection.hide().removeClass('active');
|
||||
} else {
|
||||
tabCollection
|
||||
.hide().removeClass('active')
|
||||
.filter(this.hash + '-tab').show().addClass('active');
|
||||
}
|
||||
$('#debug-kit-toolbar .panel-tab > a').removeClass('active');
|
||||
$(this).addClass('active');
|
||||
}
|
||||
);
|
||||
|
||||
//enable hiding of toolbar.
|
||||
var panelButtons = $('#debug-kit-toolbar .panel-tab:not(.panel-tab.icon)');
|
||||
$('#debug-kit-toolbar #hide-toolbar').toggle(
|
||||
function() {
|
||||
panelButtons.hide();
|
||||
},
|
||||
function() {
|
||||
panelButtons.show();
|
||||
}
|
||||
);
|
||||
}
|
||||
})(jQuery);
|
||||
212
plugins/debug_kit/vendors/js/js_debug_toolbar.js
vendored
Normal file
212
plugins/debug_kit/vendors/js/js_debug_toolbar.js
vendored
Normal file
@@ -0,0 +1,212 @@
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* Debug Toolbar Javascript.
|
||||
*
|
||||
* Long description here.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.
|
||||
* @since CakePHP v 1.2.0.4487
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
|
||||
var DebugKit = function(id) {
|
||||
var undefined,
|
||||
elements = {},
|
||||
panels = {},
|
||||
hidden = false;
|
||||
|
||||
this.initialize = function(id) {
|
||||
elements.toolbar = document.getElementById(id || 'debug-kit-toolbar');
|
||||
|
||||
if (elements.toolbar === undefined) {
|
||||
throw new Exception('Toolbar not found, make sure you loaded it.');
|
||||
}
|
||||
|
||||
for (var i in elements.toolbar.childNodes) {
|
||||
var element = elements.toolbar.childNodes[i];
|
||||
if (element.nodeName && element.id === 'panel-tabs') {
|
||||
elements.panel = element;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (var i in elements.panel.childNodes) {
|
||||
var element = elements.panel.childNodes[i];
|
||||
if (element.className && element.className.match(/panel-tab/)) {
|
||||
this.addPanel(element);
|
||||
}
|
||||
}
|
||||
|
||||
var lists = document.getElementsByTagName('ul'), index = 0;
|
||||
while (lists[index] !== undefined) {
|
||||
var element = lists[index];
|
||||
if (element.className && element.className.match(/neat-array/)) {
|
||||
neatArray(element);
|
||||
}
|
||||
++index;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Add a panel to the toolbar
|
||||
*/
|
||||
this.addPanel = function(tab, callback) {
|
||||
if (!tab.nodeName || tab.nodeName.toUpperCase() !== 'LI') {
|
||||
throw new Exception('Toolbar not found, make sure you loaded it.');
|
||||
}
|
||||
var panel = {
|
||||
id : false,
|
||||
element : tab,
|
||||
callback : callback,
|
||||
button : undefined,
|
||||
content : undefined,
|
||||
active : false
|
||||
};
|
||||
for (var i in tab.childNodes) {
|
||||
var element = tab.childNodes[i],
|
||||
tag = element.nodeName? element.nodeName.toUpperCase(): false;
|
||||
if (tag === 'A') {
|
||||
panel.id = element.hash.replace(/^#/, '');
|
||||
panel.button = element;
|
||||
} else if (tag === 'DIV') {
|
||||
panel.content = element;
|
||||
}
|
||||
}
|
||||
if (!panel.id) {
|
||||
throw new Exception('invalid element');
|
||||
}
|
||||
|
||||
if (panel.button.id && panel.button.id === 'hide-toolbar') {
|
||||
panel.callback = this.toggleToolbar;
|
||||
}
|
||||
|
||||
if (panel.callback !== undefined) {
|
||||
panel.button.onclick = function() { return panel.callback(); };
|
||||
} else {
|
||||
panel.button.onclick = function() { return window.DebugKit.togglePanel(panel.id); };
|
||||
}
|
||||
|
||||
panels[panel.id] = panel;
|
||||
return panel.id;
|
||||
};
|
||||
/**
|
||||
* Hide/show the toolbar (minimize cake)
|
||||
*/
|
||||
this.toggleToolbar = function() {
|
||||
for (var i in panels) {
|
||||
var panel = panels[i],
|
||||
display = hidden? 'block': 'none';
|
||||
if (panel.content !== undefined) {
|
||||
panel.element.style.display = display;
|
||||
}
|
||||
}
|
||||
hidden = !hidden;
|
||||
return true;
|
||||
};
|
||||
/**
|
||||
* Toggle a panel
|
||||
*/
|
||||
this.togglePanel = function(id) {
|
||||
if (panels[id] && panels[id].active) {
|
||||
this.deactivatePanel(true);
|
||||
} else {
|
||||
this.deactivatePanel(true);
|
||||
this.activatePanel(id);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Make a panel active.
|
||||
*/
|
||||
this.activatePanel = function(id, unique) {
|
||||
if (panels[id] !== undefined && !panels[id].active) {
|
||||
var panel = panels[id];
|
||||
this.deactivatePanel(true);
|
||||
if (panel.content !== undefined) {
|
||||
panel.content.style.display = 'block';
|
||||
}
|
||||
panel.button.className = panel.button.className.replace(/^(.*)$/, '$1 active');
|
||||
panel.active = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
/**
|
||||
* Deactivate a panel. use true to hide all panels.
|
||||
*/
|
||||
this.deactivatePanel = function(id) {
|
||||
if (id === true) {
|
||||
for (var i in panels) {
|
||||
this.deactivatePanel(i);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (panels[id] !== undefined && panels[id].active) {
|
||||
var panel = panels[id];
|
||||
if (panel.content !== undefined) {
|
||||
panel.content.style.display = 'none';
|
||||
}
|
||||
panel.button.className = panel.button.className.replace(/ ?(active) ?/, '');
|
||||
panel.active = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
/**
|
||||
* Add neat array functionality.
|
||||
*/
|
||||
function neatArray(list) {
|
||||
if (!list.className.match(/depth-0/)) {
|
||||
var item = list.parentNode;
|
||||
list.style.display = 'none';
|
||||
item.className = (item.className || '').replace(/^(.*)$/, '$1 expandable collapsed');
|
||||
item.onclick = function(event) {
|
||||
//var element = (event === undefined)? this: event.target;
|
||||
var element = this,
|
||||
event = event || window.event,
|
||||
act = Boolean(item === element),
|
||||
hide = Boolean(list.style.display === 'block');
|
||||
if (act && hide) {
|
||||
list.style.display = 'none';
|
||||
item.className = item.className.replace(/expanded|$/, 'collapsed');
|
||||
} else if (act) {
|
||||
list.style.display = 'block';
|
||||
item.className = item.className.replace('collapsed', 'expanded');
|
||||
}
|
||||
|
||||
if (event.cancelBubble !== undefined) {
|
||||
event.cancelBubble = true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.initialize(id);
|
||||
}
|
||||
|
||||
DebugKit.install = function() {
|
||||
var initializer = window.onload || function() {};
|
||||
window.onload = function() {
|
||||
initializer();
|
||||
// makes DebugKit a singletone instance
|
||||
window.DebugKit = new DebugKit();
|
||||
}
|
||||
}
|
||||
|
||||
DebugKit.install();
|
||||
95
plugins/debug_kit/vendors/js/mootools_debug_toolbar.js
vendored
Normal file
95
plugins/debug_kit/vendors/js/mootools_debug_toolbar.js
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* Debug Toolbar Javascript. Mootools 1.2 compatible.
|
||||
*
|
||||
* Requires Class, Event, Element, and Selectors
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.
|
||||
* @since CakePHP v 1.2.0.4487
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
|
||||
window.addEvent('domready', function() {
|
||||
new DebugKit();
|
||||
});
|
||||
var DebugKit = new Class({
|
||||
initialize : function() {
|
||||
this.neatArray();
|
||||
this.toolbar();
|
||||
},
|
||||
/**
|
||||
* Create all behaviors for neat array elements
|
||||
*/
|
||||
neatArray : function() {
|
||||
$$('#debug-kit-toolbar .neat-array li').each(function(listItem) {
|
||||
var subUl = listItem.getElement('ul');
|
||||
if (subUl) {
|
||||
listItem.addClass('expandable').addClass('collapsed');
|
||||
subUl.setStyle('display', 'none').set('state', 'closed');
|
||||
listItem.addEvent('click', function(event) {
|
||||
event.stop();
|
||||
this.toggleClass('expanded').toggleClass('collapsed');
|
||||
if (subUl.get('state') == 'closed') {
|
||||
subUl.setStyle('display', 'block').set('state', 'open');
|
||||
} else {
|
||||
subUl.setStyle('display', 'none').set('state', 'closed');
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Add behavior for toolbar buttons
|
||||
*/
|
||||
toolbar : function() {
|
||||
var tabCollection = $$('#debug-kit-toolbar li > div');
|
||||
|
||||
$$('#debug-kit-toolbar .panel-tab > a').addEvent('click', function(event) {
|
||||
event.stop();
|
||||
var buttonId = this.hash.substring(1, this.hash.length) + '-tab';
|
||||
var targetPanel = $(buttonId);
|
||||
if (!targetPanel) return;
|
||||
$$('#debug-kit-toolbar .panel-tab > a').removeClass('active');
|
||||
if (targetPanel.hasClass('active')) {
|
||||
tabCollection.removeClass('active').setStyle('display', 'none');
|
||||
} else {
|
||||
tabCollection.setStyle('display', 'none').removeClass('active');
|
||||
targetPanel.addClass('active').setStyle('display', 'block');
|
||||
this.addClass('active');
|
||||
}
|
||||
});
|
||||
|
||||
//enable hiding of toolbar.
|
||||
var panelButtons = $$('#debug-kit-toolbar .panel-tab:not(.panel-tab.icon)');
|
||||
var toolbarHide = $('hide-toolbar').set('state', 'open');
|
||||
toolbarHide.addEvent('click', function(event) {
|
||||
event.stop();
|
||||
var state = this.get('state');
|
||||
if (state == 'open') {
|
||||
panelButtons.setStyle('display', 'none');
|
||||
this.set('state', 'closed')
|
||||
} else {
|
||||
panelButtons.setStyle('display');
|
||||
this.set('state', 'open');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
95
plugins/debug_kit/vendors/js/prototype_debug_toolbar.js
vendored
Normal file
95
plugins/debug_kit/vendors/js/prototype_debug_toolbar.js
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* Debug Toolbar Javascript. Prototype 1.6.x compatible.
|
||||
*
|
||||
* Long description here.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.
|
||||
* @since CakePHP v 1.2.0.4487
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
|
||||
document.observe('dom:loaded', function() {
|
||||
new DebugKit();
|
||||
});
|
||||
|
||||
var DebugKit = Class.create({
|
||||
|
||||
initialize: function(){
|
||||
this.toolbar();
|
||||
this.neatArray();
|
||||
},
|
||||
|
||||
toolbar: function(){
|
||||
var tabCollection = $('debug-kit-toolbar').select('li > div');
|
||||
|
||||
$('debug-kit-toolbar').select('.panel-tab > a').invoke('observe', 'click', function(e){
|
||||
e.stop();
|
||||
var targetPanel = $(e.element().hash.replace(/#/, '') + '-tab');
|
||||
if (targetPanel.hasClassName('active')) {
|
||||
tabCollection.each(function(ele){
|
||||
ele.hide().removeClassName('active');
|
||||
});
|
||||
} else {
|
||||
tabCollection.each(function(ele){
|
||||
ele.hide().removeClassName('active');
|
||||
if (targetPanel.id == ele.id) {
|
||||
ele.setStyle({display: 'block'}).addClassName('active');
|
||||
}
|
||||
});
|
||||
}
|
||||
$('debug-kit-toolbar').select('.panel-tab > a').invoke('removeClassName', 'active');
|
||||
e.element().addClassName('active');
|
||||
});
|
||||
|
||||
// enable hiding of toolbar.
|
||||
var panelButtons = $('debug-kit-toolbar').select('.panel-tab');
|
||||
$('hide-toolbar').observe('click', function(eve){
|
||||
eve.stop();
|
||||
panelButtons.each(function(panel){
|
||||
if (!panel.hasClassName('icon')) {
|
||||
panel.toggle();
|
||||
};
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Create all behaviors for neat array elements
|
||||
*/
|
||||
neatArray: function() {
|
||||
$('debug-kit-toolbar').select('.neat-array li').each(function(ele){
|
||||
var sub = ele.select('ul');
|
||||
if (sub.length > 0) {
|
||||
ele.addClassName('collapsed').addClassName('expandable');
|
||||
sub.invoke('hide');
|
||||
ele.observe('click', function(eve){
|
||||
if (eve.element() == ele || eve.element().up() == ele) {
|
||||
if (sub.length > 0) {
|
||||
ele.toggleClassName('expanded').toggleClassName('collapsed');
|
||||
sub[0].toggle();
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
126
plugins/debug_kit/vendors/js/yui_debug_toolbar.js
vendored
Normal file
126
plugins/debug_kit/vendors/js/yui_debug_toolbar.js
vendored
Normal file
@@ -0,0 +1,126 @@
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* Debug Toolbar Javascript. YUI 2.6 compatible.
|
||||
*
|
||||
* Long description here.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.
|
||||
* @since CakePHP v 1.2.0.4487
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
|
||||
YAHOO.namespace('CakePHP.DebugKit');
|
||||
|
||||
YAHOO.CakePHP.DebugKit = function() {
|
||||
|
||||
var Event = YAHOO.util.Event;
|
||||
var Dom = YAHOO.util.Dom;
|
||||
var Selector = YAHOO.util.Selector;
|
||||
|
||||
|
||||
var toggle = function(el) {
|
||||
Dom.setStyle(el, 'display', ((Dom.getStyle(el, 'display') == 'none') ? '' : 'none'));
|
||||
};
|
||||
|
||||
var toggleClass = function(element, className) {
|
||||
(Dom.hasClass(element, className)) ? Dom.removeClass(element, className) : Dom.addClass(element, className);
|
||||
};
|
||||
|
||||
|
||||
|
||||
var toolbar = function() {
|
||||
var tabCollection = Selector.query('#debug-kit-toolbar li > div');
|
||||
|
||||
Dom.batch(Selector.query('#debug-kit-toolbar .panel-tab > a'), function(el) {
|
||||
Event.on(el, 'click', function(ev) {
|
||||
Event.preventDefault(ev);
|
||||
targetPanel =Dom.get(el.hash.replace(/#/, '') + '-tab');
|
||||
|
||||
if (Dom.hasClass(targetPanel, 'active')) {
|
||||
Dom.batch(tabCollection, function(ele) {
|
||||
toggle(ele);
|
||||
Dom.removeClass(ele, 'active');
|
||||
Dom.setStyle(ele, 'display', '');
|
||||
});
|
||||
} else {
|
||||
Dom.batch(tabCollection, function(ele) {
|
||||
toggle(ele);
|
||||
Dom.removeClass(ele, 'active');
|
||||
|
||||
if (targetPanel && targetPanel.id == ele.id) {
|
||||
Dom.setStyle(ele, 'display', 'block');
|
||||
Dom.addClass(ele, 'active');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Dom.removeClass(Selector.query('#debug-kit-toolbar .panel-tab > a'), 'active');
|
||||
Dom.addClass(el, 'active');
|
||||
});
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
var neatArray = function() {
|
||||
nodes = Selector.query('#debug-kit-toolbar .panel-content > ul.neat-array li > ul');
|
||||
|
||||
if (nodes.length > 0) {
|
||||
Dom.batch(nodes, function(el) {
|
||||
|
||||
var parent = el.parentNode;
|
||||
|
||||
Dom.addClass(parent, 'collapsed');
|
||||
Dom.addClass(parent, 'expandable');
|
||||
toggle(nodes);
|
||||
|
||||
Event.on(parent, 'click', function(ev) {
|
||||
sub = Selector.query('ul', parent);
|
||||
toggleClass(parent, 'expanded');
|
||||
toggleClass(parent, 'collapsed');
|
||||
toggle(sub);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var panelButtons = function() {
|
||||
Event.on('hide-toolbar', 'click', function(ev) {
|
||||
Event.preventDefault(ev);
|
||||
|
||||
Dom.getElementsByClassName('panel-tab', 'li', 'debug-kit-toolbar', function (el) {
|
||||
if (!Dom.hasClass(el, 'icon')) {
|
||||
toggle(el);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
initialize: function() {
|
||||
neatArray();
|
||||
toolbar();
|
||||
panelButtons();
|
||||
}
|
||||
};
|
||||
}(); // Execute annonymous closure & return results
|
||||
|
||||
YAHOO.util.Event.onDOMReady(YAHOO.CakePHP.DebugKit.initialize);
|
||||
79
plugins/debug_kit/vendors/shells/benchmark.php
vendored
Normal file
79
plugins/debug_kit/vendors/shells/benchmark.php
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* Benchmark Shell.
|
||||
*
|
||||
* Provides basic benchmarking of application requests
|
||||
* functionally similar to Apache AB
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.debug_kit.vendors.shells
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
class BenchmarkShell extends Shell {
|
||||
function main() {
|
||||
$url = $this->args[0];
|
||||
$this->out(sprintf('-> Testing %s', $url));
|
||||
|
||||
$n = 100;
|
||||
$t = $i = 0;
|
||||
if (isset($this->params['n'])) {
|
||||
$n = $this->params['n'];
|
||||
}
|
||||
if (isset($this->params['t'])) {
|
||||
$t = $this->params['t'];
|
||||
}
|
||||
$start = microtime(true);
|
||||
while (true) {
|
||||
if ($t && $t <= floor(microtime(true) - $start)) {
|
||||
break;
|
||||
}
|
||||
if ($n <= $i) {
|
||||
break;
|
||||
}
|
||||
file_get_contents($url);
|
||||
$i++;
|
||||
}
|
||||
$duration = microtime(true) - $start;
|
||||
$this->out('Total Requests made: ' . $i);
|
||||
$this->out('Total Time elapsed: ' . $duration . '(s)');
|
||||
$this->out(round($n / $duration, 2).' req/sec');
|
||||
}
|
||||
|
||||
function help() {
|
||||
$out = <<<EOL
|
||||
DebugKit Benchmark Shell
|
||||
|
||||
Test a fully qualified url to get avg requests per second.
|
||||
By default it does 100 requests to the provided url.
|
||||
|
||||
Use:
|
||||
cake benchmark [params] [url]
|
||||
|
||||
Params
|
||||
-n The maximum number of iterations to do.
|
||||
|
||||
-t The maximum time to take. If a single request takes more
|
||||
than this time. Only one request will be made.
|
||||
EOL;
|
||||
$this->out($out);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
133
plugins/debug_kit/views/debug.php
Normal file
133
plugins/debug_kit/views/debug.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* Debug View
|
||||
*
|
||||
* Custom Debug View class, helps with development.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.
|
||||
* @since CakePHP v 1.2.0.4487
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
App::import('Vendor', 'DebugKit.DebugKitDebugger');
|
||||
App::import('Component', 'DebugKit.Toolbar');
|
||||
/**
|
||||
* DebugView used by DebugKit
|
||||
*
|
||||
* @package debug_kit.views
|
||||
* @todo Remove workarounds.
|
||||
*/
|
||||
class DebugView extends DoppelGangerView {
|
||||
/**
|
||||
* The old extension of the current template.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $_oldExtension = null;
|
||||
/**
|
||||
* Overload _render to capture filenames and time actual rendering of each view file
|
||||
*
|
||||
* @param string $___viewFn Filename of the view
|
||||
* @param array $___dataForView Data to include in rendered view
|
||||
* @return string Rendered output
|
||||
* @access protected
|
||||
*/
|
||||
function _render($___viewFn, $___dataForView, $loadHelpers = true, $cached = false) {
|
||||
if (isset($this->_oldExtension) && strstr($___viewFn, '.debug_view')) {
|
||||
$___viewFn = substr($___viewFn, 0, -10) . $this->_oldExtension;
|
||||
}
|
||||
if (!isset($___dataForView['disableTimer'])) {
|
||||
DebugKitDebugger::startTimer('render_' . basename($___viewFn), sprintf(__('Rendering %s', true), Debugger::trimPath($___viewFn)));
|
||||
}
|
||||
|
||||
$out = parent::_render($___viewFn, $___dataForView, $loadHelpers, $cached);
|
||||
|
||||
if (!isset($___dataForView['disableTimer'])) {
|
||||
DebugKitDebugger::stopTimer('render_' . basename($___viewFn));
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders view for given action and layout. If $file is given, that is used
|
||||
* for a view filename (e.g. customFunkyView.ctp).
|
||||
* Adds timers, for all subsequent rendering, and injects the debugKit toolbar.
|
||||
*
|
||||
* @param string $action Name of action to render for
|
||||
* @param string $layout Layout to use
|
||||
* @param string $file Custom filename for view
|
||||
* @return string Rendered Element
|
||||
*/
|
||||
function render($action = null, $layout = null, $file = null) {
|
||||
DebugKitDebugger::startTimer('viewRender', __('Rendering View', true));
|
||||
$out = parent::render($action, $layout, $file);
|
||||
DebugKitDebugger::stopTimer('viewRender');
|
||||
DebugKitDebugger::stopTimer('controllerRender');
|
||||
|
||||
if (isset($this->loaded['toolbar'])) {
|
||||
$this->loaded['toolbar']->postRender();
|
||||
}
|
||||
//Temporary work around to hide the SQL dump at page bottom
|
||||
Configure::write('debug', 0);
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Workaround _render() limitation in core. Which forces View::_render() for .ctp and .thtml templates
|
||||
* Creates temporary extension to trick View::render() & View::renderLayout()
|
||||
*
|
||||
* @param string $name Action name.
|
||||
* @return string
|
||||
**/
|
||||
function _getViewFileName($name = null) {
|
||||
$filename = parent::_getViewFileName($name);
|
||||
return $this->_replaceExtension($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Workaround _render() limitation in core. Which forces View::_render() for .ctp and .thtml templates
|
||||
* Creates temporary extension to trick View::render() & View::renderLayout()
|
||||
*
|
||||
* @param string $name Layout Name
|
||||
* @return string
|
||||
**/
|
||||
function _getLayoutFileName($name = null) {
|
||||
$filename = parent::_getLayoutFileName($name);
|
||||
return $this->_replaceExtension($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* replace the Extension on a filename and set the temporary workaround extension.
|
||||
*
|
||||
* @param string $filename Filename to replace extension for.
|
||||
* @return string
|
||||
**/
|
||||
function _replaceExtension($filename) {
|
||||
if (substr($filename, -3) == 'ctp') {
|
||||
$this->_oldExtension = 'ctp';
|
||||
$filename = substr($filename, 0, strlen($filename) -3) . 'debug_view';
|
||||
} elseif (substr($filename, -5) == 'thtml') {
|
||||
$this->_oldExtension = 'thtml';
|
||||
$filename = substr($filename, 0, strlen($filename) -5) . 'debug_view';
|
||||
}
|
||||
return $filename;
|
||||
}
|
||||
}
|
||||
?>
|
||||
52
plugins/debug_kit/views/elements/debug_toolbar.ctp
Normal file
52
plugins/debug_kit/views/elements/debug_toolbar.ctp
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* Debug Toolbar Element
|
||||
*
|
||||
* Renders all of the other panel elements.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.debug_kit.views.elements
|
||||
* @since
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
?>
|
||||
<div id="debug-kit-toolbar">
|
||||
<?php if (empty($debugToolbarPanels)) :?>
|
||||
<p class="warning"><?php __('There are no active panels. You must enable a panel to see its output.'); ?></p>
|
||||
<?php else: ?>
|
||||
<ul id="panel-tabs">
|
||||
<li class="panel-tab icon">
|
||||
<a href="#hide" id="hide-toolbar">
|
||||
<?php echo $html->image('/debug_kit/img/cake.icon.png', array('alt' => 'cakePHP')); ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php foreach ($debugToolbarPanels as $panelName => $panelInfo): ?>
|
||||
<li class="panel-tab">
|
||||
<a href="#<?php echo Inflector::underscore($panelName); ?>">
|
||||
<?php echo Inflector::humanize(Inflector::underscore($panelName)); ?>
|
||||
</a>
|
||||
<div class="panel-content" id="<?php echo Inflector::underscore($panelName); ?>-tab">
|
||||
<?php echo $this->element($panelInfo['elementName'], $panelInfo); ?>
|
||||
</div>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
0
plugins/debug_kit/views/elements/empty
Normal file
0
plugins/debug_kit/views/elements/empty
Normal file
48
plugins/debug_kit/views/elements/log_panel.ctp
Normal file
48
plugins/debug_kit/views/elements/log_panel.ctp
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* Log Panel Element
|
||||
*
|
||||
*
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.debug_kit.views.elements
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
?>
|
||||
<h2><?php __('Logs') ?></h2>
|
||||
<div class="code-table">
|
||||
<?php foreach ($content as $logName => $logs): ?>
|
||||
<h3><?php echo $logName ?></h3>
|
||||
<?php
|
||||
$len = count($logs);
|
||||
if ($len > 0):
|
||||
$headers = array(__('Time', true), __('Message', true));
|
||||
$rows = array();
|
||||
for ($i = 0; $i < $len; $i += 2):
|
||||
$rows[] = array(
|
||||
$logs[$i], $logs[$i + 1]
|
||||
);
|
||||
endfor;
|
||||
echo $toolbar->table($rows, $headers, array('title' => $logName));
|
||||
else: ?>
|
||||
<p class="info"><?php __('There were no log entries made this request'); ?></p>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
43
plugins/debug_kit/views/elements/memory_panel.ctp
Normal file
43
plugins/debug_kit/views/elements/memory_panel.ctp
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* Session Panel Element
|
||||
*
|
||||
*
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.debug_kit.views.elements
|
||||
* @since
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
?>
|
||||
<h2><?php __('Memory'); ?></h2>
|
||||
<div class="current-mem-use">
|
||||
<?php echo $toolbar->message(
|
||||
__('Current Memory Use',true),
|
||||
$number->toReadableSize(DebugKitDebugger::getMemoryUse())
|
||||
);?>
|
||||
</div>
|
||||
<div class="peak-mem-use">
|
||||
<?php
|
||||
echo $toolbar->message(
|
||||
__('Peak Memory Use', true),
|
||||
$number->toReadableSize(DebugKitDebugger::getPeakMemoryUse())
|
||||
);
|
||||
?></div>
|
||||
45
plugins/debug_kit/views/elements/request_panel.ctp
Normal file
45
plugins/debug_kit/views/elements/request_panel.ctp
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* Request Panel Element
|
||||
*
|
||||
*
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.debug_kit.views.elements
|
||||
* @since
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
?>
|
||||
<h2> <?php __('Request'); ?></h2>
|
||||
<h4>Cake Params</h4>
|
||||
<?php echo $toolbar->makeNeatArray($content['params']); ?>
|
||||
|
||||
<h4>$_GET</h4>
|
||||
<?php echo $toolbar->makeNeatArray($content['get']); ?>
|
||||
|
||||
<h4>Cookie</h4>
|
||||
<?php if (isset($content['cookie'])): ?>
|
||||
<?php echo $toolbar->makeNeatArray($content['cookie']); ?>
|
||||
<?php else: ?>
|
||||
<p class="warning">To view Cookies, add CookieComponent to Controller
|
||||
<?php endif; ?>
|
||||
|
||||
<h4><?php __('Current Route') ?></h4>
|
||||
<?php echo $toolbar->makeNeatArray($content['currentRoute']); ?>
|
||||
31
plugins/debug_kit/views/elements/session_panel.ctp
Normal file
31
plugins/debug_kit/views/elements/session_panel.ctp
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* Session Panel Element
|
||||
*
|
||||
*
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.debug_kit.views.elements
|
||||
* @since
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
?>
|
||||
<h2><?php __('Session'); ?></h2>
|
||||
<?php echo $toolbar->makeNeatArray($content); ?>
|
||||
40
plugins/debug_kit/views/elements/sql_log_panel.ctp
Normal file
40
plugins/debug_kit/views/elements/sql_log_panel.ctp
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* Session Panel Element
|
||||
*
|
||||
*
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.debug_kit.views.elements
|
||||
* @since
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
?>
|
||||
<h2><?php __('Sql Logs')?></h2>
|
||||
<?php if (!empty($content)) : ?>
|
||||
<?php foreach ($content as $dbName => $queryLog) : ?>
|
||||
<div class="sql-log-panel-query-log">
|
||||
<h4><?php echo $dbName ?></h4>
|
||||
<?php echo $queryLog; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<p class="warning"><?php __('No active database connections'); ?>
|
||||
<?php endif; ?>
|
||||
44
plugins/debug_kit/views/elements/timer_panel.ctp
Normal file
44
plugins/debug_kit/views/elements/timer_panel.ctp
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* Timer Panel Element
|
||||
*
|
||||
*
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.debug_kit.views.elements
|
||||
* @since
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
$timers = DebugKitDebugger::getTimers();
|
||||
?>
|
||||
<h2><?php __('Timers'); ?></h2>
|
||||
<p class="request-time">
|
||||
<?php $totalTime = sprintf(__('%s (seconds)', true), $number->precision(DebugKitDebugger::requestTime(), 6)); ?>
|
||||
<?php echo $toolbar->message(__('Total Request Time:', true), $totalTime)?>
|
||||
</p>
|
||||
|
||||
<?php foreach ($timers as $timerName => $timeInfo):
|
||||
$rows[] = array(
|
||||
$timeInfo['message'],
|
||||
$number->precision($timeInfo['time'], 6)
|
||||
);
|
||||
$headers = array(__('Message', true), __('time in seconds', true));
|
||||
endforeach;
|
||||
echo $toolbar->table($rows, $headers, array('title' => 'Timers')); ?>
|
||||
35
plugins/debug_kit/views/elements/variables_panel.ctp
Normal file
35
plugins/debug_kit/views/elements/variables_panel.ctp
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* View Variables Panel Element
|
||||
*
|
||||
*
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.debug_kit.views.elements
|
||||
* @since
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
?>
|
||||
<h2> <?php __('View Variables'); ?></h2>
|
||||
<?php
|
||||
$vars = $this->viewVars;
|
||||
unset($vars['debugToolbarPanels'], $vars['debugToolbarJavascript']);
|
||||
?>
|
||||
<?php echo $toolbar->makeNeatArray($vars); ?>
|
||||
79
plugins/debug_kit/views/helpers/fire_php_toolbar.php
Normal file
79
plugins/debug_kit/views/helpers/fire_php_toolbar.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* FirePHP Toolbar Helper
|
||||
*
|
||||
* Injects the toolbar elements into non-HTML layouts via FireCake.
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package debug_kit
|
||||
* @subpackage debug_kit.views.helpers
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
App::import('helper', 'DebugKit.Toolbar');
|
||||
App::import('Vendor', 'DebugKit.FireCake');
|
||||
|
||||
class FirePhpToolbarHelper extends ToolbarHelper {
|
||||
/**
|
||||
* send method
|
||||
*
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
function _send() {
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
$view->element('debug_toolbar', array('plugin' => 'debug_kit', 'disableTimer' => true));
|
||||
Configure::write('debug', 1);
|
||||
}
|
||||
/**
|
||||
* makeNeatArray.
|
||||
*
|
||||
* wraps FireCake::dump() allowing panel elements to continue functioning
|
||||
*
|
||||
* @param string $values
|
||||
* @return void
|
||||
*/
|
||||
function makeNeatArray($values) {
|
||||
FireCake::info($values);
|
||||
}
|
||||
/**
|
||||
* Create a simple message
|
||||
*
|
||||
* @param string $label Label of message
|
||||
* @param string $message Message content
|
||||
* @return void
|
||||
*/
|
||||
function message($label, $message) {
|
||||
FireCake::log($message, $label);
|
||||
}
|
||||
/**
|
||||
* Generate a table with FireCake
|
||||
*
|
||||
* @param array $rows Rows to print
|
||||
* @param array $headers Headers for table
|
||||
* @param array $options Additional options and params
|
||||
* @return void
|
||||
*/
|
||||
function table($rows, $headers, $options = array()) {
|
||||
$title = $headers[0];
|
||||
if (isset($options['title'])) {
|
||||
$title = $options['title'];
|
||||
}
|
||||
array_unshift($rows, $headers);
|
||||
FireCake::table($title, $rows);
|
||||
}
|
||||
}
|
||||
?>
|
||||
150
plugins/debug_kit/views/helpers/html_toolbar.php
Normal file
150
plugins/debug_kit/views/helpers/html_toolbar.php
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* Html Toolbar Helper
|
||||
*
|
||||
* Injects the toolbar elements into HTML layouts.
|
||||
* Contains helper methods for
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package debug_kit
|
||||
* @subpackage debug_kit.views.helpers
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
App::import('helper', 'DebugKit.Toolbar');
|
||||
|
||||
class HtmlToolbarHelper extends ToolbarHelper {
|
||||
/**
|
||||
* helpers property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $helpers = array('Html', 'Javascript');
|
||||
/**
|
||||
* settings property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $settings = array('format' => 'html');
|
||||
/**
|
||||
* Recursively goes through an array and makes neat HTML out of it.
|
||||
*
|
||||
* @param mixed $values Array to make pretty.
|
||||
* @param int $openDepth Depth to add open class
|
||||
* @param int $currentDepth current depth.
|
||||
* @return string
|
||||
**/
|
||||
function makeNeatArray($values, $openDepth = 0, $currentDepth = 0) {
|
||||
$className ="neat-array depth-$currentDepth";
|
||||
if ($openDepth > $currentDepth) {
|
||||
$className .= ' expanded';
|
||||
}
|
||||
$nextDepth = $currentDepth + 1;
|
||||
$out = "<ul class=\"$className\">";
|
||||
if (!is_array($values)) {
|
||||
if (is_bool($values)) {
|
||||
$values = array($values);
|
||||
}
|
||||
if (is_null($values)) {
|
||||
$values = array(null);
|
||||
}
|
||||
}
|
||||
foreach ($values as $key => $value) {
|
||||
$out .= '<li><strong>' . $key . '</strong>';
|
||||
if ($value === null) {
|
||||
$value = '(null)';
|
||||
}
|
||||
if ($value === false) {
|
||||
$value = '(false)';
|
||||
}
|
||||
if ($value === true) {
|
||||
$value = '(true)';
|
||||
}
|
||||
if (empty($value) && $value != 0) {
|
||||
$value = '(empty)';
|
||||
}
|
||||
|
||||
if (is_object($value)) {
|
||||
$value = Set::reverse($value, true);
|
||||
}
|
||||
|
||||
if (is_array($value) && !empty($value)) {
|
||||
$out .= $this->makeNeatArray($value, $openDepth, $nextDepth);
|
||||
} else {
|
||||
$out .= $value;
|
||||
}
|
||||
$out .= '</li>';
|
||||
}
|
||||
$out .= '</ul>';
|
||||
return $out;
|
||||
}
|
||||
/**
|
||||
* Create an HTML message
|
||||
*
|
||||
* @param string $label label content
|
||||
* @param string $message message content
|
||||
* @return string
|
||||
*/
|
||||
function message($label, $message) {
|
||||
return sprintf('<p><strong>%s</strong> %s</p>', $label, $message);
|
||||
}
|
||||
/**
|
||||
* Create a table.
|
||||
*
|
||||
* @param array $rows Rows to make.
|
||||
* @param array $headers Optional header row.
|
||||
* @return string
|
||||
*/
|
||||
function table($rows, $headers = array()) {
|
||||
$out = '<table class="debug-table">';
|
||||
if (!empty($headers)) {
|
||||
$out .= $this->Html->tableHeaders($headers);
|
||||
}
|
||||
$out .= $this->Html->tableCells($rows, array('class' => 'odd'), array('class' => 'even'));
|
||||
$out .= '</table>';
|
||||
return $out;
|
||||
}
|
||||
/**
|
||||
* send method
|
||||
*
|
||||
* @return void
|
||||
* @access protected
|
||||
*/
|
||||
function _send() {
|
||||
if (Configure::read('debug') == 0) {
|
||||
return;
|
||||
}
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
$head = $this->Html->css('/debug_kit/css/debug_toolbar');
|
||||
if (isset($view->viewVars['debugToolbarJavascript'])) {
|
||||
foreach ($view->viewVars['debugToolbarJavascript'] as $script) {
|
||||
if ($script) {
|
||||
$head .= $this->Javascript->link($script);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (preg_match('#</head>#', $view->output)) {
|
||||
$view->output = preg_replace('#</head>#', $head . "\n</head>", $view->output, 1);
|
||||
}
|
||||
$toolbar = $view->element('debug_toolbar', array('plugin' => 'debug_kit', 'disableTimer' => true));
|
||||
if (preg_match('#</body>#', $view->output)) {
|
||||
$view->output = preg_replace('#</body>#', $toolbar . "\n</body>", $view->output, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
90
plugins/debug_kit/views/helpers/toolbar.php
Normal file
90
plugins/debug_kit/views/helpers/toolbar.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* Abstract Toolbar helper. Provides Base methods for content
|
||||
* specific debug toolbar helpers. Acts as a facade for other toolbars helpers as well.
|
||||
*
|
||||
* helps with development.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2006-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package debug_kit
|
||||
* @subpackage debug_kit.views.helpers
|
||||
* @since v 1.0
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
App::import('Vendor', 'DebugKit.DebugKitDebugger');
|
||||
|
||||
class ToolbarHelper extends AppHelper {
|
||||
/**
|
||||
* settings property to be overloaded. Subclasses should specify a format
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $settings = array();
|
||||
/**
|
||||
* Construct the helper and make the backend helper.
|
||||
*
|
||||
* @param string $options
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function __construct($options = array()) {
|
||||
$this->_myName = strtolower(get_class($this));
|
||||
if ($this->_myName !== 'toolbarhelper') {
|
||||
return;
|
||||
}
|
||||
if (!isset($options['output'])) {
|
||||
$options['output'] = 'DebugKit.HtmlToolbar';
|
||||
}
|
||||
App::import('Helper', $options['output']);
|
||||
$className = $options['output'];
|
||||
if (strpos($options['output'], '.') !== false) {
|
||||
list($plugin, $className) = explode('.', $options['output']);
|
||||
}
|
||||
$this->_backEndClassName = $className;
|
||||
$this->helpers = array($options['output']);
|
||||
}
|
||||
|
||||
/**
|
||||
* call__
|
||||
*
|
||||
* Allows method calls on backend helper
|
||||
*
|
||||
* @param string $method
|
||||
* @param mixed $params
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function call__($method, $params) {
|
||||
if (method_exists($this->{$this->_backEndClassName}, $method)) {
|
||||
return $this->{$this->_backEndClassName}->dispatchMethod($method, $params);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* postRender method
|
||||
*
|
||||
* Custom Callback defined in DebugView to allow helpers to modify
|
||||
* View output after all rendering is complete.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function postRender() {
|
||||
$this->_send();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user