SunQuest
 
       Miscellaneous Code
  Home arrow Miscellaneous Code arrow [PHP5] PHP Debugger and Helper
Moblin
Try It Free
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Dedicated Servers  
Download TestComplete 
JMSL Numerical Library 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MISCELLANEOUS CODE

[PHP5] PHP Debugger and Helper
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2006-06-14

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
    Try It Free
     
    ADVERTISEMENT

    Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!

    [PHP5] ODEBUGGER PACKAGE
    20060928 :
    Thanks to Sven Drieling, I corrected a bug on Unix, in the odebugger::createlog() method.
    Replaced :
    $aTemp = explode ('\\', $sTemp);
    with
    $aTemp = preg_split('#/|\\\\#', $sTemp);
    20060926 : Code has been updated!
    Various additions :
    - Some bug corrections
    - Options added (path to different files, so that it can be used anyway on a web server)
    - Options ENABLE or DISABLE (see French readme...sorry, did not have time to translate it properly)/ Basically, used to enable or disable an error level :
    oDebugger::DISABLE= E_STRICT will disable debugging on E_STRICT errors.
    By default, all levels are enabled.
    - Added use of CONTEXT. Beware : context can be heavy...! I'll add an option to disable that, just in case...CONTEXT just shows every variable initialized when an error/exception has ben caught.
    and some other mnior stuff... :-) I'll come back for a better translation (a new readme.txt file).

    THis package is a debugging and helper tool.
    It overrides the errors and exceptions handling by PHP.
    Errors are generated, even if error_reporting is set to 0.
    Errors are translated in a more comprehensive way, and hints for a correction is displayed.
    Errors can be displayed realtime, and/or logged in an XML file.
    This tool can be used by beginners, because it gives them a more comprehensive error message, and hint to debug their code. Gurus can
    personalize it to fit their needs.

    It's easy to use, you can find some examples in all the indexN.php pages.

    Version 20060612

    - Localized in : French, English (ENglish being the default language)
    - Many errors translated and hinted
    - Error types translated
    - 2 different kinds of display : the Realtime mode, and the Stats mode.
    - Easyly configurable : translations, new error messages, hints, display and so on.



    HOW TO :
    * How to call the debugger :

    $oDebugger = new odebugger ('EN');

    Where 'EN' is the chosen language.
    Check the 'xml/' folder to see which languages are currently supported.
    English being the default language, you can call the debugger this way, too, for English :
    $oDebugger = new odebugger;

    * How to add a new language :
    In the xml/ folder, you can find surbolders. Each one contains the XML files for a different language.
    'EN/' => English
    'FR/' => French.
    If you want to add, for example, German, just create a 'GE/' subfolder, and copy both the xml files :
    errors.xml and types.xml into the new folder.
    Then, edit them.
    All you have to do is change the and nodes in the XML files.
    And that's it!
    You can then call the debugger in German :
    $oDebugger = new odebugger ('GE');

    How to add a new error :
    Well, just edit the chose language errors.xml file (xml/LANGUAGE/errors.xml), and copy/paste
    a node within the root node. It must follow the others:


    An index has been used without being defined
    Check the max and min limits of your array


    Just change the values, save the file, and that's it.
    You can, of course, also change an existing node, if you do not like my translations/suggestions ;-)

    * How to change the display:
    Well, there is currently 2 types of display : realtime, and stats.
    IN the folder 'templates/', you can find some files. For example :
    default.dat
    default_log.dat

    default.dat is the default realtime display HTML template, while default_log.dat is the default stat HTML template.
    You can create your own, of course. The information supplied by odebugger replace the {INFO_NAME} types of string.
    Just make sure you put all the information you want in your templates :-)
    For the stats template, there is a slight difference : it has 3 parts.
    The first one starts from the...start, and ends on : <--! LINES HERE -->.
    This part is fixed. These are the headers!

    Then, between <--! LINES HERE -->. and , the logs will be displayed. And of course, the lines here
    will be repeated as many times as you have lines in your log.
    Then, after , you have your stats :-)

    You can set new templates with :
    odebugger::HTML
    and
    odebugger::HTMLLOG
    properties. See the part of this documentation about the OPTIONS.

    In the 'css/' folder, you can also find files. These are the CSS files used to modify the HTML templates.
    default.dat being the CSS for the default.dat HTML template.
    default_log.dat being the CSS for the default_log.dat HTML template.
    You can also, of course, set them :
    odebugger::CSS
    and
    odebugger::CSSLOG



    OPTIONS:
    Syntax :
    $oDebugger -> {OPTION} = {VALEUR};
    Foir example :
    $oDebugger -> LINES = 2;

    odebugger::LINES => integer : gives the number of source code lines to be displayed before and after the error line
    default value : 2

    odebugger::HTML => string with the name of the file for the HTML template, in the 'templates/' folder, without its extension.
    Used to display the realtime log.
    default value : 'default'

    odebugger::CSS => string with the name of the file for the CSS template, in the 'css/' folder, without its extension.
    Used to transform the HTML template for realtime log.
    default value : 'default'

    odebugger::HTMLLOG => string with the name of the file for the HTML template, in the 'templates/' folder, without its extension.
    Used to display the stats log.
    default value : 'default_log'

    odebugger::CSSLOG => string with the name of the file for the CSS template, in the 'css/' folder, without its extension.
    Used to transform the HTML template for stats log.
    default value : 'default_log'

    odebugger::REALTIME => boolean : true or false. Activate or de-activate the realtime mode (errors are displayed realtime)
    default value : true

    odebugger::LOGFILE => boolean : true or false. Activate or de-activate the saving of the log into an xml files (in 'logs/'). These can be displayed via odebugger::showLog () method, and loaded
    with the odebugger::loadXML () method.
    default value : true

    odebugger::ERROR => Boolean : true or false. Activate or de-activate the errors handling.
    default value : true

    odebugger::EXCEPTION => Boolean : true or false. Activate or de-activate the exceptions handling.
    default value : true


    You can also retrieve these values :
    echo $oDebugger -> LINES; // displays 2



    METHODS (the ones you can call only) :

    odebugger::checkCode (string sString)
    Used to check if there are any errors in a string (usually used by retrieving in a string the content of a file. See index3.php to see that in action).

    odebugger::loadXML (string sFile)
    Used to get an existing log from a file (logs are stored in the 'logs/' folder).
    This method erase any previous log (realtime or not).

    odebugger::showAll ()
    Used to display the whole current log, just as if it was in realtime mode. You can display a loaded log, or the current realtime log.

    odebugger::showLog ()
    Used to display the whole current log in stats mode. You can display a loaded log, or the current realtime log.

    odebugger::saveToFile (optional string sFile)
    Used to save the current log to a file. This methods is used automatically when the script ends, if odebugger::LOGFILE is set to true.
    But it can be called manually, with a filename.

    By : malalam

    <?php
    /**
    * CLASS odebugger
    *
    * @author : johan <barbier_johan@hotmail.com>
    */
    class odebugger {

    /**
    * private (string) sAssertion
    * Check if error comes from an essertion or not, if yes, will conatin the filename of the evaluated script
    */
    private $sAssertion = null;
    /**
    * private (string) sLang
    * localization string
    */
    private $sLang = 'EN';

    /**
    * private (int) iNbLines
    * Number of lines displayed before and after the line of the error
    */
    private $iNbLines = 2;

    /**
    * private (array) aOptions
    * Options array
    */
    private $aOptions = array (
    'REALTIME' => true,
    'LOG_FILE' => true,
    'ERROR' => true,
    'EXCEPTION' => true
    );

    /**
    * private (string) sTemplateHTML
    * HTML template file for the realtime log
    */
    private $sTemplateHTML = 'default';
    /**
    * private (string) sTemplateCSS
    * CSS template file for the realtime log
    */
    private $sTemplateCSS = 'default';
    /**
    * private (string) sTemplateHTMLLOG
    * HTML template file for the whole log file
    */
    private $sTemplateHTMLLOG = 'default_log';
    /**
    * private (string) sTemplateCSSLOG
    * CSS template file for the whole log file
    */
    private $sTemplateCSSLOG = 'default_log';

    /**
    * private (string) sCurDir
    * Current directory of the script
    */
    private $sCurDir = '';

    /**
    * private (string) sCurId
    * Current file unique id
    */
    private $sCurId = '';

    /**
    * private (object) oXMLDOC
    * XML LOG Object (DOMDocument object)
    */
    private $oXMLDOC = null;
    /**
    * private (object) oXMLROOT
    * XML LOG root Object (DOMDocument object)
    */
    private $oXMLROOT = null;
    /**
    * private (object) oCurrentNode
    * Current node Object (DOMDocument object)
    */
    private $oCurrentNode = null;

    /**
    * private (array) aCanBeSet
    * class properties that can be set via odebugger::__set()
    */
    private $aCanBeSet = array (
    'LINES' => 'iNbLines',
    'REALTIME' => "aOptions['REALTIME']",
    'LOGFILE' => "aOptions['LOG_FILE']",
    'HTML' => 'sTemplateHTML',
    'CSS' => 'sTemplateCSS',
    'HTMLLOG' => 'sTemplateHTMLLOG',
    'CSSLOG' => 'sTemplateCSSLOG',
    'ERROR' => "aOptions['ERROR']",
    'EXCEPTION' => "aOptions['EXCEPTION']"
    );

    /**
    * private (object) oXMLTYPES
    * XML DOMDocument object with the list of error types and their translation
    */
    private $oXMLTYPES = null;

    /**
    * private (object) oXMLERRORS
    * XML DOMDocument object with the list of errors and their translation
    */
    private $oXMLERRORS = null;

    /**
    * private (array) aIndex
    * replacement array for the templates
    */
    private $aIndex = array (
    0 => array (
    '{DATE_TITRE}',
    '{DATE_VALUE}'
    ),
    1 => array (
    '{TYPE_TITRE}',
    '{TYPE_VALUE}'
    ),
    2 => array (
    '{MSG_TITRE}',
    '{MSG_VALUE}'
    ),
    3 => array (
    '{FILE_TITRE}',
    '{FILE_VALUE}'
    ),
    4 => array (
    '{LINE_TITRE}',
    '{LINE_VALUE}'
    ),
    5 => array (
    '{MEM_TITRE}',
    '{MEM_VALUE}'
    ),
    6 => array (
    '{TRANS_TITRE}',
    '{TRANS_VALUE}'
    ),
    7 => array (
    '{SUGG_TITRE}',
    '{SUGG_VALUE}'
    ),
    8 => array (
    '{CONTEXT_TITRE}',
    '{CONTEXT_VALUE}'
    ),
    9 => array (
    '{SOURCE_TITRE}',
    '{SOURCE_VALUE}'
    ),
    100 => '{TOTAL_STATS}',
    101 => '{PHP_VERSION}'
    );

    /**
    * public function __construct ()
    * contsructor
    * sets the error_reporting to 0
    * gets the localization dir
    * import all the xml files
    * set the error handler
    * @Param (string) sLang : the localization used
    */
    public function __construct ($sLang = 'EN') {
    @error_reporting (0);

    $aLnDir = scandir ('xml');
    if (in_array ($sLang, $aLnDir)) {
    $this -> sLang = $sLang;
    }
    $this -> oXMLERRORS = DOMDocument::load ('xml/'.$this -> sLang.'/errors.xml');
    $this -> oXMLTYPES = DOMDocument::load ('xml/'.$this -> sLang.'/types.xml');

    $this -> oXMLDOC = new DOMDocument ('1.0', 'utf-8');
    $root = $this -> oXMLDOC -> createElement ('ERRORLOG');
    $this -> oXMLROOT = $this -> oXMLDOC -> appendChild ($root);
    if (!is_dir ('logs')) {
    @mkdir ('logs', 0744);
    }
    $sTemp = dirname (__FILE__);
    $aTemp = explode ('\\', $sTemp);
    array_pop ($aTemp);
    $this -> sCurDir = implode ('/', $aTemp).'/';
    $this -> sCurId = date ('Ymd').'_'.uniqid();

    set_error_handler (array ($this, 'myErrorHandler'));
    set_exception_handler (array ($this, 'myExceptionHandler'));
    }

    /**
    * public function checkCode ()
    * use the assert () function to get the errors in a given string, or a given file
    * @Param (string) sString : the string with the PHP code to evaluate, or the file to evaluate. Usually, it will come from a file via file_get_contents () for example
    * @Return : false if given parameter is not a string.
    */
    public function checkCode ($sCode) {
    if (file_exists ($sCode)) {
    $sString = file_get_contents ($sCode);
    $this -> sAssertion = $sCode;
    } elseif (!is_string ($sCode)) {
    return false;
    } else {
    $sString = $sCode;
    }
    $sString = str_replace (array ('<?php', '<?', '?>'), '', $sString);
    assert_options(ASSERT_ACTIVE, 1);
    assert_options(ASSERT_WARNING, 0);
    assert_options(ASSERT_QUIET_EVAL, 1);
    //assert_options (ASSERT_CALLBACK, array ($this, 'myAssertHandler')); Waiting a bit to improve this part
    assert ($sString);
    assert_options(ASSERT_ACTIVE, 0);
    }

    /**
    * public function myAssertHandler ()
    * activate the assertion. Right now, does nothing...and is not used.
    * @Param (string) file : the file from which comes the code
    * @Param (int) line : the error line
    * @Param (string) code : the error code
    * @Return : true
    */
    public function myAssertHandler ($file, $line, $code){
    return true;
    }

    /**
    * private function checkErrorMessage ()
    * try to find the correct trsnalation and suggestion from a given error message
    * @Param (string) sMsg : the PHP error message
    * @Return (array) aTempArr : array with the translation and the suggestion found
    */
    private function checkErrorMessage ($sMsg) {
    $iLength = strlen ($sMsg);
    $xpath = new DOMXPath($this -> oXMLERRORS);
    $sQueryLabel = '//error/label';
    $oLabelLists = $xpath -> query ($sQueryLabel);
    $aMsg = explode (' ', $sMsg);
    foreach ($oLabelLists as $oLabel) {
    $aLabel = explode (' ', $oLabel -> nodeValue);
    $aDiff = array_diff ($aLabel, $aMsg);
    if (empty ($aDiff)) {
    $aTempArr['TRANSLATION'] = $oLabel -> nextSibling -> nextSibling -> nodeValue;
    $aTempArr['SUGGESTION'] = $oLabel -> nextSibling -> nextSibling -> nextSibling -> nextSibling -> nodeValue;
    return $aTempArr;
    }
    }
    }

    /**
    * private function checkTypeTrans ()
    * try to find the error type translation
    * @Param (int) cErrno : the PHP constant error type code
    * @Return (string) nodeValue : the translated error type
    */
    private function checkTypeTrans ($cErrno) {
    $xpath = new DOMXPath($this -> oXMLTYPES);
    $sQueryLevel = '//type/level';
    $oLevelList = $xpath -> query ($sQueryLevel);
    foreach ($oLevelList as $oLevel) {
    if (constant ($oLevel -> nodeValue) === $cErrno) {
    return $oLevel -> nextSibling -> nextSibling -> nodeValue;
    }
    }
    }

    /**
    * public function myExceptionHandler ()
    * the exception handler : builds the XML error log
    * @Param (object) e : the Exception object
    */
    public function myExceptionHandler ($e) {
    $sErrStr = $e -> getMessage ();
    $iErrLine = $e -> getLine ();
    $sType = 'Exception '.$e -> getCode ();
    if (is_null ($this -> sAssertion)) {
    $sErrFile = $e -> getFile ();
    } else {
    $sErrFile = $this -> sAssertion;
    $this -> sAssertion = null;
    }
    $sVars = $e -> getTraceAsString ();
    $aTempArr = array ('TRANSLATION' => '', 'SUGGESTION' => '');

    $this -> buildLog ($sType, $sErrStr, $sErrFile, $iErrLine, $aTempArr, $sVars);
    }

    /**
    * public function myErrorHandler ()
    * the error handler : builds the XML error log
    * @Param (int) cErrno : the PHP constant error type code
    * @Param (string) sErrStr : the PHP error message
    * @Param (string) sErrFile : the file in which the error has been detected
    * @Param (int) iErrLine : the line of the error
    * @Param (array) mVars : the context
    */
    public function myErrorHandler ($cErrno, $sErrStr, $sErrFile, $iErrLine, $mVars) {
    $aTempArr = $this -> checkErrorMessage ($sErrStr);
    $sType = $this -> checkTypeTrans ($cErrno);
    $sVars = 'n/a';
    if (!is_null ($this -> sAssertion)) {
    $sErrFile = $this -> sAssertion;
    $this -> sAssertion = null;
    }
    $this -> buildLog ($sType, $sErrStr, $sErrFile, $iErrLine, $aTempArr, $sVars);
    }

    /**
    * private function buildLog ()
    * the error handler : builds the XML error log
    * @Param (string) sType : The type of error/exception
    * @Param (string) sErrStr : the PHP error message
    * @Param (string) sErrFile : the file in which the error has been detected
    * @Param (int) iErrLine : the line of the error
    * @Param (string) sVars : the context
    */
    private function buildLog ($sType, $sErrStr, $sErrFile, $iErrLine, $aTempArr, $sVars) {
    $iErrLine --;
    if ($iErrLine < 0) {
    $iErrLine = 0;
    }
    $oNewLog = $this -> oXMLDOC -> createElement ('ERROR');
    $dump = $this -> oXMLROOT -> getElementsByTagName('ERROR');
    $iNewId = $dump -> length + 1;
    $oNewLog = $this -> oXMLROOT -> appendChild ($oNewLog);
    $oNewLog -> setAttribute ('xml:id', '_'.$iNewId);

    $aElem[] = $this -> oXMLDOC -> createElement ('DATE', date ('d-m-Y H:i:s'));
    $aElem[] = $this -> oXMLDOC -> createElement ('TYPE', $sType);
    $sErrStr = utf8_encode ($sErrStr);
    $aElem[] = $this -> oXMLDOC -> createElement ('PHP_MESSAGE', $sErrStr);
    $aElem[] = $this -> oXMLDOC -> createElement ('FILE', $sErrFile);
    $aElem[] = $this -> oXMLDOC -> createElement ('LINE', $iErrLine);
    if (function_exists ('memory_get_usage')) {
    $iMemory = @memory_get_usage ();
    } else {
    $iMemory = 'n/a';
    }
    $aElem[] = $this -> oXMLDOC -> createElement ('MEMORY', $iMemory);
    $aElem[] = $this -> oXMLDOC -> createElement ('TRANSLATION', $aTempArr['TRANSLATION']);
    $aElem[] = $this -> oXMLDOC -> createElement ('SUGGESTION', $aTempArr['SUGGESTION']);

    $aElem[] = $this -> oXMLDOC -> createElement ('CONTEXT', $sVars);
    $oSource = $this -> oXMLDOC -> createElement ('SOURCE');
    $aSourceElem = array ();
    foreach ($this -> getLine ($sErrFile, $iErrLine) as $iLine => $sLine) {
    $sLine = utf8_encode ($sLine);
    if ($iLine === ($iErrLine)) {
    $aSourceElem[] = $this -> oXMLDOC -> createElement ('SOURCE_LINE_ERROR', ' /** ERROR AROUND THIS LINE => */ '.$sLine);
    } else {
    $aSourceElem[] = $this -> oXMLDOC -> createElement ('SOURCE_LINE', $sLine);
    }
    }
    foreach ($aSourceElem as $oSourceElem) {
    $oSource -> appendChild ($oSourceElem);
    }
    foreach ($aElem as $oElem) {
    $oNewLog -> appendChild ($oElem);
    }
    $oNewLog -> appendChild ($oSource);
    $this -> oCurrentNode = $oNewLog;
    if (true === $this -> aOptions['REALTIME']) {
    $this -> printMe ();
    }
    }
    /**
    * private function getLine ()
    * method to get the lines around the detected error
    * @Param (string) sErrFile : the file in which the error has been detected
    * @Param (int) iErrLine : the line of the error
    * @Return (array) aSource : array with each line
    */
    private function getLine ($sErrFile, $iErrLine) {
    $aSource = array ();
    if (file_exists ($sErrFile)) {
    $aLines = file ($sErrFile);
    for ($i = $iErrLine - $this -> iNbLines; $i<= $iErrLine + $this -> iNbLines; $i ++) {
    if (isset ($aLines[$i])) {
    $aSource[$i] = $aLines[$i];
    }
    }
    }
    return $aSource;
    }

    /**
    * public function loadXML ()
    * loads an external error log
    * @Param (string) sFile : the error log file to be loaded
    */
    public function loadXML ($sFile) {
    if (!file_exists ('logs/'.$sFile)) {
    return false;
    }
    $this -> oXMLDOC -> load ('logs/'.$sFile);
    }

    /**
    * public function showAll ()
    * show the whole current xml log
    */
    public function showAll () {
    $xpath = new DOMXPath($this -> oXMLDOC);
    $sQuery = '//ERROR';
    $oNodeLists = $xpath -> query ($sQuery);
    foreach ($oNodeLists as $oNodeList) {
    $this -> oCurrentNode = $oNodeList;
    $this -> printMe ();
    }
    }

    /**
    * public function showLog ()
    * show the whole current log in a table, with stats (best used after odebugger::loadXML())
    * @Return (string) sHtml : the generated HTML
    */
    public function showLog () {
    $sBaseHtml = file_get_contents ('templates/'.$this -> sTemplateHTMLLOG.'.dat');
    $iStartPos = strpos ($sBaseHtml, '<!-- LINES HERE -->');
    $sHtml = substr ($sBaseHtml, 0, $iStartPos);
    $iEndPos = strpos ($sBaseHtml, '<!-- STATS -->');
    $iLength = strlen ($sBaseHtml);
    $sTempHtml = substr ($sBaseHtml, $iStartPos, - ($iLength - $iEndPos));
    $sTempHtmlTotal = '';
    $xpath = new DOMXPath($this -> oXMLDOC);
    $sQuery = '//ERROR';
    $oNodeLists = $xpath -> query ($sQuery);
    foreach ($oNodeLists as $oNodeList) {
    $this -> oCurrentNode = $oNodeList;
    $sTempHtmlTotal .= $this -> printMeLog ($sTempHtml);
    }
    $sHtml .= $sTempHtmlTotal;
    $sQuery = '//ERROR/TYPE';
    $oNodeLists = $xpath -> query ($sQuery);
    foreach ($oNodeLists as $oNodeList) {
    $aTypes[] = $oNodeList -> nodeValue;
    }
    $sHtml .= substr ($sBaseHtml, $iEndPos, ($iLength - 1));
    $aCountType = array_count_values ($aTypes);
    $sCountType = '';
    foreach ($aCountType as $kType => $vType) {
    $sCountType .= $kType.' : '.$vType.'<br />';
    }
    $sVersion = @phpversion ();
    $sHtml = str_replace ($this -> aIndex[100], $sCountType, $sHtml);
    $sHtml = str_replace ($this -> aIndex[101], $sVersion , $sHtml);
    return $sHtml;
    }

    /**
    * private function printMe ()
    * display a caught error
    * @Return (string) sHtml : the generated HTML
    */
    private function printMe () {
    $sHtml = file_get_contents ('templates/'.$this -> sTemplateHTML.'.dat');
    $nodeList = $this -> oCurrentNode -> childNodes;
    $iId = $this -> oCurrentNode -> getAttribute ('id');
    for ($i = 0; $i < $nodeList -> length; $i++) {
    $sName = $nodeList -> item($i) -> nodeName;
    if ($sName === 'SOURCE') {
    $sourceNodeList = $nodeList -> item($i) -> childNodes;
    $sValeur = '';
    for ($j = 0; $j < $sourceNodeList -> length; $j++) {
    $sValeur .= str_replace (array ('<?php', '?>', '<?'), '', $sourceNodeList -> item($j) -> nodeValue);
    }
    $sValeur = highlight_string ('<?php '."\r\n".$sValeur.'?>', true);
    } else {
    $sValeur = $nodeList -> item($i) -> nodeValue;
    }
    $sId = uniqid().'_'.$iId;
    $aReplacement = array ($sName, $sValeur);
    $sHtml = str_replace ($this -> aIndex[$i], $aReplacement, $sHtml);
    $sHtml = str_replace ('{ID}', $sId, $sHtml);
    }
    echo $sHtml;
    }

    /**
    * private function printMeLog ()
    * display a caught error, used by odebugger::showLog()
    * @Return (string) sHtml : the generated HTML
    */
    private function printMeLog ($sHtml) {
    $nodeList = $this -> oCurrentNode -> childNodes;
    for ($i = 0; $i < $nodeList -> length; $i++) {
    if ($nodeList -> item($i) -> nodeName === 'SOURCE') {
    $sourceNodeList = $nodeList -> item($i) -> childNodes;
    $sValeur = '';
    for ($j = 0; $j < $sourceNodeList -> length; $j++) {
    $sValeur .= str_replace (array ('<?php', '?>', '<?'), '', $sourceNodeList -> item($j) -> nodeValue);
    }
    $sValeur = highlight_string ('<?php '."\r\n".$sValeur.'?>', true);
    } else {
    $sValeur = $nodeList -> item($i) -> nodeValue;
    }
    $sHtml = str_replace ($this -> aIndex[$i][1], $sValeur, $sHtml);
    }
    return $sHtml;
    }

    /**
    * public function saveToFile ()
    * save the current log to a given file
    * @Param (string) sFile : name of the log file
    */
    public function saveToFile ($sFile = null) {
    if ($sFile === null) {
    $sFile = $this -> sCurId.'_error_log.xml';
    }
    $this -> oXMLDOC -> save ($this -> sCurDir.'logs/'.$sFile);
    }

    /**
    * public function __destruct ()
    * destructor
    * will save the log to a file if the LOG_FILE option is set to true
    */
    public function __destruct () {
    if (true === $this -> aOptions['LOG_FILE']) {
    $this -> saveToFile ();
    }
    }

    /**
    * public function __set ()
    * allows some properties to be set
    * @Param (string) sProp : name of the property
    * @Param (mixed) mVal : the value to be given to the property
    * @Return (boolean) false if failed, true if succeeded
    */
    public function __set ($sProp, $mVal) {
    if (false === array_key_exists ($sProp, $this -> aCanBeSet)) {
    return false;
    }
    switch ($sProp) {
    case 'LINES' :
    if (!is_int ($mVal)) {
    return false;
    }
    $this -> iNbLines = $mVal;
    return true;
    break;
    case 'HTML' :
    if (!file_exists ('templates/'.$mVal.'.dat')) {
    return false;
    }
    $this -> sTemplateHTML = $mVal;
    return true;
    break;
    case 'HTMLLOG' :
    if (!file_exists ('templates/'.$mVal.'.dat')) {
    return false;
    }
    $this -> sTemplateHTMLLOG = $mVal;
    return true;
    break;
    case 'CSS' :
    if (!file_exists ('css/'.$mVal.'.dat')) {
    return false;
    }
    $this -> sTemplateCSS = $mVal;
    readfile ('css/'.$mVal.'.dat');
    return true;
    break;
    case 'CSSLOG' :
    if (!file_exists ('css/'.$mVal.'.dat')) {
    return false;
    }
    $this -> sTemplateCSSLOG = $mVal;
    readfile ('css/'.$mVal.'.dat');
    return true;
    break;
    case 'REALTIME' :
    if (!is_bool ($mVal)) {
    return false;
    }
    $this -> aOptions['REALTIME'] = $mVal;
    return true;
    break;
    case 'LOGFILE' :
    if (!is_bool ($mVal)) {
    return false;
    }
    $this -> aOptions['LOG_FILE'] = $mVal;
    return true;
    break;
    case 'ERROR' :
    if (!is_bool ($mVal)) {
    return false;
    }
    $this -> aOptions['ERROR'] = $mVal;
    if (true === $mVal) {
    set_error_handler (array ($this, 'myErrorHandler'));
    } else {
    restore_error_handler ();
    }
    return true;
    break;
    case 'EXCEPTION' :
    if (!is_bool ($mVal)) {
    return false;
    }
    $this -> aOptions['EXCEPTION'] = $mVal;
    if (true === $mVal) {
    set_exception_handler (array ($this, 'myExceptionHandler'));
    } else {
    restore_exception_handler ();
    }
    return true;
    break;
    default:
    return false;
    }
    }

    /**
    * public function __get ()
    * allows some properties to be get
    * @Param (string) sProp : name of the property
    * @Return (boolean) false if failed, value of the property if succeeded
    */
    public function __get ($sProp) {
    if (false === array_key_exists ($sProp, $this -> aCanBeSet)) {
    return false;
    }
    $sRealProp = $this -> aCanBeSet[$sProp];
    return $this -> $sRealProp;
    }
    }
    ?>

    Click to Download File



    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Miscellaneous Code Articles
    More By Codewalkers

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Calling all CC Power Users – and those that would like to be!

    Join this Rational Talks to You teleconference, featuring Paul Boustany and Mark Krasovich, to speak to the experts about becoming a Rational ClearCase power user. Get a chance to ask your questions and learn tips and tricks for using Rational ClearCase in Agile development
    FREE! Go There Now!


    NEW! Addressing software-as-a-service challenges using Tivoli security and WebSphere solutions

    Building a software-as-a-service solution requires addressing a few key technical challenges. In this webcast, we'll focus on the role of IBM Tivoli Directory Server and WebSphere Portlet Factory in creating a Software as a Service solution. We will demonstrate how to use Tivoli Directory Server to prevent the user population of one tenant from accessing the virtual portal and portlet components of another tenant. We will also use the dynamic profile capability of WebSphere Portlet Factory to create multiple highly customized applications from one code base.
    FREE! Go There Now!


    NEW! Download a free trial of WebSphere Business Modeler Advanced V6.1.1

    Visit IBM developerWorks to download a free trial version of WebSphere Business Modeler Advanced V6.1.1, IBM’s premier business process modeling and analysis tool for business users that offers process modeling, simulation, and analysis capabilities. IBM WebSphere Business Modeler helps you visualize, understand, and document business processes for continuous improvement.
    FREE! Go There Now!


    NEW! Download DB2 Express-C 9.5

    Visit IBM developerWorks to download IBM DB2 Express-C 9.5, a no-charge version of DB2 Express 9 database server. DB2 Express-C offers the same core data server base features as other DB2 Express editions and provides a solid base to build and deploy applications developed using C/C++, Java, .NET, PHP, and other programming languages.
    FREE! Go There Now!


    NEW! Improve your build process with IBM Rational Build Forge, Part 1: Create a continuous build and integration environment

    Learn how to implement a build management system that uses and extends your existing automation technologies. This tutorial shows, step-by-step, how to install and configure IBM Rational Build Forge to manage builds for Jakarta Tomcat from source code.
    FREE! Go There Now!


    NEW! Software Change and Configuration Management Solution Guidelines

    This whitepaper provides areas to consider when evaluating any software configuration management solution. It addresses how the IBM solutions (Rational ClearCase and Rational ClearQuest) meet the needs and requirements of both project leaders and developers to provide successful Software Change and Configuration Management.
    FREE! Go There Now!


    NEW! Webcast: Accelerating Software Innovation with System z

    Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, where he will overview Rational’s new offerings and programs to help customers accelerate software innovation on System z. He will discuss how these solutions help organizations extend their core business processes toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time.
    FREE! Go There Now!


    NEW! Webcast: Application security testing and Web compliance

    Join the IBM Watchfire team for an informative discussion on techniques and best practices to proactively manage Web application security and how to effectively build application security testing into the software development lifecycle (SDLC). In this Software Delivery Platform webcast you will learn: How to better understand potential web application security vulnerabilities, best practices and how to effectively integrate application security testing into the software development lifecycle, the importance of detecting and removing software vulnerabilities during application development.
    FREE! Go There Now!


    NEW! Webcast: Eclipse: Empowering the universal platform

    The Eclipse community is constantly working to extend Eclipse's functionality. In this webcast, learn about some of the most important and feature-rich projects under development. From multi-language support to plug-in development, tune in to see what Eclipse is capable of now.
    FREE! Go There Now!


    NEW! Webcast: Introducing the new Information Server and Solutions community: LeverageInformation

    User communities play an important role in communication and collaboration around products, solutions and other areas of special interest to members. Successful communities are able to provide the right mix of content and services to deliver a value proposition that resonates with each audience. Join Tom Inman, VP of Marketing for Information and Platform Solutions as he introduces the new LeverageINFORMATION community. During this webcast, learn about the value provided by the community and how customers and partners derive value from the community in addressing their own technical and business challenges.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    MISCELLANEOUS CODE ARTICLES

    - upload image to database sql
    - Random Password Generator
    - BCroot, get the root of a number with BC fun...
    - Find pi in a high precision
    - [PHP5] FORMCHECKER : data validation
    - SPL and ITERATOR : examples
    - Xml with Rss Feeds
    - [PHP5] NOTIMEOUT PACKAGE
    - Class to return variables to a Flash movie.
    - BCGCD Greatest Common Denominator (Large Num...
    - HMAC
    - Binary to Decimal
    - Decimal to Binary using logs
    - web.framework v1.0.0
    - Shopping Cart Class





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway