initial commit

This commit is contained in:
2026-06-25 13:03:45 +06:00
commit 4589f4a8d0
3229 changed files with 941958 additions and 0 deletions

View File

@@ -0,0 +1,227 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since DebugKit 0.1
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Debugger', 'Utility');
App::uses('FireCake', 'DebugKit.Lib');
App::uses('DebugTimer', 'DebugKit.Lib');
App::uses('DebugMemory', 'DebugKit.Lib');
/**
* DebugKit 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.
*
* @since DebugKit 0.1
*/
class DebugKitDebugger extends Debugger {
/**
* destruct method
*
* Allow timer info to be displayed if the code dies or is being debugged before rendering the view
* Cheat and use the debug log class for formatting
*
* @return void
*/
public function __destruct() {
$timers = DebugTimer::getAll();
if (Configure::read('debug') < 2 || count($timers) > 0) {
return;
}
$timers = array_values($timers);
$end = end($timers);
echo '<table class="cake-sql-log"><tbody>';
echo '<caption>Debug timer info</caption>';
echo '<tr><th>Message</th><th>Start Time (ms)</th><th>End Time (ms)</th><th>Duration (ms)</th></tr>';
$i = 0;
foreach ($timers as $timer) {
$indent = 0;
for ($j = 0; $j < $i; $j++) {
if (($timers[$j]['end']) > ($timer['start']) && ($timers[$j]['end']) > ($timer['end'])) {
$indent++;
}
}
$indent = str_repeat(' &raquo; ', $indent);
extract($timer);
$start = round($start * 1000, 0);
$end = round($end * 1000, 0);
$time = round($time * 1000, 0);
echo "<tr><td>{$indent}$message</td><td>$start</td><td>$end</td><td>$time</td></tr>";
$i++;
}
echo '</tbody></table>';
}
/**
* Start an benchmarking timer.
*
* @param string $name The name of the timer to start.
* @param string $message A message for your timer
* @return boolean true
* @deprecated use DebugTimer::start()
*/
public static function startTimer($name = null, $message = null) {
return DebugTimer::start($name, $message);
}
/**
* 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.
* @return boolean true if timer was ended, false if timer was not started.
* @deprecated use DebugTimer::stop()
*/
public static function stopTimer($name = null) {
return DebugTimer::stop($name);
}
/**
* Get all timers that have been started and stopped.
* Calculates elapsed time for each timer. If clear is true, will delete existing timers
*
* @param boolean $clear false
* @return array
* @deprecated use DebugTimer::getAll()
*/
public static function getTimers($clear = false) {
return DebugTimer::getAll($clear);
}
/**
* Clear all existing timers
*
* @return boolean true
* @deprecated use DebugTimer::clear()
*/
public static function clearTimers() {
return DebugTimer::clear();
}
/**
* 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
* @deprecated use DebugTimer::elapsedTime()
*/
public static function elapsedTime($name = 'default', $precision = 5) {
return DebugTimer::elapsedTime($name, $precision);
}
/**
* Get the total execution time until this point
*
* @return float elapsed time in seconds since script start.
* @deprecated use DebugTimer::requestTime()
*/
public static function requestTime() {
return DebugTimer::requestTime();
}
/**
* get the time the current request started.
*
* @return float time of request start
* @deprecated use DebugTimer::requestStartTime()
*/
public static function requestStartTime() {
return DebugTimer::requestStartTime();
}
/**
* get current memory usage
*
* @return integer number of bytes ram currently in use. 0 if memory_get_usage() is not available.
* @deprecated Use DebugMemory::getCurrent() instead.
*/
public static function getMemoryUse() {
return DebugMemory::getCurrent();
}
/**
* Get peak memory use
*
* @return integer peak memory use (in bytes). Returns 0 if memory_get_peak_usage() is not available
* @deprecated Use DebugMemory::getPeak() instead.
*/
public static function getPeakMemoryUse() {
return DebugMemory::getPeak();
}
/**
* Stores a memory point in the internal tracker.
* Takes a optional message name which can be used to identify the memory point.
* If no message is supplied a debug_backtrace will be done to identifty the memory point.
* If you don't have memory_get_xx methods this will not work.
*
* @param string $message Message to identify this memory point.
* @return boolean
* @deprecated Use DebugMemory::getAll() instead.
*/
public static function setMemoryPoint($message = null) {
return DebugMemory::record($message);
}
/**
* Get all the stored memory points
*
* @param boolean $clear Whether you want to clear the memory points as well. Defaults to false.
* @return array Array of memory marks stored so far.
* @deprecated Use DebugMemory::getAll() instead.
*/
public static function getMemoryPoints($clear = false) {
return DebugMemory::getAll($clear);
}
/**
* Clear out any existing memory points
*
* @return void
* @deprecated Use DebugMemory::clear() instead.
*/
public static function clearMemoryPoints() {
DebugMemory::clear();
}
/**
* Create a FirePHP error message
*
* @param array $data Data of the error
* @param array $links Links for the error
* @return void
*/
public static function fireError($data, $links) {
$name = $data['error'] . ' - ' . $data['description'];
$message = "{$data['error']} {$data['code']} {$data['description']} on line: {$data['line']} in file: {$data['file']}";
FireCake::group($name);
FireCake::error($message, $name);
if (isset($data['context'])) {
FireCake::log($data['context'], 'Context');
}
if (isset($data['trace'])) {
FireCake::log(preg_split('/[\r\n]+/', $data['trace']), 'Trace');
}
FireCake::groupEnd();
}
}
DebugKitDebugger::getInstance('DebugKitDebugger');
Debugger::addFormat('fb', array('callback' => 'DebugKitDebugger::fireError'));

