PHPIDS
Current file: /home/lstrojny/Projekte/php-ids/trunk/lib/IDS/Caching/Session.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
100.00 %100.00%
100.00% 14 / 14
 
IDS_Caching_Session
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 4 / 4
100.00 %100.00%
100.00% 13 / 13
 public function __construct($type, $init)
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 3 / 3
 public static function getInstance($type, $init)
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 4 / 4
 public function setCache(array $data)
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 2 / 2
 public function getCache()
100.00 %100.00%
100.00% 1 / 1
100.00 %100.00%
100.00% 3 / 3


       1                 : <?php                                                                             
       2                 :                                                                                   
       3                 : /**                                                                               
       4                 :  * PHPIDS                                                                         
       5                 :  *                                                                                
       6                 :  * Requirements: PHP5, SimpleXML                                                  
       7                 :  *                                                                                
       8                 :  * Copyright (c) 2008 PHPIDS group (http://php-ids.org)                           
       9                 :  *                                                                                
      10                 :  * PHPIDS is free software; you can redistribute it and/or modify                 
      11                 :  * it under the terms of the GNU Lesser General Public License as published by    
      12                 :  * the Free Software Foundation, version 3 of the License, or                     
      13                 :  * (at your option) any later version.                                            
      14                 :  *                                                                                
      15                 :  * PHPIDS is distributed in the hope that it will be useful,                      
      16                 :  * but WITHOUT ANY WARRANTY; without even the implied warranty of                 
      17                 :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                   
      18                 :  * GNU Lesser General Public License for more details.                            
      19                 :  *                                                                                
      20                 :  * You should have received a copy of the GNU Lesser General Public License       
      21                 :  * along with PHPIDS. If not, see <http://www.gnu.org/licenses/>.                 
      22                 :  *                                                                                
      23                 :  * PHP version 5.1.6+                                                             
      24                 :  *                                                                                
      25                 :  * @category Security                                                             
      26                 :  * @package  PHPIDS                                                               
      27                 :  * @author   Mario Heiderich <mario.heiderich@gmail.com>                          
      28                 :  * @author   Christian Matthies <ch0012@gmail.com>                                
      29                 :  * @author   Lars Strojny <lars@strojny.net>                                      
      30                 :  * @license  http://www.gnu.org/licenses/lgpl.html LGPL                           
      31                 :  * @link     http://php-ids.org/                                                  
      32                 :  */                                                                               
      33                 :                                                                                   
      34               1 : require_once 'IDS/Caching/Interface.php';                                         
      35                 :                                                                                   
      36                 : /**                                                                               
      37                 :  * File caching wrapper                                                           
      38                 :  *                                                                                
      39                 :  * This class inhabits functionality to get and set cache via session.            
      40                 :  *                                                                                
      41                 :  * @category  Security                                                            
      42                 :  * @package   PHPIDS                                                              
      43                 :  * @author    Christian Matthies <ch0012@gmail.com>                               
      44                 :  * @author    Mario Heiderich <mario.heiderich@gmail.com>                         
      45                 :  * @author    Lars Strojny <lars@strojny.net>                                     
      46                 :  * @copyright 2007 The PHPIDS Group                                               
      47                 :  * @license   http://www.gnu.org/licenses/lgpl.html LGPL                          
      48                 :  * @version   Release: $Id:Session.php 517 2007-09-15 15:04:13Z mario $           
      49                 :  * @link      http://php-ids.org/                                                 
      50                 :  * @since     Version 0.4                                                         
      51                 :  */                                                                               
      52               1 : class IDS_Caching_Session implements IDS_Caching_Interface                        
      53                 : {                                                                                 
      54                 :                                                                                   
      55                 :     /**                                                                           
      56                 :      * Caching type                                                               
      57                 :      *                                                                            
      58                 :      * @var string                                                                
      59                 :      */                                                                           
      60                 :     private $type = null;                                                         
      61                 :                                                                                   
      62                 :     /**                                                                           
      63                 :      * Cache configuration                                                        
      64                 :      *                                                                            
      65                 :      * @var array                                                                 
      66                 :      */                                                                           
      67                 :     private $config = null;                                                       
      68                 :                                                                                   
      69                 :     /**                                                                           
      70                 :      * Holds an instance of this class                                            
      71                 :      *                                                                            
      72                 :      * @var object                                                                
      73                 :      */                                                                           
      74                 :     private static $cachingInstance = null;                                       
      75                 :                                                                                   
      76                 :     /**                                                                           
      77                 :      * Constructor                                                                
      78                 :      *                                                                            
      79                 :      * @param string $type caching type                                           
      80                 :      * @param array  $init the IDS_Init object                                    
      81                 :      *                                                                            
      82                 :      * @return void                                                               
      83                 :      */                                                                           
      84                 :     public function __construct($type, $init)                                     
      85                 :     {                                                                             
      86               1 :         $this->type   = $type;                                                    
      87               1 :         $this->config = $init->config['Caching'];                                 
      88               1 :     }                                                                             
      89                 :                                                                                   
      90                 :     /**                                                                           
      91                 :      * Returns an instance of this class                                          
      92                 :      *                                                                            
      93                 :      * @param string $type   caching type                                         
      94                 :      * @param array  $init the IDS_Init object                                    
      95                 :      *                                                                            
      96                 :      * @return object $this                                                       
      97                 :      */                                                                           
      98                 :     public static function getInstance($type, $init)                              
      99                 :     {                                                                             
     100                 :                                                                                   
     101               4 :         if (!self::$cachingInstance) {                                            
     102               1 :             self::$cachingInstance = new IDS_Caching_Session($type, $init);       
     103               1 :         }                                                                         
     104                 :                                                                                   
     105               4 :         return self::$cachingInstance;                                            
     106                 :     }                                                                             
     107                 :                                                                                   
     108                 :     /**                                                                           
     109                 :      * Writes cache data into the session                                         
     110                 :      *                                                                            
     111                 :      * @param array $data the caching data                                        
     112                 :      *                                                                            
     113                 :      * @return object $this                                                       
     114                 :      */                                                                           
     115                 :     public function setCache(array $data)                                         
     116                 :     {                                                                             
     117                 :                                                                                   
     118               3 :         $_SESSION['PHPIDS'][$this->type] = $data;                                 
     119               3 :         return $this;                                                             
     120                 :     }                                                                             
     121                 :                                                                                   
     122                 :     /**                                                                           
     123                 :      * Returns the cached data                                                    
     124                 :      *                                                                            
     125                 :      * Note that this method returns false if either type or file cache is not set
     126                 :      *                                                                            
     127                 :      * @return mixed cache data or false                                          
     128                 :      */                                                                           
     129                 :     public function getCache()                                                    
     130                 :     {                                                                             
     131                 :                                                                                   
     132               2 :         if ($this->type && $_SESSION['PHPIDS'][$this->type]) {                    
     133               1 :             return $_SESSION['PHPIDS'][$this->type];                              
     134                 :         }                                                                         
     135                 :                                                                                   
     136               1 :         return false;                                                             
     137                 :     }                                                                             
     138                 : }                                                                                 
     139                 :                                                                                   
     140                 : /**                                                                               
     141                 :  * Local variables:                                                               
     142                 :  * tab-width: 4                                                                   
     143                 :  * c-basic-offset: 4                                                              
     144                 :  * End:                                                                           
     145                 :  */                                                                               

Generated by PHPUnit 3.3.1 and Xdebug 2.1.0-dev at Mon Dec 22 13:57:42 CET 2008.