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

Generated by PHPUnit 3.3.1 and Xdebug 2.0.2 at Thu Sep 25 18:42:10 CEST 2008.