DebugUtils.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2006-2007 by Anton E. Lebedevich                        *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 
00015     final class DebugUtils extends StaticFactory
00016     {
00017         private static $memoryAccumulator = 0;
00018         private static $currentMemory = null;
00019         
00020         public static function el($vr, $prefix = null)
00021         {
00022             if ($prefix === null) {
00023                 $trace = debug_backtrace();
00024                 $prefix = basename($trace[0]['file']).':'.$trace[0]['line'];
00025             }
00026             
00027             error_log($prefix.': '.var_export($vr, true));
00028         }
00029         
00030         public static function ev($vr, $prefix = null)
00031         {
00032             if ($prefix === null) {
00033                 $trace = debug_backtrace();
00034                 $prefix = basename($trace[0]['file']).':'.$trace[0]['line'];
00035             }
00036             
00037             echo
00038                 '<pre>'
00039                 .$prefix.': '.htmlspecialchars(var_export($vr, true))
00040                 .'</pre>';
00041         }
00042 
00043         public static function ec($vr, $prefix = null)
00044         {
00045             if ($prefix === null) {
00046                 $trace = debug_backtrace();
00047                 $prefix = basename($trace[0]['file']).':'.$trace[0]['line'];
00048             }
00049             
00050             echo "\n".$prefix.': '.var_export($vr, true)."\n";
00051         }
00052         
00053         public static function eq(Query $query, $prefix = null)
00054         {
00055             if ($prefix === null) {
00056                 $trace = debug_backtrace();
00057                 $prefix = basename($trace[0]['file']).':'.$trace[0]['line'];
00058             }
00059             
00060             error_log(
00061                 $prefix.": ".$query->toDialectString(
00062                     DBPool::me()->getLink()->getDialect()
00063                 )
00064             );
00065         }
00066         
00067         public static function microtime()
00068         {
00069             list($usec, $sec) = explode(' ', microtime(), 2);
00070             return ((float) $usec + (float) $sec);      
00071         }
00072         
00073         public static function setMemoryCounter()
00074         {
00075             self::$currentMemory = memory_get_usage();
00076         }
00077         
00078         public static function addMemoryCounter()
00079         {
00080             self::$memoryAccumulator += memory_get_usage() - self::$currentMemory;
00081         }
00082         
00083         public static function getMemoryCounter()
00084         {
00085             return self::$memoryAccumulator;
00086         }
00087         
00088         public static function errorMav($message = null)
00089         {
00090             $uri =
00091                 (
00092                     isset($_SERVER['HTTP_HOST'])
00093                     ? $_SERVER['HTTP_HOST']
00094                     : null
00095                 )
00096                 .(
00097                     isset($_SERVER['REQUEST_URI'])
00098                     ? $_SERVER['REQUEST_URI']
00099                     : null
00100                 );
00101             
00102             return
00103                 ModelAndView::create()->
00104                 setView('error')->
00105                 setModel(
00106                     Model::create()->
00107                     set(
00108                         'errorMessage',
00109                         ($message ? $message.': ' : null).$uri
00110                     )
00111                 );
00112         }
00113     }
00114 ?>