View File

@@ -0,0 +1,98 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since DebugKit 2.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Debugger', 'Utility');
/**
* Contains methods for Profiling memory usage.
*
*/
class DebugMemory {
/**
* An array of recorded memory use points.
*
* @var array
*/
protected static $_points = array();
/**
* Get current memory usage
*
* @return integer number of bytes ram currently in use. 0 if memory_get_usage() is not available.
*/
public static function getCurrent() {
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
*/
public static function getPeak() {
return memory_get_peak_usage();
}
/**
* Stores a memory point in the internal tracker.
* Takes a optional message name which can be used to identify the memory point.
* If no message is supplied a debug_backtrace will be done to identify the memory point.
*
* @param string $message Message to identify this memory point.
* @return boolean
*/
public static function record($message = null) {
$memoryUse = self::getCurrent();
if (!$message) {
$named = false;
$trace = debug_backtrace();
$message = Debugger::trimpath($trace[0]['file']) . ' line ' . $trace[0]['line'];
}
if (isset(self::$_points[$message])) {
$originalMessage = $message;
$i = 1;
while (isset(self::$_points[$message])) {
$i++;
$message = $originalMessage . ' #' . $i;
}
}
self::$_points[$message] = $memoryUse;
return true;
}
/**
* Get all the stored memory points
*
* @param boolean $clear Whether you want to clear the memory points as well. Defaults to false.
* @return array Array of memory marks stored so far.
*/
public static function getAll($clear = false) {
$marks = self::$_points;
if ($clear) {
self::$_points = array();
}
return $marks;
}
/**
* Clear out any existing memory points
*
* @return void
*/
public static function clear() {
self::$_points = array();
}
}

View File

@@ -0,0 +1,84 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since DebugKit 0.1
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
/**
* Base class for debug panels.
*
* @since DebugKit 0.1
*/
class DebugPanel {
/**
* Defines which plugin this panel is from so the element can be located.
*
* @var string
*/
public $plugin = 'DebugKit';
/**
* Defines the title for displaying on the toolbar. If null, the class name will be used.
* Overriding this allows you to define a custom name in the toolbar.
*
* @var string
*/
public $title = null;
/**
* Panel's css files
*
* @var array
*/
public $css = array();
/**
* Panel's javascript files
*
* @var array
*/
public $javascript = array();
/**
* Provide a custom element name for this panel. If null, the underscored version of the class
* name will be used.
*
* @var string
*/
public $elementName = null;
/**
* Empty constructor
*/
public function __construct() {
}
/**
* startup the panel
*
* Pull information from the controller / request
*
* @param \Controller|object $controller Controller reference.
* @return void
*/
public function startup(Controller $controller) {
}
/**
* Prepare output vars before Controller Rendering.
*
* @param \Controller|object $controller Controller reference.
* @return void
*/
public function beforeRender(Controller $controller) {
}
}

View File

@@ -0,0 +1,201 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since DebugKit 0.1
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Debugger', 'Utility');
/**
* Contains methods for Profiling and creating timers.
*
*/
class DebugTimer {
/**
* Internal timers array
*
* @var array
*/
protected static $_timers = array();
/**
* Start an benchmarking timer.
*
* @param string $name The name of the timer to start.
* @param string $message A message for your timer
* @return boolean Always true
*/
public static function start($name = null, $message = null) {
$start = microtime(true);
if (!$name) {
$named = false;
$calledFrom = debug_backtrace();
$_name = $name = Debugger::trimpath($calledFrom[0]['file']) . ' line ' . $calledFrom[0]['line'];
} else {
$named = true;
}
if (!$message) {
$message = $name;
}
$_name = $name;
$i = 1;
while (isset(self::$_timers[$name])) {
$i++;
$name = $_name . ' #' . $i;
}
if ($i > 1) {
$message .= ' #' . $i;
}
self::$_timers[$name] = array(
'start' => $start,
'message' => $message,
'named' => $named
);
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.
* @return boolean true if timer was ended, false if timer was not started.
*/
public static function stop($name = null) {
$end = microtime(true);
if (!$name) {
$names = array_reverse(array_keys(self::$_timers));
foreach ($names as $name) {
if (!empty(self::$_timers[$name]['end'])) {
continue;
}
if (empty(self::$_timers[$name]['named'])) {
break;
}
}
} else {
$i = 1;
$_name = $name;
while (isset(self::$_timers[$name])) {
if (empty(self::$_timers[$name]['end'])) {
break;
}
$i++;
$name = $_name . ' #' . $i;
}
}
if (!isset(self::$_timers[$name])) {
return false;
}
self::$_timers[$name]['end'] = $end;
return true;
}
/**
* Get all timers that have been started and stopped.
* Calculates elapsed time for each timer. If clear is true, will delete existing timers
*
* @param boolean $clear false
* @return array
*/
public static function getAll($clear = false) {
$start = self::requestStartTime();
$now = microtime(true);
$times = array();
if (!empty(self::$_timers)) {
$firstTimer = reset(self::$_timers);
$_end = $firstTimer['start'];
} else {
$_end = $now;
}
$times['Core Processing (Derived from $_SERVER["REQUEST_TIME"])'] = array(
'message' => __d('debug_kit', 'Core Processing (Derived from $_SERVER["REQUEST_TIME"])'),
'start' => 0,
'end' => $_end - $start,
'time' => round($_end - $start, 6),
'named' => null
);
foreach (self::$_timers as $name => $timer) {
if (!isset($timer['end'])) {
$timer['end'] = $now;
}
$times[$name] = array_merge($timer, array(
'start' => $timer['start'] - $start,
'end' => $timer['end'] - $start,
'time' => self::elapsedTime($name)
));
}
if ($clear) {
self::$_timers = array();
}
return $times;
}
/**
* Clear all existing timers
*
* @return boolean true
*/
public static function clear() {
self::$_timers = 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
*/
public static function elapsedTime($name = 'default', $precision = 5) {
if (!isset(self::$_timers[$name]['start']) || !isset(self::$_timers[$name]['end'])) {
return 0;
}
return round(self::$_timers[$name]['end'] - self::$_timers[$name]['start'], $precision);
}
/**
* Get the total execution time until this point
*
* @return float elapsed time in seconds since script start.
*/
public static function requestTime() {
$start = self::requestStartTime();
$now = microtime(true);
return ($now - $start);
}
/**
* get the time the current request started.
*
* @return float time of request start
*/
public static function requestStartTime() {
if (defined('TIME_START')) {
$startTime = TIME_START;
} elseif (isset($GLOBALS['TIME_START'])) {
$startTime = $GLOBALS['TIME_START'];
} else {
$startTime = env('REQUEST_TIME');
}
return $startTime;
}
}

View File

@@ -0,0 +1,538 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since DebugKit 0.1
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Debugger', 'Utility');
if (!function_exists('firecake')) {
/**
* Procedural version of FireCake::log()
*
* @param $message
* @param null $label
*/
function firecake($message, $label = null) {
FireCake::fb($message, $label, 'log');
}
}
/**
* 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/
*
*/
class FireCake {
/**
* Options for FireCake.
*
* @see _defaultOptions and setOptions();
* @var string
*/
public $options = array();
/**
* Default Options used in CakeFirePhp
*
* @var string
*/
protected $_defaultOptions = array(
'maxObjectDepth' => 10,
'maxArrayDepth' => 20,
'useNativeJsonEncode' => true,
'includeLineNumbers' => true,
);
/**
* Message Levels for messages sent via FirePHP
*
* @var array
*/
protected $_levels = array(
'log' => 'LOG',
'info' => 'INFO',
'warn' => 'WARN',
'error' => 'ERROR',
'dump' => 'DUMP',
'trace' => 'TRACE',
'exception' => 'EXCEPTION',
'table' => 'TABLE',
'groupStart' => 'GROUP_START',
'groupEnd' => 'GROUP_END',
);
/**
* Version number for X-Wf-1-Plugin-1 HTML header
*
* @var string
*/
protected $_version = '0.2.1';
/**
* internal messageIndex counter
*
* @var integer
*/
protected $_messageIndex = 1;
/**
* stack of objects encoded by stringEncode()
*
* @var array
*/
protected $_encodedObjects = array();
/**
* methodIndex to include in tracebacks when using includeLineNumbers
*
* @var array
*/
protected $_methodIndex = array('info', 'log', 'warn', 'error', 'table', 'trace');
/**
* FireCake output status
*
* @var boolean
*/
protected $_enabled = true;
/**
* get Instance of the singleton
*
* @param string $class Class instance to store in the singleton. Used with subclasses and Tests.
* @return FireCake
*/
public static 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.
* @return void
*/
public static 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
*
* @return boolean
*/
public static function detectClientExtension() {
$ua = FireCake::getUserAgent();
if (preg_match('/\sFirePHP\/([\.|\d]*)\s?/si', $ua, $match) && version_compare($match[1], '0.0.6', '>=')) {
return true;
}
if (env('HTTP_X_FIREPHP_VERSION') && version_compare(env('HTTP_X_FIREPHP_VERSION'), '0.6', '>=')) {
return true;
}
return false;
}
/**
* Get the Current UserAgent
*
* @return string UserAgent string of active client connection
*/
public static function getUserAgent() {
return env('HTTP_USER_AGENT');
}
/**
* Disable FireCake output
* All subsequent output calls will not be run.
*
* @return void
*/
public static function disable() {
$_this = FireCake::getInstance();
$_this->_enabled = false;
}
/**
* Enable FireCake output
*
* @return void
*/
public static 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)
* @return void
*/
public static 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)
* @return void
*/
public static 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)
* @return void
*/
public static 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)
* @return void
*/
public static function error($message, $label = null) {
FireCake::fb($message, $label, 'error');
}
/**
* Convenience wrapper for TABLE messages
*
* @param string $label Label for message (optional)
* @param string $message Message to log
* @return void
*/
public static function table($label, $message) {
FireCake::fb($message, $label, 'table');
}
/**
* Convenience wrapper for DUMP messages
*
* @param string $label Unique label for message
* @param string $message Message to log
* @return void
*/
public static function dump($label, $message) {
FireCake::fb($message, $label, 'dump');
}
/**
* Convenience wrapper for TRACE messages
*
* @param string $label Label for message (optional)
* @return void
*/
public static 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)
* @return void
*/
public static function group($label) {
FireCake::fb(null, $label, 'groupStart');
}
/**
* Convenience wrapper for GROUPEND messages
* Closes a group block
*
* @internal param string $label Label for group (optional)
* @return void
*/
public static 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.
* @return boolean Success
*/
public static function fb($message) {
$_this = FireCake::getInstance();
if (headers_sent($filename, $linenum)) {
trigger_error(__d('debug_kit', 'Headers already sent in %s on line %s. Cannot send log data to FirePHP.', $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(__d('debug_kit', 'Incorrect parameter count for FireCake::fb()'), 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 = FireCake::_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 &&
strtolower($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['groupStart']) {
$meta['Collapsed'] = 'true';
}
if ($type == $_this->_levels['dump']) {
$dump = FireCake::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(__d('debug_kit', 'Maximum number (99,999) of messages reached!'), E_USER_WARNING);
}
}
$_this->_sendHeader('X-Wf-1-Index', $_this->_messageIndex - 1);
return true;
}
/**
* Parse a debug backtrace
*
* @param array $trace Debug backtrace output
* @param $messageName
* @return array
*/
protected static 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']) ? FireCake::stringEncode($trace[$i]['args']) : '',
'Trace' => FireCake::_escapeTrace(array_splice($trace, $i + 1))
);
break;
}
}
return $message;
}
/**
* Fix a trace for use in output
*
* @param mixed $trace Trace to fix
* @return string
*/
protected static 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'] = FireCake::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 integer $objectDepth Current Depth in object chains.
* @param integer $arrayDepth Current Depth in array chains.
* @return string|Object
*/
public static 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 = get_object_vars($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) || $object === null) {
return $object;
}
return $return;
}
/**
* Encode an object into JSON
*
* @param mixed $object Object or array to json encode
* @param boolean $skipEncode
* @internal param bool $doIt
* @static
* @return string
*/
public static function jsonEncode($object, $skipEncode = false) {
$_this = FireCake::getInstance();
if (!$skipEncode) {
$object = FireCake::stringEncode($object);
}
return json_encode($object);
}
/**
* Send Headers - write headers.
*
* @param $name
* @param $value
* @return void
*/
protected function _sendHeader($name, $value) {
header($name . ': ' . $value);
}
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
/**
* A CakeLog listener which saves having to munge files or other configured loggers.
*
*/
class DebugKitLog implements CakeLogInterface {
/**
* logs
*
* @var array
*/
public $logs = array();
/**
* Makes the reverse link needed to get the logs later.
*
* @param $options
* @return \DebugKitLog
*/
public function __construct($options) {
$options['panel']->logger = $this;
}
/**
* Captures log messages in memory
*
* @param $type
* @param $message
* @return void
*/
public function write($type, $message) {
if (!isset($this->logs[$type])) {
$this->logs[$type] = array();
}
$this->logs[$type][] = array(date('Y-m-d H:i:s'), (string)$message);
}
}

View File

@@ -0,0 +1,81 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*
*/
App::uses('DebugPanel', 'DebugKit.Lib');
/**
* Provides information about your PHP and CakePHP environment to assist with debugging.
*
*/
class EnvironmentPanel extends DebugPanel {
/**
* beforeRender - Get necessary data about environment to pass back to controller
*
* @param Controller $controller
* @return array
*/
public function beforeRender(Controller $controller) {
parent::beforeRender($controller);
$return = array();
// PHP Data
$phpVer = phpversion();
$return['php'] = array_merge(array('PHP_VERSION' => $phpVer), $_SERVER);
unset($return['php']['argv']);
// CakePHP Data
$return['cake'] = array(
'APP' => APP,
'APP_DIR' => APP_DIR,
'APPLIBS' => APPLIBS,
'CACHE' => CACHE,
'CAKE' => CAKE,
'CAKE_CORE_INCLUDE_PATH' => CAKE_CORE_INCLUDE_PATH,
'CORE_PATH' => CORE_PATH,
'CAKE_VERSION' => Configure::version(),
'CSS' => CSS,
'CSS_URL' => CSS_URL,
'DS' => DS,
'FULL_BASE_URL' => FULL_BASE_URL,
'IMAGES' => IMAGES,
'IMAGES_URL' => IMAGES_URL,
'JS' => JS,
'JS_URL' => JS_URL,
'LOGS' => LOGS,
'ROOT' => ROOT,
'TESTS' => TESTS,
'TMP' => TMP,
'VENDORS' => VENDORS,
'WEBROOT_DIR' => WEBROOT_DIR,
'WWW_ROOT' => WWW_ROOT
);
$cakeConstants = array_fill_keys(
array(
'DS', 'ROOT', 'FULL_BASE_URL', 'TIME_START', 'SECOND', 'MINUTE', 'HOUR', 'DAY', 'WEEK', 'MONTH', 'YEAR',
'LOG_ERROR', 'FULL_BASE_URL'
), ''
);
$var = get_defined_constants(true);
$return['app'] = array_diff_key($var['user'], $return['cake'], $cakeConstants);
if (isset($var['hidef'])) {
$return['hidef'] = $var['hidef'];
}
return $return;
}
}

