PHPIDS
Current file: /home/mario/workspace/php-ids.org/trunk/lib/IDS/vendors/htmlpurifier/HTMLPurifier/DoctypeRegistry.php
Legend: executed not executed dead code

  Coverage
  Classes Methods Lines
Total
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 4 / 4
82.35 %82.35%
82.35% 28 / 34
 
HTMLPurifier_DoctypeRegistry
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 4 / 4
82.35 %82.35%
82.35% 28 / 34
 public function register($doctype, $xml = true, $modules = array ( ), $tidy_modules = array ( ), $aliases = array ( ), $dtd_public = NULL, $dtd_system = NULL)
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 13 / 13
 public function get($doctype)
100.00 %100.00%
100.00% 1 / 1
50.00 %50.00%
50.00% 3 / 6
 public function make($config)
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 1 / 1
 public function getDoctypeFromConfig($config)
100.00 %100.00%
100.00% 1 / 1
76.92 %76.92%
76.92% 10 / 13


       1                 : <?php                                                                                                
       2                 :                                                                                                      
       3                 : class HTMLPurifier_DoctypeRegistry                                                                   
       4               1 : {                                                                                                    
       5                 :                                                                                                      
       6                 :     /**                                                                                              
       7                 :      * Hash of doctype names to doctype objects                                                      
       8                 :      */                                                                                              
       9                 :     protected $doctypes;                                                                             
      10                 :                                                                                                      
      11                 :     /**                                                                                              
      12                 :      * Lookup table of aliases to real doctype names                                                 
      13                 :      */                                                                                              
      14                 :     protected $aliases;                                                                              
      15                 :                                                                                                      
      16                 :     /**                                                                                              
      17                 :      * Registers a doctype to the registry                                                           
      18                 :      * @note Accepts a fully-formed doctype object, or the                                           
      19                 :      *       parameters for constructing a doctype object                                            
      20                 :      * @param $doctype Name of doctype or literal doctype object                                     
      21                 :      * @param $modules Modules doctype will load                                                     
      22                 :      * @param $modules_for_modes Modules doctype will load for certain modes                         
      23                 :      * @param $aliases Alias names for doctype                                                       
      24                 :      * @return Editable registered doctype                                                           
      25                 :      */                                                                                              
      26                 :     public function register($doctype, $xml = true, $modules = array(),                              
      27                 :         $tidy_modules = array(), $aliases = array(), $dtd_public = null, $dtd_system = null          
      28                 :     ) {                                                                                              
      29               1 :         if (!is_array($modules)) $modules = array($modules);                                         
      30               1 :         if (!is_array($tidy_modules)) $tidy_modules = array($tidy_modules);                          
      31               1 :         if (!is_array($aliases)) $aliases = array($aliases);                                         
      32               1 :         if (!is_object($doctype)) {                                                                  
      33               1 :             $doctype = new HTMLPurifier_Doctype(                                                     
      34               1 :                 $doctype, $xml, $modules, $tidy_modules, $aliases, $dtd_public, $dtd_system          
      35               1 :             );                                                                                       
      36               1 :         }                                                                                            
      37               1 :         $this->doctypes[$doctype->name] = $doctype;                                                  
      38               1 :         $name = $doctype->name;                                                                      
      39                 :         // hookup aliases                                                                            
      40               1 :         foreach ($doctype->aliases as $alias) {                                                      
      41                 :             if (isset($this->doctypes[$alias])) continue;                                            
      42                 :             $this->aliases[$alias] = $name;                                                          
      43                 :         }                                                                                            
      44                 :         // remove old aliases                                                                        
      45               1 :         if (isset($this->aliases[$name])) unset($this->aliases[$name]);                              
      46               1 :         return $doctype;                                                                             
      47                 :     }                                                                                                
      48                 :                                                                                                      
      49                 :     /**                                                                                              
      50                 :      * Retrieves reference to a doctype of a certain name                                            
      51                 :      * @note This function resolves aliases                                                          
      52                 :      * @note When possible, use the more fully-featured make()                                       
      53                 :      * @param $doctype Name of doctype                                                               
      54                 :      * @return Editable doctype object                                                               
      55                 :      */                                                                                              
      56                 :     public function get($doctype) {                                                                  
      57               1 :         if (isset($this->aliases[$doctype])) $doctype = $this->aliases[$doctype];                    
      58               1 :         if (!isset($this->doctypes[$doctype])) {                                                     
      59               0 :             trigger_error('Doctype ' . htmlspecialchars($doctype) . ' does not exist', E_USER_ERROR);
      60               0 :             $anon = new HTMLPurifier_Doctype($doctype);                                              
      61               0 :             return $anon;                                                                            
      62                 :         }                                                                                            
      63               1 :         return $this->doctypes[$doctype];                                                            
      64                 :     }                                                                                                
      65                 :                                                                                                      
      66                 :     /**                                                                                              
      67                 :      * Creates a doctype based on a configuration object,                                            
      68                 :      * will perform initialization on the doctype                                                    
      69                 :      * @note Use this function to get a copy of doctype that config                                  
      70                 :      *       can hold on to (this is necessary in order to tell                                      
      71                 :      *       Generator whether or not the current document is XML                                    
      72                 :      *       based or not).                                                                          
      73                 :      */                                                                                              
      74                 :     public function make($config) {                                                                  
      75               1 :         return clone $this->get($this->getDoctypeFromConfig($config));                               
      76                 :     }                                                                                                
      77                 :                                                                                                      
      78                 :     /**                                                                                              
      79                 :      * Retrieves the doctype from the configuration object                                           
      80                 :      */                                                                                              
      81                 :     public function getDoctypeFromConfig($config) {                                                  
      82                 :         // recommended test                                                                          
      83               1 :         $doctype = $config->get('HTML', 'Doctype');                                                  
      84               1 :         if (!empty($doctype)) return $doctype;                                                       
      85               1 :         $doctype = $config->get('HTML', 'CustomDoctype');                                            
      86               1 :         if (!empty($doctype)) return $doctype;                                                       
      87                 :         // backwards-compatibility                                                                   
      88               1 :         if ($config->get('HTML', 'XHTML')) {                                                         
      89               1 :             $doctype = 'XHTML 1.0';                                                                  
      90               1 :         } else {                                                                                     
      91               0 :             $doctype = 'HTML 4.01';                                                                  
      92                 :         }                                                                                            
      93               1 :         if ($config->get('HTML', 'Strict')) {                                                        
      94               0 :             $doctype .= ' Strict';                                                                   
      95               0 :         } else {                                                                                     
      96               1 :             $doctype .= ' Transitional';                                                             
      97                 :         }                                                                                            
      98               1 :         return $doctype;                                                                             
      99                 :     }                                                                                                
     100                 :                                                                                                      
     101                 : }                                                                                                    
     102                 :                                                                                                      

Generated by PHPUnit 3.2.20 and Xdebug 2.0.3 at Sat Jun 7 16:15:42 CEST 2008.