Remove WsDebug

This commit is contained in:
Michael RICOIS 2016-08-03 17:03:27 +02:00
parent 622caa96a3
commit 232fa817f8
7 changed files with 0 additions and 714 deletions

View File

@ -157,24 +157,6 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
Zend_Db_Table::setDefaultAdapter($db);
}
protected function _initWsDebug()
{
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('WsDebug');
$options = array(
'plugins' => array(
'Exception',
),
);
$debug = new WsDebug_Controller_Plugin_Debug($options);
$this->bootstrap('frontController');
$frontController = $this->getResource('frontController');
$frontController->registerPlugin($debug);
}
protected function _initCache()
{
if ( APPLICATION_ENV!='development' ) {

View File

@ -1,234 +0,0 @@
<?php
/**
* @see Zend_Controller_Exception
*/
require_once 'Zend/Controller/Exception.php';
/**
* @category WsDebug
* @package WsDebug_Controller
* @subpackage Plugins
*/
class WsDebug_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(
'Exception' => null,
),
);
/**
* Standard plugins
*
* @var array
*/
public static $standardPlugins = array(
'Exception',
);
/**
* 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('Parameters must be in an array or a Zend_Config object');
}
$this->setOptions($options);
}
/**
* Creating the log tab
*/
$logger = new WsDebug_Controller_Plugin_Debug_Plugin_Log();
$this->registerPlugin($logger);
$logger->mark('Startup - WsDebug construct()', true);
/**
* Loading already defined plugins
*/
$this->_loadPlugins();
}
/**
* Get the ZFDebug logger
*
* @return Zend_Log
*/
public function getLogger()
{
return $this->getPlugin('Log')->logger();
}
/**
* Sets options of the Debug Bar
*
* @param array $options
* @return ZFDebug_Controller_Plugin_Debug
*/
public function setOptions(array $options = array())
{
if (isset($options['plugins'])) {
$this->_options['plugins'] = $options['plugins'];
}
return $this;
}
/**
* Register a new plugin in the Debug Bar
*
* @param WsDebug_Controller_Plugin_Debug_Plugin_Interface
* @return WsDebug_Controller_Plugin_Debug
*/
public function registerPlugin(WsDebug_Controller_Plugin_Debug_Plugin_Interface $plugin)
{
$this->_plugins[$plugin->getIdentifier()] = $plugin;
return $this;
}
/**
* Unregister a plugin in the Debug Bar
*
* @param string $plugin
* @return WsDebug_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 WsDebug_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()
{
$txt = '';
/**
* Creating content for all registered plugins
*/
foreach ($this->_plugins as $plugin) {
$data = $plugin->getData();
if ($data == '') {
continue;
}
$txt .= 'Debug - ' . ucfirst($plugin->getIdentifier())." : \n";
$txt .= $data;
}
$this->_output($txt);
}
### 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('WsDebug_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, WsDebug_Controller_Plugin_Debug::$standardPlugins)) {
// standard plugin
$pluginClass = 'WsDebug_Controller_Plugin_Debug_Plugin_' . $plugin;
} else {
// we use a custom plugin
if (!preg_match('~^[\w]+$~D', $plugin)) {
throw new Zend_Exception("WsDebug: Invalid plugin name [$plugin]");
}
$pluginClass = $plugin;
}
require_once str_replace('_', DIRECTORY_SEPARATOR, $pluginClass) . '.php';
$object = new $pluginClass($options);
$this->registerPlugin($object);
}
}
/**
* Output text for logging
*
* @param string $txt
* @return void
*/
protected function _output($txt)
{
//file_put_contents(APPLICATION_PATH . '/../test.log', $txt, FILE_APPEND);
//Is txt should be send by mail
//Is txt should be write to file
}
}

View File

@ -1,47 +0,0 @@
<?php
class WsDebug_Controller_Plugin_Debug_Plugin
{
public function getLinebreak()
{
return "\n";
}
/**
* Transforms data into readable format
*
* @param array $values
* @return string
*/
protected function _cleanData($values)
{
$linebreak = $this->getLinebreak();
if (is_array($values)) {
ksort($values);
}
$retVal = $linebreak;
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.$linebreak;
}
}

View File

