CC-2692: Integrate ZFDebug into Airtime

-done
This commit is contained in:
martin 2011-08-22 10:12:53 -04:00
parent 46133166f3
commit fdf1b4c100
15 changed files with 2268 additions and 0 deletions

View file

@ -93,5 +93,27 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
$view = $this->getResource('view');
$view->headTitle(Application_Model_Preference::GetHeadTitle());
}
protected function _initZFDebug()
{
if (APPLICATION_ENV == "development"){
global $CC_DBC;
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('ZFDebug');
$options = array(
'plugins' => array('Variables',
'Exception',
'Memory',
'Time')
);
$debug = new ZFDebug_Controller_Plugin_Debug($options);
$this->bootstrap('frontController');
$frontController = $this->getResource('frontController');
$frontController->registerPlugin($debug);
}
}
}

View file

@ -0,0 +1,485 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id$
*/
/**
* @see Zend_Controller_Exception
*/
require_once 'Zend/Controller/Exception.php';
/**
* @see Zend_Version
*/
require_once 'Zend/Version.php';
/**
* @see ZFDebug_Controller_Plugin_Debug_Plugin_Text
*/
require_once 'ZFDebug/Controller/Plugin/Debug/Plugin/Text.php';
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug extends Zend_Controller_Plugin_Abstract
{
/**
* Contains registered plugins
*
* @var array
*/
protected $_plugins = array();
/**
* Contains options to change Debug Bar behavior
*/
protected $_options = array(
'plugins' => array(
'Variables' => null,
'Time' => null,
'Memory' => null),
'z-index' => 255,
'jquery_path' => 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js',
'image_path' => null
);
/**
* Standard plugins
*
* @var array
*/
public static $standardPlugins = array('Cache', 'Html', 'Database', 'Exception', 'File', 'Memory', 'Registry', 'Time', 'Variables');
/**
* Debug Bar Version Number
* for internal use only
*
* @var string
*/
protected $_version = '1.5.4';
/**
* Creates a new instance of the Debug Bar
*
* @param array|Zend_Config $options
* @throws Zend_Controller_Exception
* @return void
*/
protected $_closingBracket = null;
public function __construct($options = null)
{
if (isset($options)) {
if ($options instanceof Zend_Config) {
$options = $options->toArray();
}
/*
* Verify that adapter parameters are in an array.
*/
if (!is_array($options)) {
throw new Zend_Exception('Debug parameters must be in an array or a Zend_Config object');
}
$this->setOptions($options);
}
/**
* Creating ZF Version Tab always shown
*/
$version = new ZFDebug_Controller_Plugin_Debug_Plugin_Text();
$version->setPanel($this->_getVersionPanel())
->setTab($this->_getVersionTab())
->setIdentifier('copyright')
->setIconData('data:image/gif;base64,R0lGODlhEAAQAPcAAPb7/ef2+VepAGKzAIC8SavSiYS9Stvt0uTx4fX6+ur1632+QMLgrGOuApDIZO738drs0Ofz5t7v2MfjtPP6+t7v12SzAcvnyX2+PaPRhH2+Qmy3H3K5LPP6+cXkwIHAR2+4JHi7NePz8YC/Rc3ozfH49XK5KXq9OrzdpNzu1YrEUqrVkdzw5uTw4d/v2dDow5zOeO3279Hq0m+4JqrUhpnMbeHw3N3w6Mflwm22HmazBODy7tfu3un06r7gsuXy4sTisIzGXvH59ny9PdPr1rXZpMzlu36/Q5bLb+Pw3tDnxNHr1Lfbm+b199/x62q1Fp3NcdjszqTPh/L599vt04/GWmazCPb7/LHZnW63I3W6MXa7MmGuAt/y7Gq1E2m0Eb7cp9frzZLJaO/489bu3HW3N7rerN/v2q7WjIjEVuLx343FVrDXj9nt0cTjvW2zIoPBSNjv4OT09IXDUpvLeeHw3dPqyNLpxs/nwHe8OIvFWrPaoGe0C5zMb83mvHm8Oen06a3Xl9XqyoC/Qr/htWe0DofDU4nFWbPYk7ndqZ/PfYPBTMPhrqHRgoLBSujz55PKadHpxfX6+6LNeqPQfNXt2pPIYH2+O7vcoHi4OOf2+PL5+NTs2N3u1mi1E7XZl4zEVJjLaZHGauby5KTShmSzBO/38s/oz3i7MtbrzMHiuYTCT4fDTtXqye327uDv3JDHXu328JnMcu738LLanvD49ZTJYpPKauX19tvv44jBWo7GWpfKZ+Dv27XcpcrluXu8ONTs16zXleT08qfUjKzUlc7pzm63HaTRfZXKZuj06HG4KavViGe0EcDfqcjmxaDQgZrNdOHz77/ep4/HYL3esnW6LobCS3S5K57OctDp0JXKbez17N7x6cbkwLTZlbXXmLrcnrvdodHr06PQe8jkt5jIa93v13m8OI7CW3O6L3a7Nb7gs6nUjmu2GqjTgZjKaKLQeZnMc4LAReL08rTbopbLbuTx4KDOdtbry7DYmrvfrrPaoXK5K5zOegAAACH5BAEAAAAALAAAAAAQABAAAAhMAAEIHEiwoMGDCBMOlCKgoUMuHghInEiggEOHAC5eJNhQ4UAuAjwIJLCR4AEBDQS2uHiAYLGOHjNqlCmgYAONApQ0jBGzp8+fQH8GBAA7');
$this->registerPlugin($version);
/**
* Loading aready defined plugins
*/
$this->_loadPlugins();
}
/**
* Sets options of the Debug Bar
*
* @param array $options
* @return ZFDebug_Controller_Plugin_Debug
*/
public function setOptions(array $options = array())
{
if (isset($options['jquery_path'])) {
$this->_options['jquery_path'] = $options['jquery_path'];
}
if (isset($options['z-index'])) {
$this->_options['z-index'] = $options['z-index'];
}
if (isset($options['image_path'])) {
$this->_options['image_path'] = $options['image_path'];
}
if (isset($options['plugins'])) {
$this->_options['plugins'] = $options['plugins'];
}
return $this;
}
/**
* Register a new plugin in the Debug Bar
*
* @param ZFDebug_Controller_Plugin_Debug_Plugin_Interface
* @return ZFDebug_Controller_Plugin_Debug
*/
public function registerPlugin(ZFDebug_Controller_Plugin_Debug_Plugin_Interface $plugin)
{
$this->_plugins[$plugin->getIdentifier()] = $plugin;
return $this;
}
/**
* Unregister a plugin in the Debug Bar
*
* @param string $plugin
* @return ZFDebug_Controller_Plugin_Debug
*/
public function unregisterPlugin($plugin)
{
if (false !== strpos($plugin, '_')) {
foreach ($this->_plugins as $key => $_plugin) {
if ($plugin == get_class($_plugin)) {
unset($this->_plugins[$key]);
}
}
} else {
$plugin = strtolower($plugin);
if (isset($this->_plugins[$plugin])) {
unset($this->_plugins[$plugin]);
}
}
return $this;
}
/**
* Get a registered plugin in the Debug Bar
*
* @param string $identifier
* @return ZFDebug_Controller_Plugin_Debug_Plugin_Interface
*/
public function getPlugin($identifier)
{
$identifier = strtolower($identifier);
if (isset($this->_plugins[$identifier])) {
return $this->_plugins[$identifier];
}
return false;
}
/**
* Defined by Zend_Controller_Plugin_Abstract
*/
public function dispatchLoopShutdown()
{
if ($this->getRequest()->isXmlHttpRequest()) {
return;
}
$disable = Zend_Controller_Front::getInstance()->getRequest()->getParam('ZFDEBUG_DISABLE');
if (isset($disable)) {
return;
}
$html = '';
/**
* Creating menu tab for all registered plugins
*/
foreach ($this->_plugins as $plugin)
{
$panel = $plugin->getPanel();
if ($panel == '') {
continue;
}
/* @var $plugin ZFDebug_Controller_Plugin_Debug_Plugin_Interface */
$html .= '<div id="ZFDebug_' . $plugin->getIdentifier()
. '" class="ZFDebug_panel">' . $panel . '</div>';
}
$html .= '<div id="ZFDebug_info">';
/**
* Creating panel content for all registered plugins
*/
foreach ($this->_plugins as $plugin)
{
$tab = $plugin->getTab();
if ($tab == '') {
continue;
}
if (null !== $this->_options['image_path'] && file_exists($this->_options['image_path'] .'/'. $plugin->getIdentifier() .'.png')) {
$plugin_icon = $this->_options['image_path'] .'/'. $plugin->getIdentifier() .'.png';
} else {
$plugin_icon = $plugin->getIconData();
}
/* @var $plugin ZFDebug_Controller_Plugin_Debug_Plugin_Interface */
$html .= '<span class="ZFDebug_span clickable" onclick="ZFDebugPanel(\'ZFDebug_' . $plugin->getIdentifier() . '\');">';
$html .= '<img src="' . $plugin_icon . '" style="vertical-align:middle" alt="' . $plugin->getIdentifier() . '" title="' . $plugin->getIdentifier() . '"'. $this->getClosingBracket() .' ';
$html .= $tab . '</span>';
}
$html .= '<span class="ZFDebug_span ZFDebug_last clickable" id="ZFDebug_toggler" onclick="ZFDebugSlideBar()">&#171;</span>';
$html .= '</div>';
$this->_output($html);
}
### INTERNAL METHODS BELOW ###
/**
* Load plugins set in config option
*
* @return void;
*/
protected function _loadPlugins()
{
foreach($this->_options['plugins'] as $plugin => $options) {
if (is_numeric($plugin)) {
# Plugin passed as array value instead of key
$plugin = $options;
$options = array();
}
// Register an instance
if (is_object($plugin) && in_array('ZFDebug_Controller_Plugin_Debug_Plugin_Interface', class_implements($plugin))) {
$this->registerPlugin($plugin);
continue;
}
if (!is_string($plugin)) {
throw new Exception("Invalid plugin name", 1);
}
$plugin = ucfirst($plugin);
// Register a classname
if (in_array($plugin, ZFDebug_Controller_Plugin_Debug::$standardPlugins)) {
// standard plugin
$pluginClass = 'ZFDebug_Controller_Plugin_Debug_Plugin_' . $plugin;
} else {
// we use a custom plugin
if (!preg_match('~^[\w]+$~D', $plugin)) {
throw new Zend_Exception("ZFDebug: Invalid plugin name [$plugin]");
}
$pluginClass = $plugin;
}
require_once str_replace('_', DIRECTORY_SEPARATOR, $pluginClass) . '.php';
$object = new $pluginClass($options);
$this->registerPlugin($object);
}
}
/**
* Return version tab
*
* @return string
*/
protected function _getVersionTab()
{
return ' ' . Zend_Version::VERSION . '/'.phpversion();
}
/**
* Returns version panel
*
* @return string
*/
protected function _getVersionPanel()
{
$panel = '<h4>ZFDebug v'.$this->_version.'</h4>' .
'<p>©2008-2009 <a href="http://jokke.dk">Joakim Nygård</a> &amp; <a href="http://www.bangal.de">Andreas Pankratz</a></p>' .
'<p>The project is hosted at <a href="http://code.google.com/p/zfdebug/">http://zfdebug.googlecode.com</a> and released under the BSD License' . $this->getLinebreak() .
'Includes images from the <a href="http://www.famfamfam.com/lab/icons/silk/">Silk Icon set</a> by Mark James</p>'.
'<p>Disable ZFDebug temporarily by sending ZFDEBUG_DISABLE as a GET/POST parameter</p>';
// $panel .= '<h4>Zend Framework '.Zend_Version::VERSION.' / PHP '.phpversion().' with extensions:</h4>';
// $extensions = get_loaded_extensions();
// natcasesort($extensions);
// $panel .= implode('<br>', $extensions);
return $panel;
}
/**
* Returns path to the specific icon
*
* @return string
*/
protected function _icon($kind)
{
switch ($kind) {
case 'database':
if (null === $this->_options['image_path'])
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAEYSURBVBgZBcHPio5hGAfg6/2+R980k6wmJgsJ5U/ZOAqbSc2GnXOwUg7BESgLUeIQ1GSjLFnMwsKGGg1qxJRmPM97/1zXFAAAAEADdlfZzr26miup2svnelq7d2aYgt3rebl585wN6+K3I1/9fJe7O/uIePP2SypJkiRJ0vMhr55FLCA3zgIAOK9uQ4MS361ZOSX+OrTvkgINSjS/HIvhjxNNFGgQsbSmabohKDNoUGLohsls6BaiQIMSs2FYmnXdUsygQYmumy3Nhi6igwalDEOJEjPKP7CA2aFNK8Bkyy3fdNCg7r9/fW3jgpVJbDmy5+PB2IYp4MXFelQ7izPrhkPHB+P5/PjhD5gCgCenx+VR/dODEwD+A3T7nqbxwf1HAAAAAElFTkSuQmCC';
return $this->_options['image_path'] . '/database.png';
break;
case 'exception':
if (null === $this->_options['image_path'])
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAJPSURBVDjLpZPLS5RhFMYfv9QJlelTQZwRb2OKlKuINuHGLlBEBEOLxAu46oL0F0QQFdWizUCrWnjBaDHgThCMoiKkhUONTqmjmDp2GZ0UnWbmfc/ztrC+GbM2dXbv4ZzfeQ7vefKMMfifyP89IbevNNCYdkN2kawkCZKfSPZTOGTf6Y/m1uflKlC3LvsNTWArr9BT2LAf+W73dn5jHclIBFZyfYWU3or7T4K7AJmbl/yG7EtX1BQXNTVCYgtgbAEAYHlqYHlrsTEVQWr63RZFuqsfDAcdQPrGRR/JF5nKGm9xUxMyr0YBAEXXHgIANq/3ADQobD2J9fAkNiMTMSFb9z8ambMAQER3JC1XttkYGGZXoyZEGyTHRuBuPgBTUu7VSnUAgAUAWutOV2MjZGkehgYUA6O5A0AlkAyRnotiX3MLlFKduYCqAtuGXpyH0XQmOj+TIURt51OzURTYZdBKV2UBSsOIcRp/TVTT4ewK6idECAihtUKOArWcjq/B8tQ6UkUR31+OYXP4sTOdisivrkMyHodWejlXwcC38Fvs8dY5xaIId89VlJy7ACpCNCFCuOp8+BJ6A631gANQSg1mVmOxxGQYRW2nHMha4B5WA3chsv22T5/B13AIicWZmNZ6cMchTXUe81Okzz54pLi0uQWp+TmkZqMwxsBV74Or3od4OISPr0e3SHa3PX0f3HXKofNH/UIG9pZ5PeUth+CyS2EMkEqs4fPEOBJLsyske48/+xD8oxcAYPzs4QaS7RR2kbLTTOTQieczfzfTv8QPldGvTGoF6/8AAAAASUVORK5CYII=';
return $this->_options['image_path'] . '/exception.png';
break;
case 'error':
if (null === $this->_options['image_path'])
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAIsSURBVDjLpVNLSJQBEP7+h6uu62vLVAJDW1KQTMrINQ1vPQzq1GOpa9EppGOHLh0kCEKL7JBEhVCHihAsESyJiE4FWShGRmauu7KYiv6Pma+DGoFrBQ7MzGFmPr5vmDFIYj1mr1WYfrHPovA9VVOqbC7e/1rS9ZlrAVDYHig5WB0oPtBI0TNrUiC5yhP9jeF4X8NPcWfopoY48XT39PjjXeF0vWkZqOjd7LJYrmGasHPCCJbHwhS9/F8M4s8baid764Xi0Ilfp5voorpJfn2wwx/r3l77TwZUvR+qajXVn8PnvocYfXYH6k2ioOaCpaIdf11ivDcayyiMVudsOYqFb60gARJYHG9DbqQFmSVNjaO3K2NpAeK90ZCqtgcrjkP9aUCXp0moetDFEeRXnYCKXhm+uTW0CkBFu4JlxzZkFlbASz4CQGQVBFeEwZm8geyiMuRVntzsL3oXV+YMkvjRsydC1U+lhwZsWXgHb+oWVAEzIwvzyVlk5igsi7DymmHlHsFQR50rjl+981Jy1Fw6Gu0ObTtnU+cgs28AKgDiy+Awpj5OACBAhZ/qh2HOo6i+NeA73jUAML4/qWux8mt6NjW1w599CS9xb0mSEqQBEDAtwqALUmBaG5FV3oYPnTHMjAwetlWksyByaukxQg2wQ9FlccaK/OXA3/uAEUDp3rNIDQ1ctSk6kHh1/jRFoaL4M4snEMeD73gQx4M4PsT1IZ5AfYH68tZY7zv/ApRMY9mnuVMvAAAAAElFTkSuQmCC';
return $this->_options['image_path'] . '/error.png';
break;
default:
if (null === $this->_options['image_path'])
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAHhSURBVDjLpZI9SJVxFMZ/r2YFflw/kcQsiJt5b1ije0tDtbQ3GtFQYwVNFbQ1ujRFa1MUJKQ4VhYqd7K4gopK3UIly+57nnMaXjHjqotnOfDnnOd/nt85SURwkDi02+ODqbsldxUlD0mvHw09ubSXQF1t8512nGJ/Uz/5lnxi0tB+E9QI3D//+EfVqhtppGxUNzCzmf0Ekojg4fS9cBeSoyzHQNuZxNyYXp5ZM5Mk1ZkZT688b6thIBenG/N4OB5B4InciYBCVyGnEBHO+/LH3SFKQuF4OEs/51ndXMXC8Ajqknrcg1O5PGa2h4CJUqVES0OO7sYevv2qoFBmJ/4gF4boaOrg6rPLYWaYiVfDo0my8w5uj12PQleB0vcp5I6HsHAUoqUhR29zH+5B4IxNTvDmxljy3x2YCYUwZVlbzXJh9UKeQY6t2m0Lt94Oh5loPdqK3EkjzZi4MM/Y9Db3MTv/mYWVxaqkw9IOATNR7B5ABHPrZQrtg9sb8XDKa1+QOwsri4zeHD9SAzE1wxBTXz9xtvMc5ZU5lirLSKIz18nJnhOZjb22YKkhd4odg5icpcoyL669TAAujlyIvmPHSWXY1ti1AmZ8mJ3ElP1ips1/YM3H300g+W+51nc95YPEX8fEbdA2ReVYAAAAAElFTkSuQmCC';
return $this->_options['image_path'] . '/unknown.png';
break;
}
}
/**
* Returns html header for the Debug Bar
*
* @return string
*/
protected function _headerOutput() {
$collapsed = isset($_COOKIE['ZFDebugCollapsed']) ? $_COOKIE['ZFDebugCollapsed'] : 0;
return ('
<style type="text/css" media="screen">
#ZFDebug_debug { font: 11px/1.4em Lucida Grande, Lucida Sans Unicode, sans-serif; position:fixed; bottom:5px; left:5px; color:#000; z-index: ' . $this->_options['z-index'] . ';}
#ZFDebug_debug ol {margin:10px 0px; padding:0 25px}
#ZFDebug_debug li {margin:0 0 10px 0;}
#ZFDebug_debug .clickable {cursor:pointer}
#ZFDebug_toggler { font-weight:bold; background:#BFBFBF; }
.ZFDebug_span { border: 1px solid #999; border-right:0px; background:#DFDFDF; padding: 5px 5px; }
.ZFDebug_last { border: 1px solid #999; }
.ZFDebug_panel { text-align:left; position:absolute;bottom:21px;width:800px; max-height:400px; overflow:auto; display:none; background:#E8E8E8; padding:5px; border: 1px solid #999; }
.ZFDebug_panel .pre {font: 11px/1.4em Monaco, Lucida Console, monospace; margin:0 0 0 22px}
#ZFDebug_exception { border:1px solid #CD0A0A;display: block; }
</style>
<script type="text/javascript">
if (typeof jQuery == "undefined") {
var scriptObj = document.createElement("script");
scriptObj.src = "'.$this->_options['jquery_path'].'";
scriptObj.type = "text/javascript";
var head=document.getElementsByTagName("head")[0];
head.insertBefore(scriptObj,head.firstChild);
jQuery.noConflict();
}
var ZFDebugLoad = window.onload;
window.onload = function(){
if (ZFDebugLoad) {
ZFDebugLoad();
}
ZFDebugCollapsed();
};
function ZFDebugCollapsed() {
if ('.$collapsed.' == 1) {
ZFDebugPanel();
jQuery("#ZFDebug_toggler").html("&#187;");
return jQuery("#ZFDebug_debug").css("left", "-"+parseInt(jQuery("#ZFDebug_debug").outerWidth()-jQuery("#ZFDebug_toggler").outerWidth()+1)+"px");
}
}
function ZFDebugPanel(name) {
jQuery(".ZFDebug_panel").each(function(i){
if(jQuery(this).css("display") == "block") {
jQuery(this).slideUp();
} else {
if (jQuery(this).attr("id") == name)
jQuery(this).slideDown();
else
jQuery(this).slideUp();
}
});
}
function ZFDebugSlideBar() {
if (jQuery("#ZFDebug_debug").position().left > 0) {
document.cookie = "ZFDebugCollapsed=1;expires=;path=/";
ZFDebugPanel();
jQuery("#ZFDebug_toggler").html("&#187;");
return jQuery("#ZFDebug_debug").animate({left:"-"+parseInt(jQuery("#ZFDebug_debug").outerWidth()-jQuery("#ZFDebug_toggler").outerWidth()+1)+"px"}, "normal", "swing");
} else {
document.cookie = "ZFDebugCollapsed=0;expires=;path=/";
jQuery("#ZFDebug_toggler").html("&#171;");
return jQuery("#ZFDebug_debug").animate({left:"5px"}, "normal", "swing");
}
}
function ZFDebugToggleElement(name, whenHidden, whenVisible){
if(jQuery(name).css("display")=="none"){
jQuery(whenVisible).show();
jQuery(whenHidden).hide();
} else {
jQuery(whenVisible).hide();
jQuery(whenHidden).show();
}
jQuery(name).slideToggle();
}
</script>');
}
/**
* Appends Debug Bar html output to the original page
*
* @param string $html
* @return void
*/
protected function _output($html)
{
$response = $this->getResponse();
$response->setBody(preg_replace('/(<\/head>)/i', $this->_headerOutput() . '$1', $response->getBody()));
$response->setBody(str_ireplace('</body>', '<div id="ZFDebug_debug">'.$html.'</div></body>', $response->getBody()));
}
public function getLinebreak()
{
return '<br'.$this->getClosingBracket();
}
public function getClosingBracket()
{
if (!$this->_closingBracket) {
if ($this->_isXhtml()) {
$this->_closingBracket = ' />';
} else {
$this->_closingBracket = '>';
}
}
return $this->_closingBracket;
}
protected function _isXhtml()
{
if ($view = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view) {
$doctype = $view->doctype();
return $doctype->isXhtml();
}
return false;
}
}

View file

@ -0,0 +1,92 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id: $
*/
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug_Plugin
{
protected $_closingBracket = null;
public function getLinebreak()
{
return '<br'.$this->getClosingBracket();
}
public function getIconData()
{
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAHhSURBVDjLpZI9SJVxFMZ/r2YFflw/kcQsiJt5b1ije0tDtbQ3GtFQYwVNFbQ1ujRFa1MUJKQ4VhYqd7K4gopK3UIly+57nnMaXjHjqotnOfDnnOd/nt85SURwkDi02+ODqbsldxUlD0mvHw09ubSXQF1t8512nGJ/Uz/5lnxi0tB+E9QI3D//+EfVqhtppGxUNzCzmf0Ekojg4fS9cBeSoyzHQNuZxNyYXp5ZM5Mk1ZkZT688b6thIBenG/N4OB5B4InciYBCVyGnEBHO+/LH3SFKQuF4OEs/51ndXMXC8Ajqknrcg1O5PGa2h4CJUqVES0OO7sYevv2qoFBmJ/4gF4boaOrg6rPLYWaYiVfDo0my8w5uj12PQleB0vcp5I6HsHAUoqUhR29zH+5B4IxNTvDmxljy3x2YCYUwZVlbzXJh9UKeQY6t2m0Lt94Oh5loPdqK3EkjzZi4MM/Y9Db3MTv/mYWVxaqkw9IOATNR7B5ABHPrZQrtg9sb8XDKa1+QOwsri4zeHD9SAzE1wxBTXz9xtvMc5ZU5lirLSKIz18nJnhOZjb22YKkhd4odg5icpcoyL669TAAujlyIvmPHSWXY1ti1AmZ8mJ3ElP1ips1/YM3H300g+W+51nc95YPEX8fEbdA2ReVYAAAAAElFTkSuQmCC';
}
public function getClosingBracket()
{
if (!$this->_closingBracket) {
if ($this->_isXhtml()) {
$this->_closingBracket = ' />';
} else {
$this->_closingBracket = '>';
}
}
return $this->_closingBracket;
}
protected function _isXhtml()
{
$view = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view;
$doctype = $view->doctype();
return $doctype->isXhtml();
}
/**
* Transforms data into readable format
*
* @param array $values
* @return string
*/
protected function _cleanData($values)
{
$linebreak = $this->getLinebreak();
if (is_array($values)) {
ksort($values);
}
$retVal = '<div class="pre">';
foreach ($values as $key => $value)
{
$key = htmlspecialchars($key);
if (is_numeric($value)) {
$retVal .= $key.' => '.$value.$linebreak;
}
else if (is_string($value)) {
$retVal .= $key.' => \''.htmlspecialchars($value).'\''.$linebreak;
}
else if (is_array($value))
{
$retVal .= $key.' => '.self::_cleanData($value);
}
else if (is_object($value))
{
$retVal .= $key.' => '.get_class($value).' Object()'.$linebreak;
}
else if (is_null($value))
{
$retVal .= $key.' => NULL'.$linebreak;
}
}
return $retVal.'</div>';
}
}

View file

@ -0,0 +1,129 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id: $
*/
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug_Plugin_Auth implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface
{
/**
* Contains plugin identifier name
*
* @var string
*/
protected $_identifier = 'auth';
/**
* Contains Zend_Auth object
*
* @var Zend_Auth
*/
protected $_auth;
/**
* Contains "column name" for the username
*
* @var string
*/
protected $_user = 'user';
/**
* Contains "column name" for the role
*
* @var string
*/
protected $_role = 'role';
/**
* Contains Acls for this application
*
* @var Zend_Acl
*/
protected $_acl;
/**
* Create ZFDebug_Controller_Plugin_Debug_Plugin_Auth
*
* @var string $user
* @var string $role
* @return void
*/
public function __construct(array $options = array())
{
$this->_auth = Zend_Auth::getInstance();
if (isset($options['user'])) {
$this->_user = $options['user'];
}
if (isset($options['role'])) {
$this->_role = $options['role'];
}
}
/**
* Gets identifier for this plugin
*
* @return string
*/
public function getIdentifier()
{
return $this->_identifier;
}
/**
* Returns the base64 encoded icon
*
* @return string
**/
public function getIconData()
{
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAJ3SURBVDjLpZNtSNNRFIcNKunF1rZWBMJqKaSiX9RP1dClsjldA42slW0q5oxZiuHrlqllLayoaJa2jbm1Lc3QUZpKFmmaTMsaRp+kMgjBheSmTL2//kqMBJlFHx44XM7vOfdyuH4A/P6HFQ9zo7cpa/mM6RvCrVDzaVDy6C5JJKv6rwSnIhlFd0R0Up/GwF2KWyl01CTSkM/dQoQRzAurCjRCGnRUUE2FaoSL0HExiYVzsQwcj6RNrSqo4W5Gh6Yc4+1qDDTkIy+GhYK4nTgdz0H2PrrHUJzs71NQn86enPn+CVN9GnzruoYR63mMPbkC59gQzDl7pt7rc9f7FNyUhPY6Bx9gwt4E9zszhWWpdg6ZcS8j3O7zCTuEpnXB+3MNZkUUZu0NmHE8XsL91oSWwiiEc3MeseLrN6woYCWa/Zl8ozyQ3w3Hl2lYy0SwlCUvsVi/Gv2JwITnYPDun2Hy6jYuEzAF1jUBCVYpO6kXo+NuGMeBAgcgfwNkvgBOPgUqXgKvP7rBFvRhE1crp8Vq1noFYSlacVyqGk0D86gbART9BDk9BFnPCNJbCY5aCFL1Cyhtp0RWAp74MsKSrkq9guHyvfMTtmLc1togpZoyqYmyNoITzVTYRJCiXYBIQ3CwFqi83o3JDhX6C0M8XsGIMoQ4OyuRlq1DdZcLkmbgGDX1iIEKNxAcbgTEOqC4ZRaJ6Ub86K7CYFEo8Qo+GBQlQyXBczLZpbloaQ9k1NUz/kD2myBBKxRZpa5hVcQslalatoUxizxAVVrN3CW21bFj9F858Q9dnIRmDyeuybM71uxmH9BNBB1q6zybV7H9s1Ue4PM3/gu/AEbfqfWy2twsAAAAAElFTkSuQmCC';
}
/**
* Gets menu tab for the Debugbar
*
* @return string
*/
public function getTab()
{
$username = 'Not Authed';
$role = 'Unknown Role';
if(!$this->_auth->hasIdentity()) {
return 'Not authorized';
}
$identity = $this->_auth->getIdentity();
if (is_object($identity)) {
$username = $this->_auth->getIdentity()->{$this->_user};
$role = $this->_auth->getIdentity()->{$this->_role};
}
else {
$username = $this->_auth->getIdentity();
$role = '';
}
return $username . ' (' . $role . ')';
}
/**
* Gets content panel for the Debugbar
*
* @return string
*/
public function getPanel()
{
return '';
}
}

View file

@ -0,0 +1,132 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id$
*/
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug_Plugin_Cache extends ZFDebug_Controller_Plugin_Debug_Plugin implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface
{
/**
* Contains plugin identifier name
*
* @var string
*/
protected $_identifier = 'cache';
/**
* @var Zend_Cache_Backend_ExtendedInterface
*/
protected $_cacheBackends = array();
/**
* Create ZFDebug_Controller_Plugin_Debug_Plugin_Cache
*
* @param array $options
* @return void
*/
public function __construct(array $options = array())
{
if (!isset($options['backend'])) {
throw new Zend_Exception("ZFDebug: Cache plugin needs 'backend' parameter");
}
is_array($options['backend']) || $options['backend'] = array($options['backend']);
foreach ($options['backend'] as $name => $backend) {
if ($backend instanceof Zend_Cache_Backend_ExtendedInterface ) {
$this->_cacheBackends[$name] = $backend;
}
}
}
/**
* Gets identifier for this plugin
*
* @return string
*/
public function getIdentifier()
{
return $this->_identifier;
}
/**
* Returns the base64 encoded icon
*
* @return string
**/
public function getIconData()
{
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAI/SURBVDjLjZPbS9NhHMYH+zNidtCSQrqwQtY5y2QtT2QGrTZf13TkoYFlzsWa/tzcoR3cSc2xYUlGJfzAaIRltY0N12H5I+jaOxG8De+evhtdOP1hu3hv3sPzPO/z4SsBIPnfuvG8cbBlWiEVO5OUItA0VS8oxi9EdhXo+6yV3V3UGHRvVXHNfNv6zRfNuBZVoiFcB/3LdnQ8U+Gk+bhPVKB3qUOuf6/muaQR/qwDkZ9BRFdCmMr5EPz6BN7lMYylLGgNNaKqt3K0SKDnQ7us690t3rNsxeyvaUz+8OJpzo/QNzd8WTtcaQ7WlBmPvxhx1V2Pg7oDziIBimwwf3qAGWESkVwQ7owNujk1ztvk+cg4NnAUTT4FrrjqUKHdF9jxBfXr1rgjaSk4OlMcLrnOrJ7latxbL1V2lgvlbG9MtMTrMw1r1PImtfyn1n5q47TlBLf90n5NmalMtUdKZoyQMkLKlIGLjMyYhFpmlz3nGEVmFJlRZNaf7pIaEndM24XIjCOzjX9mm2S2JsqdkMYIqbB1j5C6yWzVk7YRFTsGFu7l+4nveExIA9aMCcOJh6DIoMigyOh+o4UryRWQOtIjaJtoziM1FD0mpE4uZcTc72gBaUyYKEI6khgqINXO3saR7kM8IZUVCRDS0Ucf+xFbCReQhr97MZ51wpWxYnhpCD3zOrT4lTisr+AJqVx0Fiiyr4/vhP4VyyMFIUWNqRrV96vWKXKckBoIqWzXYcoPDrUslDJoopuEVEpIB0sR+AuErIiZ6OqMKAAAAABJRU5ErkJggg==';
}
/**
* Gets menu tab for the Debugbar
*
* @return string
*/
public function getTab()
{
return 'Cache';
}
/**
* Gets content panel for the Debugbar
*
* @return string
*/
public function getPanel()
{
$panel = '';
# Support for APC
if (function_exists('apc_sma_info') && ini_get('apc.enabled')) {
$mem = apc_sma_info();
$mem_size = $mem['num_seg']*$mem['seg_size'];
$mem_avail = $mem['avail_mem'];
$mem_used = $mem_size-$mem_avail;
$cache = apc_cache_info();
$panel .= '<h4>APC '.phpversion('apc').' Enabled</h4>';
$panel .= round($mem_avail/1024/1024, 1).'M available, '.round($mem_used/1024/1024, 1).'M used'.$this->getLinebreak()
. $cache['num_entries'].' Files cached ('.round($cache['mem_size']/1024/1024, 1).'M)'.$this->getLinebreak()
. $cache['num_hits'].' Hits ('.round($cache['num_hits'] * 100 / ($cache['num_hits']+$cache['num_misses']), 1).'%)'.$this->getLinebreak()
. $cache['expunges'].' Expunges (cache full count)';
}
foreach ($this->_cacheBackends as $name => $backend) {
$fillingPercentage = $backend->getFillingPercentage();
$ids = $backend->getIds();
# Print full class name, backends might be custom
$panel .= '<h4>Cache '.$name.' ('.get_class($backend).')</h4>';
$panel .= count($ids).' Entr'.(count($ids)>1?'ies':'y').''.$this->getLinebreak()
. 'Filling Percentage: '.$backend->getFillingPercentage().'%'.$this->getLinebreak();
$cacheSize = 0;
foreach ($ids as $id)
{
# Calculate valid cache size
$mem_pre = memory_get_usage();
if ($cached = $backend->load($id)) {
$mem_post = memory_get_usage();
$cacheSize += $mem_post-$mem_pre;
unset($cached);
}
}
$panel .= 'Valid Cache Size: '.round($cacheSize/1024, 1). 'K';
}
return $panel;
}
}

View file

@ -0,0 +1,170 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id$
*/
/**
* @see Zend_Db_Table_Abstract
*/
require_once 'Zend/Db/Table/Abstract.php';
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug_Plugin_Database extends ZFDebug_Controller_Plugin_Debug_Plugin implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface
{
/**
* Contains plugin identifier name
*
* @var string
*/
protected $_identifier = 'database';
/**
* @var array
*/
protected $_db = array();
protected $_explain = false;
/**
* Create ZFDebug_Controller_Plugin_Debug_Plugin_Variables
*
* @param Zend_Db_Adapter_Abstract|array $adapters
* @return void
*/
public function __construct(array $options = array())
{
if(!isset($options['adapter']) || !count($options['adapter'])) {
if (Zend_Db_Table_Abstract::getDefaultAdapter()) {
$this->_db[0] = Zend_Db_Table_Abstract::getDefaultAdapter();
$this->_db[0]->getProfiler()->setEnabled(true);
}
} else if ($options['adapter'] instanceof Zend_Db_Adapter_Abstract ) {
$this->_db[0] = $options['adapter'];
$this->_db[0]->getProfiler()->setEnabled(true);
} else {
foreach ($options['adapter'] as $name => $adapter) {
if ($adapter instanceof Zend_Db_Adapter_Abstract) {
$adapter->getProfiler()->setEnabled(true);
$this->_db[$name] = $adapter;
}
}
}
if (isset($options['explain'])) {
$this->_explain = (bool)$options['explain'];
}
}
/**
* Gets identifier for this plugin
*
* @return string
*/
public function getIdentifier()
{
return $this->_identifier;
}
/**
* Returns the base64 encoded icon
*
* @return string
**/
public function getIconData()
{
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAEYSURBVBgZBcHPio5hGAfg6/2+R980k6wmJgsJ5U/ZOAqbSc2GnXOwUg7BESgLUeIQ1GSjLFnMwsKGGg1qxJRmPM97/1zXFAAAAEADdlfZzr26miup2svnelq7d2aYgt3rebl585wN6+K3I1/9fJe7O/uIePP2SypJkiRJ0vMhr55FLCA3zgIAOK9uQ4MS361ZOSX+OrTvkgINSjS/HIvhjxNNFGgQsbSmabohKDNoUGLohsls6BaiQIMSs2FYmnXdUsygQYmumy3Nhi6igwalDEOJEjPKP7CA2aFNK8Bkyy3fdNCg7r9/fW3jgpVJbDmy5+PB2IYp4MXFelQ7izPrhkPHB+P5/PjhD5gCgCenx+VR/dODEwD+A3T7nqbxwf1HAAAAAElFTkSuQmCC';
}
/**
* Gets menu tab for the Debugbar
*
* @return string
*/
public function getTab()
{
if (!$this->_db)
return 'No adapter';
foreach ($this->_db as $adapter) {
$profiler = $adapter->getProfiler();
$adapterInfo[] = $profiler->getTotalNumQueries().' in '.round($profiler->getTotalElapsedSecs()*1000, 2).' ms';
}
$html = implode(' / ', $adapterInfo);
return $html;
}
/**
* Gets content panel for the Debugbar
*
* @return string
*/
public function getPanel()
{
if (!$this->_db)
return '';
$html = '<h4>Database queries</h4>';
if (Zend_Db_Table_Abstract::getDefaultMetadataCache ()) {
$html .= 'Metadata cache is ENABLED';
} else {
$html .= 'Metadata cache is DISABLED';
}
# For adding quotes to query params
function add_quotes(&$value, $key) {
$value = "'".$value."'";
}
foreach ($this->_db as $name => $adapter) {
if ($profiles = $adapter->getProfiler()->getQueryProfiles()) {
$adapter->getProfiler()->setEnabled(false);
$html .= '<h4>Adapter '.$name.'</h4><ol>';
foreach ($profiles as $profile) {
$params = $profile->getQueryParams();
array_walk($params, 'add_quotes');
$paramCount = count($params);
if ($paramCount) {
$html .= '<li>'.htmlspecialchars(preg_replace(array_fill(0, $paramCount, '/\?/'), $params, $profile->getQuery(), 1));
} else {
$html .= '<li>'.htmlspecialchars($profile->getQuery());
}
$html .= '<p><strong>Time:</strong> '.round($profile->getElapsedSecs()*1000, 2).' ms'.$this->getLinebreak();
$supportedAdapter = ($adapter instanceof Zend_Db_Adapter_Mysqli
|| $adapter instanceof Zend_Db_Adapter_Pdo_Mysql);
# Run explain if enabled, supported adapter and SELECT query
if ($this->_explain && $supportedAdapter && Zend_Db_Profiler::SELECT == $profile->getQueryType()) {
$explain = $adapter->fetchRow('EXPLAIN '.$profile->getQuery());
$html .= '<strong>Type:</strong> '.strtolower($explain['select_type']).', '.$explain['type'].$this->getLinebreak()
.'<strong>Possible Keys:</strong> '.$explain['possible_keys'].$this->getLinebreak()
.'<strong>Key Used:</strong> '.$explain['key'].$this->getLinebreak()
.'<strong>Rows:</strong> '.$explain['rows'].$this->getLinebreak()
.'<strong>Extra:</strong> '.$explain['Extra'];
}
$html .= '</p></li>';
}
$html .= '</ol>';
}
}
return $html;
}
}

View file

@ -0,0 +1,163 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id$
*/
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug_Plugin_Exception implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface
{
/**
* Contains plugin identifier name
*
* @var string
*/
protected $_identifier = 'exception';
/**
* Contains any errors
*
* @var param array
*/
static $errors = array();
/**
* Gets identifier for this plugin
*
* @return string
*/
public function getIdentifier ()
{
return $this->_identifier;
}
/**
* Returns the base64 encoded icon
*
* @return string
**/
public function getIconData()
{
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAJPSURBVDjLpZPLS5RhFMYfv9QJlelTQZwRb2OKlKuINuHGLlBEBEOLxAu46oL0F0QQFdWizUCrWnjBaDHgThCMoiKkhUONTqmjmDp2GZ0UnWbmfc/ztrC+GbM2dXbv4ZzfeQ7vefKMMfifyP89IbevNNCYdkN2kawkCZKfSPZTOGTf6Y/m1uflKlC3LvsNTWArr9BT2LAf+W73dn5jHclIBFZyfYWU3or7T4K7AJmbl/yG7EtX1BQXNTVCYgtgbAEAYHlqYHlrsTEVQWr63RZFuqsfDAcdQPrGRR/JF5nKGm9xUxMyr0YBAEXXHgIANq/3ADQobD2J9fAkNiMTMSFb9z8ambMAQER3JC1XttkYGGZXoyZEGyTHRuBuPgBTUu7VSnUAgAUAWutOV2MjZGkehgYUA6O5A0AlkAyRnotiX3MLlFKduYCqAtuGXpyH0XQmOj+TIURt51OzURTYZdBKV2UBSsOIcRp/TVTT4ewK6idECAihtUKOArWcjq/B8tQ6UkUR31+OYXP4sTOdisivrkMyHodWejlXwcC38Fvs8dY5xaIId89VlJy7ACpCNCFCuOp8+BJ6A631gANQSg1mVmOxxGQYRW2nHMha4B5WA3chsv22T5/B13AIicWZmNZ6cMchTXUe81Okzz54pLi0uQWp+TmkZqMwxsBV74Or3od4OISPr0e3SHa3PX0f3HXKofNH/UIG9pZ5PeUth+CyS2EMkEqs4fPEOBJLsyske48/+xD8oxcAYPzs4QaS7RR2kbLTTOTQieczfzfTv8QPldGvTGoF6/8AAAAASUVORK5CYII=';
}
/**
* Creates Error Plugin ans sets the Error Handler
*
* @return void
*/
public function __construct ()
{
set_error_handler(array($this , 'errorHandler'));
}
/**
* Gets menu tab for the Debugbar
*
* @return string
*/
public function getTab ()
{
$response = Zend_Controller_Front::getInstance()->getResponse();
$errorCount = count(self::$errors);
if (! $response->isException() && ! $errorCount)
return '';
$error = '';
$exception = '';
if ($errorCount)
$error = ($errorCount == 1 ? '1 Error' : $errorCount . ' Errors');
$count = count($response->getException());
//if ($this->_options['show_exceptions'] && $count)
if ($count)
$exception = ($count == 1) ? '1 Exception' : $count . ' Exceptions';
$text = $exception . ($exception == '' || $error == '' ? '' : ' - ') . $error;
return $text;
}
/**
* Gets content panel for the Debugbar
*
* @return string
*/
public function getPanel ()
{
$response = Zend_Controller_Front::getInstance()->getResponse();
$errorCount = count(self::$errors);
if (! $response->isException() && ! $errorCount)
return '';
$html = '';
foreach ($response->getException() as $e) {
$html .= '<h4>' . get_class($e) . ': ' . $e->getMessage() . '</h4><p>thrown in ' . $e->getFile() . ' on line ' . $e->getLine() . '</p>';
$html .= '<h4>Call Stack</h4><ol>';
foreach ($e->getTrace() as $t) {
$func = $t['function'] . '()';
if (isset($t['class']))
$func = $t['class'] . $t['type'] . $func;
if (! isset($t['file']))
$t['file'] = 'unknown';
if (! isset($t['line']))
$t['line'] = 'n/a';
$html .= '<li>' . $func . '<br>in ' . str_replace($_SERVER['DOCUMENT_ROOT'], '', $t['file']) . ' on line ' . $t['line'] . '</li>';
}
$html .= '</ol>';
}
if ($errorCount) {
$html .= '<h4>Errors</h4><ol>';
foreach (self::$errors as $error) {
$html .= '<li>' . sprintf("%s: %s in %s on line %d", $error['type'], $error['message'], str_replace($_SERVER['DOCUMENT_ROOT'], '', $error['file']), $error['line']) . '</li>';
}
$html .= '</ol>';
}
return $html;
}
/**
* Debug Bar php error handler
*
* @param string $level
* @param string $message
* @param string $file
* @param string $line
* @return bool
*/
public static function errorHandler ($level, $message, $file, $line)
{
if (! ($level & error_reporting()))
return false;
switch ($level) {
case E_NOTICE:
case E_USER_NOTICE:
$type = 'Notice';
break;
case E_WARNING:
case E_USER_WARNING:
$type = 'Warning';
break;
case E_ERROR:
case E_USER_ERROR:
$type = 'Fatal Error';
break;
default:
$type = 'Unknown, ' . $level;
break;
}
self::$errors[] = array('type' => $type , 'message' => $message , 'file' => $file , 'line' => $line);
if (ini_get('log_errors'))
error_log(sprintf("%s: %s in %s on line %d", $type, $message, $file, $line));
return true;
}
}

View file

@ -0,0 +1,166 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id$
*/
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug_Plugin_File extends ZFDebug_Controller_Plugin_Debug_Plugin implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface
{
/**
* Contains plugin identifier name
*
* @var string
*/
protected $_identifier = 'file';
/**
* Base path of this application
* String is used to strip it from filenames
*
* @var string
*/
protected $_basePath;
/**
* Stores included files
*
* @var array
*/
protected $_includedFiles = null;
/**
* Stores name of own extension library
*
* @var string
*/
protected $_library;
/**
* Setting Options
*
* basePath:
* This will normally not your document root of your webserver, its your
* application root directory with /application, /library and /public
*
* library:
* Your own library extension(s)
*
* @param array $options
* @return void
*/
public function __construct(array $options = array())
{
isset($options['base_path']) || $options['base_path'] = $_SERVER['DOCUMENT_ROOT'];
isset($options['library']) || $options['library'] = null;
$this->_basePath = realpath($options['base_path']);
is_array($options['library']) || $options['library'] = array($options['library']);
$this->_library = array_merge($options['library'], array('Zend', 'ZFDebug'));
}
/**
* Gets identifier for this plugin
*
* @return string
*/
public function getIdentifier()
{
return $this->_identifier;
}
/**
* Returns the base64 encoded icon
*
* @return string
**/
public function getIconData()
{
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAADPSURBVCjPdZFNCsIwEEZHPYdSz1DaHsMzuPM6RRcewSO4caPQ3sBDKCK02p+08DmZtGkKlQ+GhHm8MBmiFQUU2ng0B7khClTdQqdBiX1Ma1qMgbDlxh0XnJHiit2JNq5HgAo3KEx7BFAM/PMI0CDB2KNvh1gjHZBi8OR448GnAkeNDEDvKZDh2Xl4cBcwtcKXkZdYLJBYwCCFPDRpMEjNyKcDPC4RbXuPiWKkNABPOuNhItegz0pGFkD+y3p0s48DDB43dU7+eLWes3gdn5Y/LD9Y6skuWXcAAAAASUVORK5CYII=';
}
/**
* Gets menu tab for the Debugbar
*
* @return string
*/
public function getTab()
{
return count($this->_getIncludedFiles()) . ' Files';
}
/**
* Gets content panel for the Debugbar
*
* @return string
*/
public function getPanel()
{
$included = $this->_getIncludedFiles();
$html = '<h4>File Information</h4>';
$html .= count($included).' Files Included'.$this->getLinebreak();
$size = 0;
foreach ($included as $file) {
$size += filesize($file);
}
$html .= 'Total Size: '. round($size/1024, 1).'K'.$this->getLinebreak();
$html .= 'Basepath: ' . $this->_basePath .$this->getLinebreak();
$libraryFiles = array();
foreach ($this->_library as $key => $value) {
if ('' != $value) {
$libraryFiles[$key] = '<h4>' . $value . ' Files</h4>';
}
}
$html .= '<h4>Application Files</h4>';
foreach ($included as $file) {
$file = str_replace($this->_basePath, '', $file);
$filePaths = explode(DIRECTORY_SEPARATOR, $file);
$inUserLib = false;
foreach ($this->_library as $key => $library)
{
if('' != $library && in_array($library, $filePaths)) {
$libraryFiles[$key] .= $file . $this->getLinebreak();
$inUserLib = TRUE;
}
}
if (!$inUserLib) {
$html .= $file .$this->getLinebreak();
}
}
$html .= implode('', $libraryFiles);
return $html;
}
/**
* Gets included files
*
* @return array
*/
protected function _getIncludedFiles()
{
if (null !== $this->_includedFiles) {
return $this->_includedFiles;
}
$this->_includedFiles = get_included_files();
sort($this->_includedFiles);
return $this->_includedFiles;
}
}

View file

@ -0,0 +1,101 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id$
*/
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug_Plugin_Html extends ZFDebug_Controller_Plugin_Debug_Plugin implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface
{
/**
* Contains plugin identifier name
*
* @var string
*/
protected $_identifier = 'html';
/**
* Create ZFDebug_Controller_Plugin_Debug_Plugin_Html
*
* @param string $tab
* @paran string $panel
* @return void
*/
public function __construct()
{
}
/**
* Gets identifier for this plugin
*
* @return string
*/
public function getIdentifier()
{
return $this->_identifier;
}
/**
* Returns the base64 encoded icon
*
* @return string
**/
public function getIconData()
{
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAEdSURBVDjLjZIxTgNBDEXfbDZIlIgmCKWgSpMGxEk4AHehgavQcJY0KRKJJiBQLkCR7PxvmiTsbrJoLY1sy/Ibe+an9XodtqkfSUd+Op0mTlgpidFodKpGRAAwn8/pstI2AHvfbi6KAkndgHZx31iP2/CTE3Q1A0ji6fUjsiFn8fJ4k44mSCmR0sl3QhJXF2fYwftXPl5hsVg0Xr0d2yZnIwWbqrlyOZlMDtc+v33H9eUQO7ACOZAC2Ye8qqIJqCfZRtnIIBnVQH8AdQOqylTZWPBwX+zGj93ZrXU7ZLlcxj5vArYi5/Iweh+BNQCbrVl8/uAMvjvvJbBU/++6rVarGI/HB0BbI4PBgNlsRtGlsL4CK7sAfQX2L6CPwH4BZf1E9tbX5ioAAAAASUVORK5CYII=';
}
/**
* Gets menu tab for the Debugbar
*
* @return string
*/
public function getTab()
{
return 'HTML';
}
/**
* Gets content panel for the Debugbar
*
* @return string
*/
public function getPanel()
{
$body = Zend_Controller_Front::getInstance()->getResponse()->getBody();
$panel = '<h4>HTML Information</h4>';
$panel .= $this->_isXhtml().'
<script type="text/javascript">
var ZFHtmlLoad = window.onload;
window.onload = function(){
if (ZFHtmlLoad) {
ZFHtmlLoad();
}
jQuery("#ZFDebug_Html_Tagcount").html(document.getElementsByTagName("*").length);
jQuery("#ZFDebug_Html_Stylecount").html(jQuery("link[rel*=stylesheet]").length);
jQuery("#ZFDebug_Html_Scriptcount").html(jQuery("script[src]").length);
jQuery("#ZFDebug_Html_Imgcount").html(jQuery("img[src]").length);
};
</script>';
$panel .= '<span id="ZFDebug_Html_Tagcount"></span> Tags'.$this->getLinebreak()
. 'HTML Size: '.round(strlen($body)/1024, 2).'K'.$this->getLinebreak()
. '<span id="ZFDebug_Html_Stylecount"></span> Stylesheet Files'.$this->getLinebreak()
. '<span id="ZFDebug_Html_Scriptcount"></span> Javascript Files'.$this->getLinebreak()
. '<span id="ZFDebug_Html_Imgcount"></span> Images'.$this->getLinebreak()
. '<form method="post" action="http://validator.w3.org/check"><p><input type="hidden" name="fragment" value="'.htmlentities($body).'"'.$this->getClosingBracket().'<input type="submit" value="Validate With W3C"'.$this->getClosingBracket().'</p></form>';
return $panel;
}
}

View file

@ -0,0 +1,50 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id$
*/
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
interface ZFDebug_Controller_Plugin_Debug_Plugin_Interface
{
/**
* Has to return html code for the menu tab
*
* @return string
*/
public function getTab();
/**
* Has to return html code for the content panel
*
* @return string
*/
public function getPanel();
/**
* Has to return a unique identifier for the specific plugin
*
* @return string
*/
public function getIdentifier();
/**
* Return the path to an icon
*
* @return string
*/
public function getIconData();
}

View file

@ -0,0 +1,165 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id$
*/
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug_Plugin_Memory extends Zend_Controller_Plugin_Abstract implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface
{
/**
* Contains plugin identifier name
*
* @var string
*/
protected $_identifier = 'memory';
/**
* @var array
*/
protected $_memory = array(
'dispatchLoopShutdown' => 0,
'dispatchLoopStartup' => 0
);
protected $_closingBracket = null;
/**
* Creating time plugin
* @return void
*/
public function __construct()
{
Zend_Controller_Front::getInstance()->registerPlugin($this);
}
/**
* Gets identifier for this plugin
*
* @return string
*/
public function getIdentifier()
{
return $this->_identifier;
}
/**
* Returns the base64 encoded icon
*
* @return string
**/
public function getIconData()
{
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAGvSURBVDjLpZO7alZREEbXiSdqJJDKYJNCkPBXYq12prHwBezSCpaidnY+graCYO0DpLRTQcR3EFLl8p+9525xgkRIJJApB2bN+gZmqCouU+NZzVef9isyUYeIRD0RTz482xouBBBNHi5u4JlkgUfx+evhxQ2aJRrJ/oFjUWysXeG45cUBy+aoJ90Sj0LGFY6anw2o1y/mK2ZS5pQ50+2XiBbdCvPk+mpw2OM/Bo92IJMhgiGCox+JeNEksIC11eLwvAhlzuAO37+BG9y9x3FTuiWTzhH61QFvdg5AdAZIB3Mw50AKsaRJYlGsX0tymTzf2y1TR9WwbogYY3ZhxR26gBmocrxMuhZNE435FtmSx1tP8QgiHEvj45d3jNlONouAKrjjzWaDv4CkmmNu/Pz9CzVh++Yd2rIz5tTnwdZmAzNymXT9F5AtMFeaTogJYkJfdsaaGpyO4E62pJ0yUCtKQFxo0hAT1JU2CWNOJ5vvP4AIcKeao17c2ljFE8SKEkVdWWxu42GYK9KE4c3O20pzSpyyoCx4v/6ECkCTCqccKorNxR5uSXgQnmQkw2Xf+Q+0iqQ9Ap64TwAAAABJRU5ErkJggg==';
}
/**
* Gets menu tab for the Debugbar
*
* @return string
*/
public function getTab()
{
if (function_exists('memory_get_peak_usage')) {
return round(memory_get_peak_usage()/1024) . 'K of '.ini_get("memory_limit");
}
return 'MemUsage n.a.';
}
/**
* Gets content panel for the Debugbar
*
* @return string
*/
public function getPanel()
{
$panel = '<h4>Memory Usage</h4>';
$panel .= 'Dispatch: ' . round(($this->_memory['dispatchLoopShutdown']-$this->_memory['dispatchLoopStartup'])/1024,2) .'K'.$this->getLinebreak();
if (isset($this->_memory['user']) && count($this->_memory['user'])) {
foreach ($this->_memory['user'] as $key => $value) {
$panel .= $key.': '.round($value/1024).'K'.$this->getLinebreak();
}
}
return $panel;
}
/**
* Sets a memory mark identified with $name
*
* @param string $name
*/
public function mark($name) {
if (!function_exists('memory_get_peak_usage')) {
return;
}
if (isset($this->_memory['user'][$name]))
$this->_memory['user'][$name] = memory_get_peak_usage()-$this->_memory['user'][$name];
else
$this->_memory['user'][$name] = memory_get_peak_usage();
}
/**
* Defined by Zend_Controller_Plugin_Abstract
*
* @param Zend_Controller_Request_Abstract
* @return void
*/
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
{
if (function_exists('memory_get_peak_usage')) {
$this->_memory['dispatchLoopStartup'] = memory_get_peak_usage();
}
}
/**
* Defined by Zend_Controller_Plugin_Abstract
*
* @param Zend_Controller_Request_Abstract
* @return void
*/
public function dispatchLoopShutdown()
{
if (function_exists('memory_get_peak_usage')) {
$this->_memory['dispatchLoopShutdown'] = memory_get_peak_usage();
}
}
public function getLinebreak()
{
return '<br'.$this->getClosingBracket();
}
public function getClosingBracket()
{
if (!$this->_closingBracket) {
if ($this->_isXhtml()) {
$this->_closingBracket = ' />';
} else {
$this->_closingBracket = '>';
}
}
return $this->_closingBracket;
}
protected function _isXhtml()
{
$view = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view;
$doctype = $view->doctype();
return $doctype->isXhtml();
}
}

View file

@ -0,0 +1,90 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id: $
*/
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug_Plugin_Registry extends ZFDebug_Controller_Plugin_Debug_Plugin implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface
{
/**
* Contains plugin identifier name
*
* @var string
*/
protected $_identifier = 'registry';
/**
* Contains Zend_Registry
*
* @var Zend_Registry
*/
protected $_registry;
/**
* Create ZFDebug_Controller_Plugin_Debug_Plugin_Registry
*
* @return void
*/
public function __construct()
{
$this->_registry = Zend_Registry::getInstance();
}
/**
* Gets identifier for this plugin
*
* @return string
*/
public function getIdentifier()
{
return $this->_identifier;
}
/**
* Returns the base64 encoded icon
*
* @return string
**/
public function getIconData()
{
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAH2SURBVDjLjZNLTxNRGIaJv6ZNWeBwkZFLQtGAC4l/wKULV+7YILeSYukEUhJoSASVuCI0hpAYDSUQCJBSoAaC0wbBUi4aWphpO52Zlpa+nnOqCAptJ3k3M3me73LOlAAoyZfDqQdOEvyO89/vRcGZ5HeWmySFYdWHVOQN0vE58jrLJMFJ82hewVU4+bMfqdPxP9VBn+A4D88wP59PwFqmsH7UgeTJEMlsTuIyI5uRsDfCMcmtAtoyhVmOu5kkHZuFsiNA3XuEi+QCdhxluL0D/SvpoO+vhIksiItNiPqqyXgfIL403gjfoTsIL70gQBdim3VQvz2FFnwOxf8E8kYF0rIVYqcRM70Vgf/Pe/ohwsutOJdcpBpP4Mek+jPEfbWQVzkG+7tNcNsqt68tkcLZTIzM6YZ21IbolgHq9j1o+z04nKhHRnlH2p6A32LCvFD55fIYr960VHgSSqCFVDJBEeugh+zw2jnpc0/5rthuRMBaioWBqrVrFylXOUpankIi0AjJY0DC3wD9oA9rAnc2bat+n++2UkH8XHaTZfGQlg3QdlsIbIVX4KSPAv+60L+SO/PECmJiI1lYM9SQBR7b3einfn6kEMwEIZd5Q48sQQt1Qv/xFqt2Tp5x3B8sBmYC71h926az6njdUR6hMy8O17wqFqb5Bd2o/0SFzIZrAAAAAElFTkSuQmCC';
}
/**
* Gets menu tab for the Debugbar
*
* @return string
*/
public function getTab()
{
return ' Registry (' . $this->_registry->count() . ')';
}
/**
* Gets content panel for the Debugbar
*
* @return string
*/
public function getPanel()
{
$html = '<h4>Registered Instances</h4>';
$this->_registry->ksort();
$html .= $this->_cleanData($this->_registry);
return $html;
}
}

View file

@ -0,0 +1,150 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id$
*/
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug_Plugin_Text implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface
{
/**
* @var string
*/
protected $_tab = '';
/**
* @var string
*/
protected $_panel = '';
/**
* Contains plugin identifier name
*
* @var string
*/
protected $_identifier = 'text';
/**
* Contains plugin icon data
*
* @var string
*/
protected $_icondata = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAHhSURBVDjLpZI9SJVxFMZ/r2YFflw/kcQsiJt5b1ije0tDtbQ3GtFQYwVNFbQ1ujRFa1MUJKQ4VhYqd7K4gopK3UIly+57nnMaXjHjqotnOfDnnOd/nt85SURwkDi02+ODqbsldxUlD0mvHw09ubSXQF1t8512nGJ/Uz/5lnxi0tB+E9QI3D//+EfVqhtppGxUNzCzmf0Ekojg4fS9cBeSoyzHQNuZxNyYXp5ZM5Mk1ZkZT688b6thIBenG/N4OB5B4InciYBCVyGnEBHO+/LH3SFKQuF4OEs/51ndXMXC8Ajqknrcg1O5PGa2h4CJUqVES0OO7sYevv2qoFBmJ/4gF4boaOrg6rPLYWaYiVfDo0my8w5uj12PQleB0vcp5I6HsHAUoqUhR29zH+5B4IxNTvDmxljy3x2YCYUwZVlbzXJh9UKeQY6t2m0Lt94Oh5loPdqK3EkjzZi4MM/Y9Db3MTv/mYWVxaqkw9IOATNR7B5ABHPrZQrtg9sb8XDKa1+QOwsri4zeHD9SAzE1wxBTXz9xtvMc5ZU5lirLSKIz18nJnhOZjb22YKkhd4odg5icpcoyL669TAAujlyIvmPHSWXY1ti1AmZ8mJ3ElP1ips1/YM3H300g+W+51nc95YPEX8fEbdA2ReVYAAAAAElFTkSuQmCC';
/**
* Create ZFDebug_Controller_Plugin_Debug_Plugin_Text
*
* @param string $tab
* @paran string $panel
* @return void
*/
public function __construct(array $options = array())
{
if (isset($options['tab'])) {
$this->setTab($tab);
}
if (isset($options['panel'])) {
$this->setPanel($panel);
}
}
/**
* Gets identifier for this plugin
*
* @return string
*/
public function getIdentifier()
{
return $this->_identifier;
}
/**
* Sets identifier for this plugin
*
* @param string $name
* @return ZFDebug_Controller_Plugin_Debug_Plugin_Text Provides a fluent interface
*/
public function setIdentifier($name)
{
$this->_identifier = $name;
return $this;
}
/**
* Returns the base64 encoded icon
*
* @return string
**/
public function getIconData()
{
return $this->_icondata;
}
/**
* Sets icon data for this plugin
*
* @param string $data
* @return ZFDebug_Controller_Plugin_Debug_Plugin_Text Provides a fluent interface
*/
public function setIconData($data)
{
$this->_icondata = $data;
return $this;
}
/**
* Gets menu tab for the Debugbar
*
* @return string
*/
public function getTab()
{
return $this->_tab;
}
/**
* Gets content panel for the Debugbar
*
* @return string
*/
public function getPanel()
{
return $this->_panel;
}
/**
* Sets tab content
*
* @param string $tab
* @return ZFDebug_Controller_Plugin_Debug_Plugin_Text Provides a fluent interface
*/
public function setTab($tab)
{
$this->_tab = $tab;
return $this;
}
/**
* Sets panel content
*
* @param string $panel
* @return ZFDebug_Controller_Plugin_Debug_Plugin_Text Provides a fluent interface
*/
public function setPanel($panel)
{
$this->_panel = $panel;
return $this;
}
}

View file

@ -0,0 +1,249 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id$
*/
/**
* @see Zend_Session
*/
require_once 'Zend/Session.php';
/**
* @see Zend_Session_Namespace
*/
require_once 'Zend/Session/Namespace.php';
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug_Plugin_Time extends Zend_Controller_Plugin_Abstract implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface
{
/**
* Contains plugin identifier name
*
* @var string
*/
protected $_identifier = 'time';
/**
* @var array
*/
protected $_timer = array(
'dispatchLoopStartup' => 0,
'dispatchLoopShutdown' => 0
);
protected $_closingBracket = null;
/**
* Creating time plugin
* @return void
*/
public function __construct()
{
Zend_Controller_Front::getInstance()->registerPlugin($this);
}
/**
* Gets identifier for this plugin
*
* @return string
*/
public function getIdentifier()
{
return $this->_identifier;
}
/**
* Returns the base64 encoded icon
*
* @return string
**/
public function getIconData()
{
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAKrSURBVDjLpdPbT9IBAMXx/qR6qNbWUy89WS5rmVtutbZalwcNgyRLLMyuoomaZpRQCt5yNRELL0TkBSXUTBT5hZSXQPwBAvor/fZGazlb6+G8nIfP0znbgG3/kz+Knsbb+xxNV63DLxVLHzqV0vCrfMluzFmw1OW8ePEwf8+WgM1UXDnapVgLePr5Nj9DJBJGFEN8+TzKqL2RzkenV4yl5ws2BXob1WVeZxXhoB+PP0xzt0Bly0fKTePozV5GphYQPA46as+gU5/K+w2w6Ev2Ol/KpNCigM01R2uPgDcQIRSJEYys4JmNoO/y0tbnY9JlxnA9M15bfHZHCnjzVN4x7TLz6fMSJqsPgLAoMvV1niSQBGIbUP3Ki93t57XhItVXjulTQHf9hfk5/xgGyzQTgQjx7xvE4nG0j3UsiiLR1VVaLN3YpkTuNLgZGzRSq8wQUoD16flkOPSF28/cLCYkwqvrrAGXC1UYWtuRX1PR5RhgTJTI1Q4wKwzwWHk4kQI6a04nQ99mUOlczMYkFhPrBMQoN+7eQ35Nhc01SvA7OEMSFzTv8c/0UXc54xfQcj/bNzNmRmNy0zctMpeEQFSio/cdvqUICz9AiEPb+DLK2gE+2MrR5qXPpoAn6mxdr1GBwz1FiclDcAPCEkTXIboByz8guA75eg8WxxDtFZloZIdNKaDu5rnt9UVHE5POep6Zh7llmsQlLBNLSMTiEm5hGXXDJ6qb3zJiLaIiJy1Zpjy587ch1ahOKJ6XHGGiv5KeQSfFun4ulb/josZOYY0di/0tw9YCquX7KZVnFW46Ze2V4wU1ivRYe1UWI1Y1vgkDvo9PGLIoabp7kIrctJXSS8eKtjyTtuDErrK8jIYHuQf8VbK0RJUsLfEg94BfIztkLMvP3v3XN/5rfgIYvAvmgKE6GAAAAABJRU5ErkJggg==';
}
/**
* Gets menu tab for the Debugbar
*
* @return string
*/
public function getTab()
{
return round($this->_timer['dispatchLoopShutdown'],2) .'/'.round($this->_timer['dispatchLoopShutdown']-$this->_timer['dispatchLoopStartup'],2). ' ms';
}
/**
* Gets content panel for the Debugbar
*
* @return string
*/
public function getPanel()
{
$html = '<h4>Custom Timers</h4>';
$html .= 'Dispatch: ' . round(($this->_timer['dispatchLoopShutdown']-$this->_timer['dispatchLoopStartup']),2) .' ms'.$this->getLinebreak();
if (isset($this->_timer['user']) && count($this->_timer['user'])) {
foreach ($this->_timer['user'] as $name => $time) {
$html .= ''.$name.': '. round($time,2).' ms'.$this->getLinebreak();
}
}
if (!Zend_Session::isStarted()){
Zend_Session::start();
}
$request = Zend_Controller_Front::getInstance()->getRequest();
$this_module = $request->getModuleName();
$this_controller = $request->getControllerName();
$this_action = $request->getActionName();
$timerNamespace = new Zend_Session_Namespace('ZFDebug_Time',false);
$timerNamespace->data[$this_module][$this_controller][$this_action][] = round($this->_timer['dispatchLoopShutdown'],2);
$html .= '<h4>Overall Timers</h4>';
foreach ($timerNamespace->data as $module => $controller)
{
if ($module != $this_module) {
continue;
}
$html .= $module . $this->getLinebreak();
$html .= '<div class="pre">';
foreach ($controller as $con => $action)
{
if ($con != $this_controller) {
continue;
}
$html .= ' ' . $con . $this->getLinebreak();
$html .= '<div class="pre">';
foreach ($action as $key => $data)
{
if ($key != $this_action) {
continue;
}
$html .= ' ' . $key . $this->getLinebreak();
$html .= '<div class="pre">';
$html .= ' Avg: ' . $this->_calcAvg($data) . ' ms / '.count($data).' requests'.$this->getLinebreak();
$html .= ' Min: ' . round(min($data), 2) . ' ms'.$this->getLinebreak();
$html .= ' Max: ' . round(max($data), 2) . ' ms'.$this->getLinebreak();
$html .= '</div>';
}
$html .= '</div>';
}
$html .= '</div>';
}
$html .= $this->getLinebreak().'Reset timers by sending ZFDEBUG_RESET as a GET/POST parameter';
return $html;
}
/**
* Sets a time mark identified with $name
*
* @param string $name
*/
public function mark($name) {
if (isset($this->_timer['user'][$name]))
$this->_timer['user'][$name] = (microtime(true)-$_SERVER['REQUEST_TIME'])*1000-$this->_timer['user'][$name];
else
$this->_timer['user'][$name] = (microtime(true)-$_SERVER['REQUEST_TIME'])*1000;
}
#public function routeStartup(Zend_Controller_Request_Abstract $request) {
# $this->timer['routeStartup'] = (microtime(true)-$_SERVER['REQUEST_TIME'])*1000;
#}
#public function routeShutdown(Zend_Controller_Request_Abstract $request) {
# $this->timer['routeShutdown'] = (microtime(true)-$_SERVER['REQUEST_TIME'])*1000;
#}
/**
* Defined by Zend_Controller_Plugin_Abstract
*
* @param Zend_Controller_Request_Abstract
* @return void
*/
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
{
$reset = Zend_Controller_Front::getInstance()->getRequest()->getParam('ZFDEBUG_RESET');
if (isset($reset)) {
if (!Zend_Session::isStarted()) {
Zend_Session::start();
}
$timerNamespace = new Zend_Session_Namespace('ZFDebug_Time',false);
$timerNamespace->unsetAll();
}
$this->_timer['dispatchLoopStartup'] = (microtime(true)-$_SERVER['REQUEST_TIME'])*1000;
}
/**
* Defined by Zend_Controller_Plugin_Abstract
*
* @param Zend_Controller_Request_Abstract
* @return void
*/
public function dispatchLoopShutdown()
{
$this->_timer['dispatchLoopShutdown'] = (microtime(true)-$_SERVER['REQUEST_TIME'])*1000;
}
/**
* Calculate average time from $array
*
* @param array $array
* @param int $precision
* @return float
*/
protected function _calcAvg(array $array, $precision=2)
{
if (!is_array($array)) {
return 'ERROR in method _calcAvg(): this is a not array';
}
foreach ($array as $value)
if (!is_numeric($value)) {
return 'ERROR in method _calcAvg(): the array contains one or more non-numeric values';
}
$cuantos=count($array);
return round(array_sum($array)/$cuantos,$precision);
}
public function getLinebreak()
{
return '<br'.$this->getClosingBracket();
}
public function getClosingBracket()
{
if (!$this->_closingBracket) {
if ($this->_isXhtml()) {
$this->_closingBracket = ' />';
} else {
$this->_closingBracket = '>';
}
}
return $this->_closingBracket;
}
protected function _isXhtml()
{
$view = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view;
$doctype = $view->doctype();
return $doctype->isXhtml();
}
}

View file

@ -0,0 +1,104 @@
<?php
/**
* ZFDebug Zend Additions
*
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
* @version $Id$
*/
/**
* @category ZFDebug
* @package ZFDebug_Controller
* @subpackage Plugins
* @copyright Copyright (c) 2008-2009 ZF Debug Bar Team (http://code.google.com/p/zfdebug)
* @license http://code.google.com/p/zfdebug/wiki/License New BSD License
*/
class ZFDebug_Controller_Plugin_Debug_Plugin_Variables extends ZFDebug_Controller_Plugin_Debug_Plugin implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface
{
/**
* Contains plugin identifier name
*
* @var string
*/
protected $_identifier = 'variables';
/**
* @var Zend_Controller_Request_Abstract
*/
protected $_request;
/**
* Create ZFDebug_Controller_Plugin_Debug_Plugin_Variables
*
* @return void
*/
public function __construct()
{
}
/**
* Gets identifier for this plugin
*
* @return string
*/
public function getIdentifier()
{
return $this->_identifier;
}
/**
* Returns the base64 encoded icon
*
* @return string
**/
public function getIconData()
{
return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAFWSURBVBgZBcE/SFQBAAfg792dppJeEhjZn80MChpqdQ2iscmlscGi1nBPaGkviKKhONSpvSGHcCrBiDDjEhOC0I68sjvf+/V9RQCsLHRu7k0yvtN8MTMPICJieaLVS5IkafVeTkZEFLGy0JndO6vWNGVafPJVh2p8q/lqZl60DpIkaWcpa1nLYtpJkqR1EPVLz+pX4rj47FDbD2NKJ1U+6jTeTRdL/YuNrkLdhhuAZVP6ukqbh7V0TzmtadSEDZXKhhMG7ekZl24jGDLgtwEd6+jbdWAAEY0gKsPO+KPy01+jGgqlUjTK4ZroK/UVKoeOgJ5CpRyq5e2qjhF1laAS8c+Ymk1ZrVXXt2+9+fJBYUwDpZ4RR7Wtf9u9m2tF8Hwi9zJ3/tg5pW2FHVv7eZJHd75TBPD0QuYze7n4Zdv+ch7cfg8UAcDjq7mfwTycew1AEQAAAMB/0x+5JQ3zQMYAAAAASUVORK5CYII=';
}
/**
* Gets menu tab for the Debugbar
*
* @return string
*/
public function getTab()
{
return ' Variables';
}
/**
* Gets content panel for the Debugbar
*
* @return string
*/
public function getPanel()
{
$this->_request = Zend_Controller_Front::getInstance()->getRequest();
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
if ($viewRenderer->view && method_exists($viewRenderer->view, 'getVars')) {
$viewVars = $this->_cleanData($viewRenderer->view->getVars());
} else {
$viewVars = "No 'getVars()' method in view class";
}
$vars = '';
if ($this->_request->isPost())
{
$vars .= '<h4>$_POST</h4>'
. '<div id="ZFDebug_post">' . $this->_cleanData($this->_request->getPost()) . '</div>';
}
$vars .= '<h4>$_COOKIE</h4>'
. '<div id="ZFDebug_cookie">' . $this->_cleanData($this->_request->getCookie()) . '</div>'
. '<h4>Request</h4>'
. '<div id="ZFDebug_requests">' . $this->_cleanData($this->_request->getParams()) . '</div>'
. '<h4>View vars</h4>'
. '<div id="ZFDebug_vars">' . $viewVars . '</div>';
return $vars;
}
}