Subversion Repositories eFlore/Applications.cel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2390 jpm 1
<?php
2
 
3
/**
4
 * PHPExcel
5
 *
6
 * Copyright (c) 2006 - 2013 PHPExcel
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with this library; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21
 *
22
 * @category   PHPExcel
23
 * @package    PHPExcel_CachedObjectStorage
24
 * @copyright  Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
25
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
26
 * @version    ##VERSION##, ##DATE##
27
 */
28
 
29
 
30
/**
31
 * PHPExcel_CachedObjectStorageFactory
32
 *
33
 * @category    PHPExcel
34
 * @package        PHPExcel_CachedObjectStorage
35
 * @copyright    Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
36
 */
37
class PHPExcel_CachedObjectStorageFactory
38
{
39
    const cache_in_memory               = 'Memory';
40
    const cache_in_memory_gzip          = 'MemoryGZip';
41
    const cache_in_memory_serialized    = 'MemorySerialized';
42
    const cache_igbinary                = 'Igbinary';
43
    const cache_to_discISAM             = 'DiscISAM';
44
    const cache_to_apc                  = 'APC';
45
    const cache_to_memcache             = 'Memcache';
46
    const cache_to_phpTemp              = 'PHPTemp';
47
    const cache_to_wincache             = 'Wincache';
48
    const cache_to_sqlite               = 'SQLite';
49
    const cache_to_sqlite3              = 'SQLite3';
50
 
51
 
52
    /**
53
     * Name of the method used for cell cacheing
54
     *
55
     * @var string
56
     */
57
    private static $_cacheStorageMethod = NULL;
58
 
59
    /**
60
     * Name of the class used for cell cacheing
61
     *
62
     * @var string
63
     */
64
    private static $_cacheStorageClass = NULL;
65
 
66
 
67
    /**
68
     * List of all possible cache storage methods
69
     *
70
     * @var string[]
71
     */
72
    private static $_storageMethods = array(
73
        self::cache_in_memory,
74
        self::cache_in_memory_gzip,
75
        self::cache_in_memory_serialized,
76
        self::cache_igbinary,
77
        self::cache_to_phpTemp,
78
        self::cache_to_discISAM,
79
        self::cache_to_apc,
80
        self::cache_to_memcache,
81
        self::cache_to_wincache,
82
        self::cache_to_sqlite,
83
        self::cache_to_sqlite3,
84
    );
85
 
86
 
87
    /**
88
     * Default arguments for each cache storage method
89
     *
90
     * @var array of mixed array
91
     */
92
    private static $_storageMethodDefaultParameters = array(
93
        self::cache_in_memory               => array(
94
                                                    ),
95
        self::cache_in_memory_gzip          => array(
96
                                                    ),
97
        self::cache_in_memory_serialized    => array(
98
                                                    ),
99
        self::cache_igbinary                => array(
100
                                                    ),
101
        self::cache_to_phpTemp              => array( 'memoryCacheSize' => '1MB'
102
                                                    ),
103
        self::cache_to_discISAM             => array( 'dir'             => NULL
104
                                                    ),
105
        self::cache_to_apc                  => array( 'cacheTime'       => 600
106
                                                    ),
107
        self::cache_to_memcache             => array( 'memcacheServer'  => 'localhost',
108
                                                      'memcachePort'    => 11211,
109
                                                      'cacheTime'       => 600
110
                                                    ),
111
        self::cache_to_wincache             => array( 'cacheTime'       => 600
112
                                                    ),
113
        self::cache_to_sqlite               => array(
114
                                                    ),
115
        self::cache_to_sqlite3              => array(
116
                                                    ),
117
    );
118
 
119
 
120
    /**
121
     * Arguments for the active cache storage method
122
     *
123
     * @var array of mixed array
124
     */
125
    private static $_storageMethodParameters = array();
126
 
127
 
128
    /**
129
     * Return the current cache storage method
130
     *
131
     * @return string|NULL
132
     **/
133
    public static function getCacheStorageMethod()
134
    {
135
        return self::$_cacheStorageMethod;
136
    }   //    function getCacheStorageMethod()
137
 
138
 
139
    /**
140
     * Return the current cache storage class
141
     *
142
     * @return PHPExcel_CachedObjectStorage_ICache|NULL
143
     **/
144
    public static function getCacheStorageClass()
145
    {
146
        return self::$_cacheStorageClass;
147
    }   //    function getCacheStorageClass()
148
 
149
 
150
    /**
151
     * Return the list of all possible cache storage methods
152
     *
153
     * @return string[]
154
     **/
155
    public static function getAllCacheStorageMethods()
156
    {
157
        return self::$_storageMethods;
158
    }   //    function getCacheStorageMethods()
159
 
160
 
161
    /**
162
     * Return the list of all available cache storage methods
163
     *
164
     * @return string[]
165
     **/
166
    public static function getCacheStorageMethods()
167
    {
168
        $activeMethods = array();
169
        foreach(self::$_storageMethods as $storageMethod) {
170
            $cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $storageMethod;
171
            if (call_user_func(array($cacheStorageClass, 'cacheMethodIsAvailable'))) {
172
                $activeMethods[] = $storageMethod;
173
            }
174
        }
175
        return $activeMethods;
176
    }   //    function getCacheStorageMethods()
177
 
178
 
179
    /**
180
     * Identify the cache storage method to use
181
     *
182
     * @param    string            $method        Name of the method to use for cell cacheing
183
     * @param    array of mixed    $arguments    Additional arguments to pass to the cell caching class
184
     *                                        when instantiating
185
     * @return boolean
186
     **/
187
    public static function initialize($method = self::cache_in_memory, $arguments = array())
188
    {
189
        if (!in_array($method,self::$_storageMethods)) {
190
            return FALSE;
191
        }
192
 
193
        $cacheStorageClass = 'PHPExcel_CachedObjectStorage_'.$method;
194
        if (!call_user_func(array( $cacheStorageClass,
195
                                   'cacheMethodIsAvailable'))) {
196
            return FALSE;
197
        }
198
 
199
        self::$_storageMethodParameters[$method] = self::$_storageMethodDefaultParameters[$method];
200
        foreach($arguments as $k => $v) {
201
            if (array_key_exists($k, self::$_storageMethodParameters[$method])) {
202
                self::$_storageMethodParameters[$method][$k] = $v;
203
            }
204
        }
205
 
206
        if (self::$_cacheStorageMethod === NULL) {
207
            self::$_cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $method;
208
            self::$_cacheStorageMethod = $method;
209
        }
210
        return TRUE;
211
    }   //    function initialize()
212
 
213
 
214
    /**
215
     * Initialise the cache storage
216
     *
217
     * @param    PHPExcel_Worksheet     $parent        Enable cell caching for this worksheet
218
     * @return    PHPExcel_CachedObjectStorage_ICache
219
     **/
220
    public static function getInstance(PHPExcel_Worksheet $parent)
221
    {
222
        $cacheMethodIsAvailable = TRUE;
223
        if (self::$_cacheStorageMethod === NULL) {
224
            $cacheMethodIsAvailable = self::initialize();
225
        }
226
 
227
        if ($cacheMethodIsAvailable) {
228
            $instance = new self::$_cacheStorageClass( $parent,
229
                                                       self::$_storageMethodParameters[self::$_cacheStorageMethod]
230
                                                     );
231
            if ($instance !== NULL) {
232
                return $instance;
233
            }
234
        }
235
 
236
        return FALSE;
237
    }   //    function getInstance()
238
 
239
 
240
    /**
241
     * Clear the cache storage
242
     *
243
     **/
244
	public static function finalize()
245
	{
246
		self::$_cacheStorageMethod = NULL;
247
		self::$_cacheStorageClass = NULL;
248
		self::$_storageMethodParameters = array();
249
	}
250
 
251
}