File Source for CachedObjectStorageFactory.php

PHPExcel

# Source for file CachedObjectStorageFactory.php

Documentation is available at CachedObjectStorageFactory.php

1. <?php
3. class PHPExcel_CachedObjectStorageFactory {
4. const cache_in_memory = 'Memory';
5. const cache_in_memory_gzip = 'MemoryGZip';
6. const cache_in_memory_serialized = 'MemorySerialized';
7. const cache_to_discISAM = 'DiscISAM';
8. const cache_to_apc = 'APC';
9. const cache_to_memcache = 'Memcache';
10. const cache_to_phpTemp = 'PHPTemp';
11. const cache_to_wincache = 'Wincache';
14. private static $_cacheStorageMethod = null;
16. private static $_cacheStorageClass = null;
19. private static $_storageMethods = array(
20. self:: cache_in_memory,
21. self:: cache_in_memory_gzip,
22. self:: cache_in_memory_serialized,
23. self:: cache_to_phpTemp,
24. self:: cache_to_discISAM,
25. self:: cache_to_apc,
26. self:: cache_to_memcache,
27. self:: cache_to_wincache,
28. );
31. private static $_storageMethodDefaultParameters = array(
32. self:: cache_in_memory => array(
33. ),
34. self:: cache_in_memory_gzip => array(
35. ),
36. self:: cache_in_memory_serialized => array(
37. ),
38. self:: cache_to_phpTemp => array( 'memoryCacheSize' => '1MB'
39. ),
40. self:: cache_to_discISAM => array(
41. ),
42. self:: cache_to_apc => array( 'cacheTime' => 600
43. ),
44. self:: cache_to_memcache => array( 'memcacheServer' => 'localhost',
45. 'memcachePort' => 11211,
46. 'cacheTime' => 600
47. ),
48. self:: cache_to_wincache => array( 'cacheTime' => 600
49. )
50. );
53. private static $_storageMethodParameters = array();
56. public static function getCacheStorageMethod() {
57. if (! is_null(self::$_cacheStorageMethod)) {
58. return self::$_cacheStorageMethod;
59. }
60. return null;
61. } // function getCacheStorageMethod()
64. public static function getCacheStorageClass() {
65. if (! is_null(self::$_cacheStorageClass)) {
66. return self::$_cacheStorageClass;
67. }
68. return null;
69. } // function getCacheStorageClass()
72. public static function getCacheStorageMethods() {
73. return self::$_storageMethods;
74. } // function getCacheStorageMethods()
77. public static function initialize($method = self:: cache_in_memory, $arguments = array()) {
78. if (! in_array($method,self::$_storageMethods)) {
79. return false;
80. }
82. switch($method) {
83. case self:: cache_to_apc :
84. if (! function_exists('apc_store')) {
85. return false;
86. }
87. if (apc_sma_info() === false) {
88. return false;
89. }
90. break;
91. case self:: cache_to_memcache :
92. if (! function_exists('memcache_add')) {
93. return false;
94. }
95. break;
96. case self:: cache_to_wincache :
97. if (! function_exists('wincache_ucache_add')) {
98. return false;
99. }
100. break;
101. }
103. self::$_storageMethodParameters[$method] = self::$_storageMethodDefaultParameters[$method];
104. foreach($arguments as $k => $v) {
105. if (isset(self::$_storageMethodParameters[$method][$k])) {
106. self::$_storageMethodParameters[$method][$k] = $v;
107. }
108. }
110. if (is_null(self::$_cacheStorageMethod)) {
111. self::$_cacheStorageClass = 'PHPExcel_CachedObjectStorage_'.$method;
112. self::$_cacheStorageMethod = $method;
113. }
114. return true;
115. } // function initialize()
118. public static function getInstance(PHPExcel_Worksheet $parent) {
119. if ( is_null(self::$_cacheStorageMethod)) {
120. self:: initialize();
121. }
123. $instance = new self::$_cacheStorageClass($parent,self::$_storageMethodParameters[self::$_cacheStorageMethod]);
124. if (! is_null($instance)) {
125. return $instance;
126. }
128. return false;
129. } // function getInstance()
131. }

Documentation generated on Sun, 27 Feb 2011 16:28:41 -0800 by phpDocumentor 1.4.3