View File

@@ -0,0 +1,83 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('DebugPanel', 'DebugKit.Lib');
/**
* Provides debug information on previous requests.
*
*/
class HistoryPanel extends DebugPanel {
/**
* Number of history elements to keep
*
* @var string
*/
public $history = 5;
/**
* Constructor
*
* @param array $settings Array of settings.
* @return \HistoryPanel
*/
public function __construct($settings) {
if (isset($settings['history'])) {
$this->history = $settings['history'];
}
}
/**
* beforeRender callback function
*
* @param Controller $controller
* @return array contents for panel
*/
public function beforeRender(Controller $controller) {
$cacheKey = $controller->Toolbar->cacheKey;
$toolbarHistory = Cache::read($cacheKey, 'debug_kit');
$historyStates = array();
if (is_array($toolbarHistory) && !empty($toolbarHistory)) {
$prefix = array();
if (!empty($controller->request->params['prefix'])) {
$prefix[$controller->request->params['prefix']] = false;
}
foreach ($toolbarHistory as $i => $state) {
if (!isset($state['request']['content']['url'])) {
continue;
}
$title = $state['request']['content']['url'];
$query = @$state['request']['content']['query'];
if (isset($query['url'])) {
unset($query['url']);
}
if (!empty($query)) {
$title .= '?' . urldecode(http_build_query($query));
}
$historyStates[] = array(
'title' => $title,
'url' => array_merge($prefix, array(
'plugin' => 'debug_kit',
'controller' => 'toolbar_access',
'action' => 'history_state',
$i + 1))
);
}
}
if (count($historyStates) >= $this->history) {
array_pop($historyStates);
}
return $historyStates;
}
}