@ -1,148 +0,0 @@
<?php
class WsDebug_Controller_Plugin_Debug_Plugin_Exception implements WsDebug_Controller_Plugin_Debug_Plugin_Interface
{
protected static $_logger;
/**
* Contains plugin identifier name
*
* @var string
*/
protected $_identifier = 'exception';
/**
* Contains any errors
*
* @var param array
*/
static $errors = array();
protected $_rendered = false;
/**
* Get the logger
*
* @return Zend_Log
*/
public static function getLogger()
{
if (!self::$_logger) {
if ($zfdebug = Zend_Controller_Front::getInstance()->getPlugin('WsDebug_Controller_Plugin_Debug')) {
self::$_logger = $zfdebug->getPlugin('Log')->getLog();
} else {
return false;
}
}
return self::$_logger;
}
/**
* Gets identifier for this plugin
*
* @return string
*/
public function getIdentifier()
{
return $this->_identifier;
}
/**
* 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 getData()
{
$response = Zend_Controller_Front::getInstance()->getResponse();
$exception = '';
foreach ($response->getException() as $e) {
$exception = get_class($e) . ': ' . $e->getMessage()
. ' thrown in ' . str_replace($_SERVER['DOCUMENT_ROOT'], '', $e->getFile())
. ' on line ' . $e->getLine();
$exception .= "\n";
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';
$exception .= ' - ' . $func . ' in '
. str_replace($_SERVER['DOCUMENT_ROOT'], '', $t['file'])
. ' on line ' . $t['line'] . "\n";
}
$exception .= "\n";
if ($logger = self::getLogger())
$logger->crit($exception);
}
return $exception;
}
/**
* 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:
$method = 'notice';
$type = 'Notice';
break;
case E_WARNING:
case E_USER_WARNING:
$method = 'warn';
$type = 'Warning';
break;
case E_ERROR:
case E_USER_ERROR:
$method = 'crit';
$type = 'Fatal Error';
break;
default:
$method = 'err';
$type = 'Unknown, ' . $level;
break;
}
self::$errors[] = array(
'type' => $type ,
'message' => $message ,
'file' => $file ,
'line' => $line,
'trace' => debug_backtrace()
);
$message = sprintf(
"%s in %s on line %d",
$message,
str_replace($_SERVER['DOCUMENT_ROOT'], '', $file),
$line
);
// if (ini_get('log_errors'))
// error_log(sprintf("%s: %s", $type, $message));
if (($logger = self::getLogger())) {
$logger->$method($message);
}
return false;
}
}

View File

@ -1,17 +0,0 @@
<?php
interface WsDebug_Controller_Plugin_Debug_Plugin_Interface
{
/**
* Has to return texte of compile data
*
* @return string
*/
public function getData();
/**
* Has to return a unique identifier for the specific plugin
*
* @return string
*/
public function getIdentifier();
}

View File

