commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / packages / IDS / Caching / Session.php
1 <?php
2
3 /**
4 * PHPIDS
5 *
6 * Requirements: PHP5, SimpleXML
7 *
8 * Copyright (c) 2008 PHPIDS group (https://phpids.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 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-2009 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 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 object $init the IDS_Init object
81 *
82 * @return void
83 */
84 public function __construct($type, $init)
85 {
86 $this->type = $type;
87 $this->config = $init->config['Caching'];
88 }
89
90 /**
91 * Returns an instance of this class
92 *
93 * @param string $type caching type
94 * @param object $init the IDS_Init object
95 *
96 * @return object $this
97 */
98 public static function getInstance($type, $init)
99 {
100
101 if (!self::$cachingInstance) {
102 self::$cachingInstance = new IDS_Caching_Session($type, $init);
103 }
104
105 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 $_SESSION['PHPIDS'][$this->type] = $data;
119 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 if ($this->type && $_SESSION['PHPIDS'][$this->type]) {
133 return $_SESSION['PHPIDS'][$this->type];
134 }
135
136 return false;
137 }
138 }
139
140 /**
141 * Local variables:
142 * tab-width: 4
143 * c-basic-offset: 4
144 * End:
145 * vim600: sw=4 ts=4 expandtab
146 */