View File

@@ -0,0 +1,160 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('DebugPanel', 'DebugKit.Lib');
/**
* Provides a list of included files for the current request
*
*/
class IncludePanel extends DebugPanel {
/**
* The list of plugins within the application
*
* @var <type>
*/
protected $_pluginPaths = array();
/**
* File Types
*
* @var array
*/
protected $_fileTypes = array(
'Cache', 'Config', 'Configure', 'Console', 'Component', 'Controller',
'Behavior', 'Datasource', 'Model', 'Plugin', 'Test', 'View', 'Utility',
'Network', 'Routing', 'I18n', 'Log', 'Error'
);
/**
* Get a list of plugins on construct for later use
*/
public function __construct() {
foreach (CakePlugin::loaded() as $plugin) {
$this->_pluginPaths[$plugin] = CakePlugin::path($plugin);
}
parent::__construct();
}
/**
* Get a list of files that were included and split them out into the various parts of the app
*
* @param Controller $controller
* @return array
*/
public function beforeRender(Controller $controller) {
$return = array('core' => array(), 'app' => array(), 'plugins' => array());
foreach (get_included_files() as $file) {
$pluginName = $this->_isPluginFile($file);
if ($pluginName) {
$return['plugins'][$pluginName][$this->_getFileType($file)][] = $this->_niceFileName($file, $pluginName);
} elseif ($this->_isAppFile($file)) {
$return['app'][$this->_getFileType($file)][] = $this->_niceFileName($file, 'app');
} elseif ($this->_isCoreFile($file)) {
$return['core'][$this->_getFileType($file)][] = $this->_niceFileName($file, 'core');
}
}
$return['paths'] = $this->_includePaths();
ksort($return['core']);
ksort($return['plugins']);
ksort($return['app']);
return $return;
}
/**
* Get the possible include paths
* @return array
*/
protected function _includePaths() {
$paths = array_flip(array_merge(explode(PATH_SEPARATOR, get_include_path()), array(CAKE)));
unset($paths['.']);
return array_flip($paths);
}
/**
* Check if a path is part of cake core
* @param string $file
* @return boolean
*/
protected function _isCoreFile($file) {
return strstr($file, CAKE);
}
/**
* Check if a path is from APP but not a plugin
* @param string $file
* @return boolean
*/
protected function _isAppFile($file) {
return strstr($file, APP);
}
/**
* Check if a path is from a plugin
* @param string $file
* @return boolean
*/
protected function _isPluginFile($file) {
foreach ($this->_pluginPaths as $plugin => $path) {
if (strstr($file, $path)) {
return $plugin;
}
}
return false;
}
/**
* Replace the path with APP, CORE or the plugin name
* @param string $file
* @param string
* - app for app files
* - core for core files
* - PluginName for the name of a plugin
* @return boolean
*/
protected function _niceFileName($file, $type) {
switch ($type) {
case 'app':
return str_replace(APP, 'APP/', $file);
case 'core':
return str_replace(CAKE, 'CORE/', $file);
default:
return str_replace($this->_pluginPaths[$type], $type . '/', $file);
}
}
/**
* Get the type of file (model, controller etc)
* @param string $file
* @return string
*/
protected function _getFileType($file) {
foreach ($this->_fileTypes as $type) {
if (stripos($file, '/' . $type . '/') !== false) {
return $type;
}
}
return 'Other';
}
}