@ -1,177 +0,0 @@
<?php
class WsDebug_Controller_Plugin_Debug_Plugin_Log
extends Zend_Controller_Plugin_Abstract
implements WsDebug_Controller_Plugin_Debug_Plugin_Interface
{
const ZFLOG = 10;
protected $_logger;
protected $_writer;
protected $_marks = array();
public function __construct()
{
Zend_Controller_Front::getInstance()->registerPlugin($this);
$this->_writer = new WsDebug_Controller_Plugin_Debug_Plugin_Log_Writer();
$this->_logger = new Zend_Log($this->_writer);
$this->_logger->addPriority('ZFLOG', self::ZFLOG);
}
public function __call($method, $params)
{
$this->_logger->$method(array_shift($params));
}
public function getLog()
{
return $this->_logger;
}
public function getWriter()
{
return $this->_writer;
}
/**
* Has to return html code for the content panel
*
* @return string
*/
public function getData()
{
$request = Zend_Controller_Front::getInstance()->getRequest();
$module = $request->getModuleName();
if ('default' !== $module) {
$module = " ($module module)";
} else {
$module = '';
}
$controller = $request->getControllerName();
$action = $request->getActionName();
$panel = '';
//$panel = "Event log for {$controller}Controller->{$action}Action() {$module}\n";
$panel .= implode("\n", $this->_writer->getMessages());
return $panel;
}
/**
* Has to return a unique identifier for the specific plugin
*
* @return string
*/
public function getIdentifier()
{
return 'log';
}
/**
* Sets a time mark identified with $name
*
* @param string $name
*/
public function mark($name, $logFirst = false) {
if (isset($this->_marks[$name])) {
$this->_marks[$name]['time'] = round((microtime(true)-$_SERVER['REQUEST_TIME'])*1000-$this->_marks[$name]['time']).'ms';
if (function_exists('memory_get_usage')) {
$this->_marks[$name]['memory'] = round((memory_get_usage()-$this->_marks[$name]['memory'])/1024) . 'K';
} else {
$this->_marks[$name]['memory'] = 'N/A';
}
$this->_logger->zflog(
array('time' => $this->_marks[$name]['time'],
'memory' => $this->_marks[$name]['memory'],
'message' => $name
)
);
} else {
$this->_marks[$name]['time'] = (microtime(true)-$_SERVER['REQUEST_TIME'])*1000;
if (function_exists('memory_get_usage')) {
$this->_marks[$name]['memory'] = memory_get_usage();
} else {
$this->_marks[$name]['memory'] = 'N/A';
}
if ($logFirst) {
$this->_logger->zflog(
array('time' => round($this->_marks[$name]['time']).'ms',
'memory' => round($this->_marks[$name]['memory']/1024).'K',
'message' => $name
)
);
}
}
}
/**
* Defined by Zend_Controller_Plugin_Abstract
*
* @param Zend_Controller_Request_Abstract
* @return void
*/
public function routeStartup(Zend_Controller_Request_Abstract $request)
{
$this->mark('Route');
}
/**
* Defined by Zend_Controller_Plugin_Abstract
*
* @param Zend_Controller_Request_Abstract
* @return void
*/
public function routeShutdown(Zend_Controller_Request_Abstract $request)
{
$this->mark('Route');
}
/**
* Defined by Zend_Controller_Plugin_Abstract
*
* @param Zend_Controller_Request_Abstract
* @return void
*/
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$this->mark(
$request->getControllerName() . 'Controller::'.
$request->getActionName() .'Action'
);
}
/**
* Defined by Zend_Controller_Plugin_Abstract
*
* @param Zend_Controller_Request_Abstract
* @return void
*/
public function postDispatch(Zend_Controller_Request_Abstract $request)
{
$this->mark(
$request->getControllerName() . 'Controller::'.
$request->getActionName() .'Action'
);
}
/**
* Defined by Zend_Controller_Plugin_Abstract
*
* @param Zend_Controller_Request_Abstract
* @return void
*/
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
{
$this->mark('Dispatch');
}
/**
* Defined by Zend_Controller_Plugin_Abstract
*
* @param Zend_Controller_Request_Abstract
* @return void
*/
public function dispatchLoopShutdown()
{
$this->mark('Dispatch');
}
}

View File

@ -1,73 +0,0 @@
<?php
class WsDebug_Controller_Plugin_Debug_Plugin_Log_Writer extends Zend_Log_Writer_Abstract
{
protected $_messages = array();
protected $_errors = 0;
public static function factory($config)
{
return new self();
}
public function getMessages()
{
return $this->_messages;
}
public function getErrorCount()
{
return $this->_errors;
}
/**
* Write a message to the log.
*
* @param array $event event data
* @return void
*/
protected function _write($event)
{
/*
$output = '<tr>';
$output .= '<td style="color:%color%;text-align:right;padding-right:1em">%priorityName%</td>';
$output .= '<td style="color:%color%;text-align:right;padding-right:1em">%memory%</td>';
$output .= '<td style="color:%color%;">%message%</td></tr>'; // (%priority%)
$event['color'] = '#C9C9C9';
// Count errors
if ($event['priority'] < 7) {
$event['color'] = 'green';
}
if ($event['priority'] < 6) {
$event['color'] = '#fd9600';
}
if ($event['priority'] < 5) {
$event['color'] = 'red';
$this->_errors++;
}
if ($event['priority'] == WsDebug_Controller_Plugin_Debug_Plugin_Log::ZFLOG) {
$event['priorityName'] = $event['message']['time'];
$event['memory'] = $event['message']['memory'];
$event['message'] = $event['message']['message'];
} else {
// self::$_lastEvent = null;
$event['message'] = $event['priorityName'] .': '. $event['message'];
$event['priorityName'] = '&nbsp;';
$event['memory'] = '&nbsp;';
}
foreach ($event as $name => $value) {
if ('message' == $name) {
$measure = '&nbsp;';
if ((is_object($value) && !method_exists($value,'__toString'))) {
$value = gettype($value);
} elseif (is_array($value)) {
$measure = $value[0];
$value = $value[1];
}
}
$output = str_replace("%$name%", $value, $output);
}
$this->_messages[] = $output;
*/
}
}