Web Commons
Current file: /home/antoine/zavaee/Web Commons/WebCommons/config.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
100.00%100.00%
100.00% 2 / 2
100.00%100.00%
100.00% 3 / 3
100.00%100.00%
100.00% 14 / 14
 
IniFileConfig
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 3 / 3
100.00%100.00%
100.00% 14 / 14
 public function __construct($filename)
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 5 / 5
 public function getItem($section, $item)
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 5 / 5
 public function getSection($section)
100.00%100.00%
100.00% 1 / 1
100.00%100.00%
100.00% 4 / 4
MisconfigurationException
100.00%100.00%
100.00% 1 / 1
  
   
100.00%100.00%
100.00% 0 / 0


       1                 : <?php                                                                         
       2                 : /**                                                                           
       3                 :  * This file groups classes that are used to manage configuration.            
       4                 :  *                                                                             
       5                 :  * @author Antoine d'Otreppe de Bouvette <a.dotreppe@aspyct.org>              
       6                 :  * @license http://www.opensource.org/licenses/mit-license.php                
       7                 :  * @version 0.1dev                                                            
       8                 :  */                                                                           
       9                 :                                                                               
      10                 : /**                                                                           
      11                 :  * Provides an access to configuration sections and items.                    
      12                 :  * @since 0.1                                                                 
      13                 :  */                                                                           
      14                 : interface Config {                                                            
      15                 :     /**                                                                       
      16                 :      * Returns an array containing values defined inside $section             
      17                 :      * @param string $section                                                 
      18                 :      * @return mixed[string]                                                  
      19                 :      * @throws MisconfigurationException                                      
      20                 :      * @since 0.1                                                             
      21                 :      */                                                                       
      22                 :     function getSection($section);                                            
      23                 :                                                                                   
      24                 :     /**                                                                       
      25                 :      * Returns a configuration $item from a $section                          
      26                 :      * @param string $section                                                 
      27                 :      * @param string $item                                                    
      28                 :      * @return mixed                                                          
      29                 :      * @throws MisconfigurationException                                      
      30                 :      * @since 0.1                                                             
      31                 :      */                                                                       
      32                 :     function getItem($section, $item);                                        
      33                 : }                                                                             
      34                 :                                                                               
      35                 : /**                                                                           
      36                 :  * A configuration built with a .ini file.                                    
      37                 :  * @since 0.1                                                                 
      38                 :  */                                                                           
      39                 : class IniFileConfig implements Config {                                       
      40                 :     /**                                                                       
      41                 :      * Holds the configuration items and sections.                            
      42                 :      * @var string[string][string]                                            
      43                 :      */                                                                       
      44                 :     private $config;                                                          
      45                 :                                                                                   
      46                 :     /**                                                                       
      47                 :      * Throws a MisconfigurationException if the file is missing, could not be
      48                 :      * read or parsed.                                                        
      49                 :      *                                                                         
      50                 :      * @param string $filename path to config file.                           
      51                 :      * @throws MisconfigurationException                                      
      52                 :      * @since 0.1                                                             
      53                 :      */                                                                       
      54                 :     public function __construct($filename) {                                  
      55               5 :         $this->config = load_extensible_ini_file($filename, true);            
      56                 :                                                                                       
      57               5 :         if ($this->config === false) {                                        
      58               1 :             throw new MisconfigurationException(                              
      59                 :                 'Could not read or parse config file at ' . $filename         
      60               1 :             );                                                                
      61                 :         }                                                                     
      62               5 :     }                                                                         
      63                 :                                                                                   
      64                 :     /**                                                                       
      65                 :      * (non-PHPdoc)                                                           
      66                 :      * @see WebCommons/Config::getItem()                                      
      67                 :      */                                                                       
      68                 :     public function getItem($section, $item) {                                
      69               2 :         $section = self::getSection($section);                                
      70                 :                                                                                       
      71               2 :         if (array_key_exists($item, $section)) {                              
      72               1 :             return $section[$item];                                           
      73                 :         }                                                                     
      74                 :         else {                                                                
      75               1 :             throw new MisconfigurationException(                              
      76               1 :                 'No such configuration item: ' . $item);                      
      77                 :         }                                                                     
      78                 :     }                                                                         
      79                 :                                                                                   
      80                 :     /**                                                                       
      81                 :      * (non-PHPdoc)                                                           
      82                 :      * @see WebCommons/Config::getSection()                                   
      83                 :      */                                                                       
      84                 :     public function getSection($section) {                                    
      85               4 :         if (array_key_exists($section, $this->config)) {                      
      86               3 :             return $this->config[$section];                                   
      87                 :         }                                                                     
      88                 :         else {                                                                
      89               1 :             throw new MisconfigurationException(                              
      90               1 :                 'No such configuration section: ' . $section);                
      91                 :         }                                                                     
      92                 :     }                                                                         
      93                 : }                                                                             
      94                 :                                                                               
      95                 : /**                                                                           
      96                 :  * Exception thrown when the configuration could not be read                  
      97                 :  * or when a requested configuration item is missing.                         
      98                 :  * @since 0.1                                                                 
      99                 :  */                                                                           
     100                 : class MisconfigurationException extends Exception {}                          

Generated by PHPUnit 3.4.5 and Xdebug 2.1.0 at Fri Jul 16 0:48:38 CEST 2010.