View File

@@ -0,0 +1,51 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('DebugPanel', 'DebugKit.Lib');
/**
* Log Panel - Reads log entries made this request.
*
*/
class LogPanel extends DebugPanel {
/**
* Constructor - sets up the log listener.
*
* @return \LogPanel
*/
public function __construct() {
parent::__construct();
$existing = CakeLog::configured();
if (empty($existing)) {
CakeLog::config('default', array(
'engine' => 'FileLog'
));
}
CakeLog::config('debug_kit_log_panel', array(
'engine' => 'DebugKit.DebugKitLog',
'panel' => $this
));
}
/**
* beforeRender Callback
*
* @param Controller $controller
* @return array
*/
public function beforeRender(Controller $controller) {
$logger = $this->logger;
return $logger;
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('DebugPanel', 'DebugKit.Lib');
/**
* Provides debug information on the Current request params.
*
*/
class RequestPanel extends DebugPanel {
/**
* beforeRender callback - grabs request params
*
* @param Controller $controller
* @return array
*/
public function beforeRender(Controller $controller) {
$out = array();
$out['params'] = $controller->request->params;
$out['url'] = $controller->request->url;
$out['query'] = $controller->request->query;
$out['data'] = $controller->request->data;
if (isset($controller->Cookie)) {
$out['cookie'] = $controller->Cookie->read();
}
$out['get'] = $_GET;
$out['currentRoute'] = Router::currentRoute();
return $out;
}
}

View File

@@ -0,0 +1,32 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('DebugPanel', 'DebugKit.Lib');
/**
* Provides debug information on the Session contents.
*
*/
class SessionPanel extends DebugPanel {
/**
* beforeRender callback
*
* @param \Controller|object $controller
* @return array
*/
public function beforeRender(Controller $controller) {
$sessions = $controller->Toolbar->Session->read();
return $sessions;
}
}

View File

@@ -0,0 +1,64 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('DebugPanel', 'DebugKit.Lib');
/**
* Provides debug information on the SQL logs and provides links to an ajax explain interface.
*
*/
class SqlLogPanel extends DebugPanel {
/**
* Minimum number of Rows Per Millisecond that must be returned by a query before an explain
* is done.
*
* @var integer
*/
public $slowRate = 20;
/**
* Gets the connection names that should have logs + dumps generated.
*
* @param \Controller|string $controller
* @return array
*/
public function beforeRender(Controller $controller) {
if (!class_exists('ConnectionManager')) {
return array();
}
$connections = array();
$dbConfigs = ConnectionManager::sourceList();
foreach ($dbConfigs as $configName) {
$driver = null;
$db = ConnectionManager::getDataSource($configName);
if (
(empty($db->config['driver']) && empty($db->config['datasource'])) ||
!method_exists($db, 'getLog')
) {
continue;
}
if (isset($db->config['datasource'])) {
$driver = $db->config['datasource'];
}
$explain = false;
$isExplainable = (preg_match('/(Mysql|Postgres)$/', $driver));
if ($isExplainable) {
$explain = true;
}
$connections[$configName] = $explain;
}
return array('connections' => $connections, 'threshold' => $this->slowRate);
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('DebugPanel', 'DebugKit.Lib');
/**
* Provides debug information on all timers used in a request.
*
*/
class TimerPanel extends DebugPanel {
/**
* startup - add in necessary helpers
*
* @param Controller $controller
* @return void
*/
public function startup(Controller $controller) {
if (!in_array('Number', array_keys(HelperCollection::normalizeObjectArray($controller->helpers)))) {
$controller->helpers[] = 'Number';
}
if (!in_array('SimpleGraph', array_keys(HelperCollection::normalizeObjectArray($controller->helpers)))) {
$controller->helpers[] = 'DebugKit.SimpleGraph';
}
}
}

View File

@@ -0,0 +1,31 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('DebugPanel', 'DebugKit.Lib');
/**
* Provides debug information on the View variables.
*
*/
class VariablesPanel extends DebugPanel {
/**
* beforeRender callback
*
* @param Controller $controller
* @return array
*/
public function beforeRender(Controller $controller) {
return array_merge($controller->viewVars, array('$request->data' => $controller->request->data));
}
}