Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php // PHP 5.2
- require_once 'lib/org/firephp/core/FirePHP.class.php';
- /**
- * Console Class Object
- * Assorted tools to handle error / debug messags
- * @author eric.miller@e-vations.com
- * @version Apr 27, 2011
- */
- class Console{
- const EOL = "\r\n";
- const CSS_OPEN = "/*";
- const CSS_CLOSE = "*/";
- const HTML_OPEN = "<!-- ";
- const HTML_CLOSE = " -->";
- const DATESTAMP_FORMAT = 'Y-m-d H:i:s';
- const FIREBUG = TRUE;
- const FIREBUG_LOG = 'log';
- const FIREBUG_INFO = 'info';
- const FIREBUG_WARN = 'warn';
- const FIREBUG_ERROR = 'error';
- public static function write($msg=NULL, $label=NULL){
- self::toFirebug($msg, self::FIREBUG_LOG, $label);
- return;
- }
- public static function error($msg=NULL, $label=NULL){
- self::errorToFirebug($msg);
- return;
- }
- public static function exception($e=NULL){
- self::exceptionToFirebug($e);
- return;
- }
- public static function debug($msg=NULL, $label=NULL){
- self::infoToFirebug($msg, $label);
- return;
- }
- public static function warn($msg=NULL, $label=NULL){
- self::warnToFirebug($msg, $label);
- return;
- }
- /**
- * Write errors to CSS File
- * @param unknown_type $msg
- * @param unknown_type $label
- */
- public static function cssWrite($msg=NULL, $label=NULL){
- self::write(self::CSS_OPEN . self::getDatestamp() . ' ' .(!is_NULL($label) ? '['.$label.'] ' : ''). $msg . ' ' . self::CSS_CLOSE . self::EOL);
- return;
- }
- /**
- * CSS Error Method
- * Add error message to css
- * @param String $msg
- */
- public static function cssError($msg=''){
- Console::cssWrite($msg, 'error');
- return;
- }
- /**
- * CSS Debug Method
- * Add Debug information to css
- * @param String $msg
- * @param boolean $debug
- */
- public static function cssDebug($msg='', $label=NULL){
- if(self::isDebug()){
- Console::cssWrite((!is_NULL($label) ? ''.$label.' - ' : '').$msg, 'debug');
- }
- }
- /**
- * Debug Check Switch
- * Reads value of $_REQUEST[debug], if any and returns TRUE/FALSE
- * @return boolean TRUE/FALSE
- */
- public static function isDebug(){
- $isDebug = FALSE;
- if(isset($_REQUEST['debug']) && $_REQUEST['debug'] == '1'){
- $isDebug = TRUE;
- }
- return $isDebug;
- }
- private static function getDatestamp(){
- return date(self::DATESTAMP_FORMAT);
- }
- private static function toFirebug($var=NULL, $type=self::FIREBUG_LOG, $label=NULL){
- if(self::FIREBUG && self::isDebug()){
- ob_start();
- $firephp = FirePHP::getInstance(TRUE);
- $firephp->setEnabled(self::isDebug());
- $firephp->setOptions(array(
- 'includeLineNumbers' => TRUE,
- ));
- switch ($type){
- case self::FIREBUG_ERROR:
- $firephp->error($var, label);
- $firephp->trace('Stacktrace');
- break;
- case self::FIREBUG_INFO:
- $firephp->info($var, $label);
- break;
- case self::FIREBUG_WARN:
- $firephp->warn($var, $label);
- break;
- default:
- $firephp->log($var, $label);
- break;
- }
- }
- return;
- }
- private static function exceptionToFirebug($e=NULL){
- if(get_class($e) == 'Exception'){
- $msg = self::getDatestamp() . ' - ' . $e->getMessage() . '('.$e->getFile().':'.$e->getLine().')';
- self::errorToFirebug($msg);
- }
- return;
- }
- private static function errorToFirebug($msg='', $label=NULL){
- self::toFirebug($msg, self::FIREBUG_ERROR, $label);
- return;
- }
- private static function infoToFirebug($msg='', $label=NULL){
- self::toFirebug($msg, self::FIREBUG_INFO, $label);
- return;
- }
- private static function warnToFirebug($msg='', $label=NULL){
- self::toFirebug($msg, self::FIREBUG_WARN, $label);
- return;
- }
- private static function registerFirebug(){
- if(self::FIREBUG && self::isDebug()){
- ob_start();
- $firephp = FirePHP::getInstance(TRUE);
- $firephp->registerErrorHandler( $throwErrorExceptions=FALSE );
- $firephp->registerExceptionHandler();
- $firephp->registerAssertionHandler( $convertAssertionErrorsToExceptions=TRUE, $throwAssertionExceptions=FALSE );
- }
- return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement