Current file: /home/greg/workspace/PHPDS-dev-trunk/PHPDevShell/stable/trunk/includes/PHPDS_debug.class.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
0.00%0.00%
0.00% 0 / 1
7.69%7.69%
7.69% 1 / 13 CRAP
20.00%20.00%
20.00% 11 / 55
 
PHPDS_debug
0.00%0.00%
0.00% 0 / 1
7.69%7.69%
7.69% 1 / 13
20.00%20.00%
20.00% 11 / 55
 construct ($domain = null)
0.00%0.00%
0.00% 0 / 1 6.00
50.00%50.00%
50.00% 4 / 8
 domain ($domain = null)
0.00%0.00%
0.00% 0 / 1 28.91
23.53%23.53%
23.53% 4 / 17
 enable($doit = null)
100.00%100.00%
100.00% 1 / 1 2
100.00%100.00%
100.00% 2 / 2
 isEnabled()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 __invoke($data, $label = null)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 dump($data, $label = 'data')
0.00%0.00%
0.00% 0 / 1 12
0.00%0.00%
0.00% 0 / 4
 log($data, $label = null)
0.00%0.00%
0.00% 0 / 1 20
0.00%0.00%
0.00% 0 / 4
 debug($data)
0.00%0.00%
0.00% 0 / 1 12
0.00%0.00%
0.00% 0 / 3
 info($data)
0.00%0.00%
0.00% 0 / 1 12
0.00%0.00%
0.00% 0 / 3
 warn($data)
0.00%0.00%
0.00% 0 / 1 12
0.00%0.00%
0.00% 0 / 3
 warning($data)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 error($datal)
0.00%0.00%
0.00% 0 / 1 12
0.00%0.00%
0.00% 0 / 3
 process($data)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 4


       1                 : <?php                                                                                                                                     
       2                 : /**                                                                                                                                       
       3                 :  * PHPDevShell is a RAD Framework aimed at developing administrative applications.                                                        
       4                 :  *                                                                                                                                        
       5                 :  * @package PHPDevShell                                                                                                                   
       6                 :  * @link http://www.phpdevshell.org                                                                                                       
       7                 :  * @copyright Copyright (C) 2007 Jason Schoeman, All rights reserved.                                                                     
       8                 :  * @license GNU/LGPL, see readme/licensed_under_lgpl or http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html                            
       9                 :  * @author Jason Schoeman, Contact: titan [at] phpdevshell [dot] org.                                                                     
      10                 :  *                                                                                                                                        
      11                 :  * Copyright notice: See readme/notice                                                                                                    
      12                 :  * By using PHPDevShell you agree to notice and license, if you dont agree to this notice/license you are not allowed to use PHPDevShell. 
      13                 :  *                                                                                                                                        
      14                 :  * This is the debug module. It's used widely accross the framework to log data and allow data feedback on a separate channel (backend).  
      15                 :  *                                                                                                                                        
      16                 :  * It supports level and domain filtering.                                                                                                
      17                 :  *                                                                                                                                        
      18                 :  * Currently supported backend:                                                                                                           
      19                 :  * - server log: the data is written to the error_log                                                                                     
      20                 :  * - firePHP: the data is send with the webpage to be displayed by FirePHP                                                                
      21                 :  */                                                                                                                                       
      22                 : /**                                                                                                                                       
      23                 :  * Adds FirePHP support to PHPDevShell.                                                                                                   
      24                 :  *                                                                                                                                        
      25                 :  * @author Greg                                                                                                                           
      26                 :  */                                                                                                                                       
      27                 : class PHPDS_debug extends PHPDS_dependant                                                                                                 
      28               1 : {                                                                                                                                         
      29                 :     /* levels of verbosity: the higher, the more data will be sent */                                                                     
      30                 :     const DEBUG = 4;                                                                                                                      
      31                 :     const INFO = 3;                                                                                                                       
      32                 :     const WARN = 2;                                                                                                                       
      33                 :     const ERROR = 1;                                                                                                                      
      34                 :     const LOG = 0;                                                                                                                        
      35                 :     protected $enabled = false; /* boolean: is the data to be sent, anyway */                                                             
      36                 :     protected $level = PHPDS_debug::LOG; /* level of verbosity */                                                                         
      37                 :     protected $domain; /* string (maybe null): to which semantic domain this instance is related */                                       
      38                 :     protected $conduits = null;                                                                                                           
      39                 :                                                                                                                                           
      40                 :     /**                                                                                                                                   
      41                 :      * @date 20110202 (v1.1) (greg) moved to construct() instead of __cosntruct()                                                         
      42                 :      * @date 20110216 (v1.1.1)  (greg) fixed a bug with enable                                                                            
      43                 :      * @version 1.1.1                                                                                                                     
      44                 :      * @param $domain the semantic domain of the debug object (to match (or not) the filters are set in configuration)                    
      45                 :      */                                                                                                                                   
      46                 :     public function construct ($domain = null)                                                                                            
      47                 :     {                                                                                                                                     
      48               1 :         $this->conduits = $this->errorHandler;                                                                                            
      49               1 :         $this->domain(empty($domain) ? '!' : $domain);                                                                                    
      50                 :                                                                                                                                           
      51               1 :         if ($this->enabled) {                                                                                                             
      52               0 :             $configuration = $this->configuration['debug'];                                                                               
      53               0 :             $this->enabled = !empty($configuration['enable']);                                                                            
      54               0 :             $this->level = empty($configuration['level']) ? PHPDS_debug::LOG : intval($configuration['level']);                           
      55               0 :         }                                                                                                                                 
      56                 :                                                                                                                                           
      57               1 :         return true;                                                                                                                      
      58                 :     }                                                                                                                                     
      59                 :                                                                                                                                           
      60                 :     /**                                                                                                                                   
      61                 :      * Accessor for the domain field: get (and possibily set) the domain                                                                  
      62                 :      *                                                                                                                                    
      63                 :      * The domain is the semantic field of the data sent to this instance ; it's used to filter which data will be actually sent          
      64                 :      * Note: the object will enable/disabled itself based on the domain debug configuration: the domain MUST be in the array to be active.
      65                 :      *                                                                                                                                    
      66                 :      * @version 1.1                                                                                                                       
      67                 :      * @author greg                                                                                                                       
      68                 :      *                                                                                                                                    
      69                 :      * @date 20110216 (v1.1) (greg) domain filters can now be regex                                                                       
      70                 :      *                                                                                                                                    
      71                 :      * @param $domain string (optional) the semantic domain                                                                               
      72                 :      * @return string, the domain (maybe null)                                                                                            
      73                 :      */                                                                                                                                   
      74                 :     public function domain ($domain = null)                                                                                               
      75                 :     {                                                                                                                                     
      76               1 :         if (! is_null($domain)) {                                                                                                         
      77               1 :             if (isset($this->configuration['debug'])) {                                                                                   
      78               0 :                 $configuration = $this->configuration['debug'];                                                                           
      79               0 :                 if (isset($configuration['domains'])) {                                                                                   
      80               0 :                     if (is_array($configuration['domains'])) {                                                                            
      81                 :                         ///$this->enabled = in_array($domain, $configuration['domains']);                                                 
      82               0 :                         foreach($configuration['domains'] as $possible_domain) {                                                          
      83                 :                             //if (preg_match('/^(.*%)?'.$possible_domain.'$/', $domain)) {                                                
      84               0 :                             if (fnmatch($possible_domain, $domain)) {                                                                     
      85               0 :                                 $this->enabled = true;                                                                                    
      86               0 :                                 $this->domain = $domain;                                                                                  
      87               0 :                                 return $domain;                                                                                           
      88                 :                             }                                                                                                             
      89               0 :                         }                                                                                                                 
      90               0 :                         $this->enabled = false;                                                                                           
      91               0 :                     }                                                                                                                     
      92               0 :                 }                                                                                                                         
      93               0 :             }                                                                                                                             
      94               1 :         }                                                                                                                                 
      95               1 :         return $domain;                                                                                                                   
      96                 :     }                                                                                                                                     
      97                 :                                                                                                                                           
      98                 :     /**                                                                                                                                   
      99                 :      * Enable or disable the debugger output ; get the current state                                                                      
     100                 :      *                                                                                                                                    
     101                 :      * Note: at this time, the debugger has to be enabled at startup                                                                      
     102                 :      *                                                                                                                                    
     103                 :      * @param $doit                (optional) enable (true or disable (false)                                                             
     104                 :      * @return boolean        weither it's currently enabled                                                                              
     105                 :      */                                                                                                                                   
     106                 :     function enable($doit = null)                                                                                                         
     107                 :     {                                                                                                                                     
     108               1 :         if (!is_null($doit)) $this->enabled = (boolean)$doit;                                                                             
     109               1 :         return $this->enabled;                                                                                                            
     110                 :     }                                                                                                                                     
     111                 :                                                                                                                                           
     112                 :     /**                                                                                                                                   
     113                 :      * Is this instance sending data?                                                                                                     
     114                 :      *                                                                                                                                    
     115                 :      * @return boolean                                                                                                                    
     116                 :      */                                                                                                                                   
     117                 :     public function isEnabled()                                                                                                           
     118                 :     {                                                                                                                                     
     119               0 :         return ($this->enabled == true);                                                                                                  
     120                 :     }                                                                                                                                     
     121                 :                                                                                                                                           
     122                 :     /**                                                                                                                                   
     123                 :      * Magic method: shortcut to log($ata)                                                                                                
     124                 :      */                                                                                                                                   
     125                 :     public function __invoke($data, $label = null)                                                                                        
     126                 :     {                                                                                                                                     
     127               0 :         return $this->log($data);                                                                                                         
     128                 :     }                                                                                                                                     
     129                 :                                                                                                                                           
     130                 :     /**                                                                                                                                   
     131                 :      * Dump the content of a variable to the backends                                                                                     
     132                 :      *                                                                                                                                    
     133                 :      * @param $data                                                                                                                       
     134                 :      * @param $label                                                                                                                      
     135                 :      */                                                                                                                                   
     136                 :     public function dump($data, $label = 'data')                                                                                          
     137                 :     {                                                                                                                                     
     138               0 :         if (!$this->enabled) return;                                                                                                      
     139                 :                                                                                                                                           
     140               0 :         if ($this->firephp) $this->firephp->dump($label, $data);                                                                          
     141               0 :         $this->error_log('DUMP', $data);                                                                                                  
     142               0 :     }                                                                                                                                     
     143                 :                                                                                                                                           
     144                 :     /**                                                                                                                                   
     145                 :      * Log the data to the backends with the LOG level (the smallest, most often seen)                                                    
     146                 :      *                                                                                                                                    
     147                 :      * @param $data                                                                                                                       
     148                 :      * @param $label                                                                                                                      
     149                 :      */                                                                                                                                   
     150                 :     public function log($data, $label = null)                                                                                             
     151                 :     {                                                                                                                                     
     152               0 :         if (!$this->enabled || ($this->level < PHPDS_debug::LOG)) return;                                                                 
     153                 :                                                                                                                                           
     154               0 :         if (empty($label)) $label = $this->domain;                                                                                        
     155                 :                                                                                                                                           
     156                 :                                                                                                                                           
     157               0 :         $this->conduits->conductor($data, PHPDS_debug::LOG, $this->domain.': '.$label);                                                   
     158               0 :     }                                                                                                                                     
     159                 :     /**                                                                                                                                   
     160                 :      * Push Firebug Debug Info                                                                                                            
     161                 :      *                                                                                                                                    
     162                 :      * @param mixed $data                                                                                                                 
     163                 :      * @return void                                                                                                                       
     164                 :      */                                                                                                                                   
     165                 :     public function debug($data)                                                                                                          
     166                 :     {                                                                                                                                     
     167               0 :         if (!$this->enabled || ($this->level < PHPDS_debug::DEBUG)) return;                                                               
     168                 :                                                                                                                                           
     169               0 :         $this->conduits->conductor($data, PHPDS_debug::DEBUG, $this->domain);                                                             
     170               0 :     }                                                                                                                                     
     171                 :     /**                                                                                                                                   
     172                 :      * Push Firebug Info                                                                                                                  
     173                 :      *                                                                                                                                    
     174                 :      * @param mixed $data                                                                                                                 
     175                 :      * @return void                                                                                                                       
     176                 :      */                                                                                                                                   
     177                 :     public function info($data)                                                                                                           
     178                 :     {                                                                                                                                     
     179               0 :         if (!$this->enabled || ($this->level < PHPDS_debug::INFO)) return;                                                                
     180                 :                                                                                                                                           
     181               0 :         $this->conduits->conductor($data, PHPDS_debug::INFO, $this->domain);                                                              
     182               0 :     }                                                                                                                                     
     183                 :     /**                                                                                                                                   
     184                 :      * Push Firebug Warning                                                                                                               
     185                 :      *                                                                                                                                    
     186                 :      * @param mixed $data                                                                                                                 
     187                 :      * @return void                                                                                                                       
     188                 :      */                                                                                                                                   
     189                 :     public function warn($data)                                                                                                           
     190                 :     {                                                                                                                                     
     191               0 :         if (!$this->enabled || ($this->level < PHPDS_debug::WARN)) return;                                                                
     192                 :                                                                                                                                           
     193               0 :         $this->conduits->conductor($data, PHPDS_debug::WARN, $this->domain);                                                              
     194               0 :     }                                                                                                                                     
     195                 :     /**                                                                                                                                   
     196                 :      * Push Firebug Warning                                                                                                               
     197                 :      *                                                                                                                                    
     198                 :      * @param mixed $data                                                                                                                 
     199                 :      */                                                                                                                                   
     200                 :     public function warning($data)                                                                                                        
     201                 :     {                                                                                                                                     
     202               0 :         return $this->warn($data);                                                                                                        
     203                 :     }                                                                                                                                     
     204                 :     /**                                                                                                                                   
     205                 :      * Push Firebug Error                                                                                                                 
     206                 :      *                                                                                                                                    
     207                 :      * @param mixed $data                                                                                                                 
     208                 :      * @return void                                                                                                                       
     209                 :      */                                                                                                                                   
     210                 :     public function error($datal)                                                                                                         
     211                 :     {                                                                                                                                     
     212               0 :         if (!$this->enabled || ($this->level < PHPDS_debug::ERROR)) return;                                                               
     213                 :                                                                                                                                           
     214               0 :         $this->conduits->conductor($data, PHPDS_debug::ERROR, $this->domain);                                                             
     215               0 :     }                                                                                                                                     
     216                 :     /**                                                                                                                                   
     217                 :      * FirePHP Process                                                                                                                    
     218                 :      *                                                                                                                                    
     219                 :      * @param mixed $data                                                                                                                 
     220                 :      * @return void                                                                                                                       
     221                 :      */                                                                                                                                   
     222                 :     public function process($data)                                                                                                        
     223                 :     {                                                                                                                                     
     224               0 :         $content = $data['sql'];                                                                                                          
     225               0 :         $key = '['.$data['counter'].'] '.$data['key'].' ('.$data['result'].')';                                                           
     226                 :                                                                                                                                           
     227               0 :         $this->log($content, $key);                                                                                                       
     228               0 :     }                                                                                                                                     
     229                 :                                                                                                                                           
     230                 : }                                                                                                                                         
     231                 :                                                                                                                                           

Generated by PHP_CodeCoverage 1.0.4 using PHP 5.3.6 and PHPUnit 3.5.14 at Mon Aug 8 22:35:38 PDT 2011.