## Apache Zeta Components Manual :: File Source for array.php

## Source for file array.php

Documentation is available at array.php

1. <?php
2. /**
3. * File containing the ezcCacheStorageArray class.
4. *
5. * Licensed to the Apache Software Foundation (ASF) under one
6. * or more contributor license agreements. See the NOTICE file
7. * distributed with this work for additional information
8. * regarding copyright ownership. The ASF licenses this file
9. * to you under the Apache License, Version 2.0 (the
10. * "License"); you may not use this file except in compliance
11. * with the License. You may obtain a copy of the License at
12. *
13. * http://www.apache.org/licenses/LICENSE-2.0
14. *
15. * Unless required by applicable law or agreed to in writing,
16. * software distributed under the License is distributed on an
17. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18. * KIND, either express or implied. See the License for the
19. * specific language governing permissions and limitations
20. * under the License.
21. *
22. * @package Cache
23. * @version //autogentag//
24. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
25. * @filesource
26. */
28. /**
29. * This cache storage implementation stores arrays and scalar values
30. * (int, float, string, bool) in files on your hard disk as PHP code. This makes
31. * the restoring of cache data extremly fast, since the stored data is simply
32. * included and parsed by the PHP interpreter. It takes its base methods from
33. * the extended storage base class {@link ezcCacheStorageFile}.
34. *
35. * Another storage class with a similar approach exists,
36. * {@link ezcCacheStorageFileEvalArray}. This class is uses exactly the same
37. * mechanisms as ezcCacheStorageFileArray, except that is does not simply
38. * require the stored source code, but uses eval() to restore the data.
39. *
40. * Main purpose behind these 2 similar implementations is the following:
41. * Most byte code caches are capable of caching code for included files,
42. * but not for eval()ed strings. Therefore the *Evalarray class will
43. * permit you to get your cached data not cached a second time by an
44. * accellerator like APC, whereas the *Array class will permit you to
45. * explicitly allow this. ATTENTION: If you do not use a byte code cache
46. * with your PHP installation, the use of ezcCacheStorageFileArray is
47. * recommende over the usage of ezcCacheStorageEvalarray.
48. *
49. * For example code of using a cache storage, see {@link ezcCacheManager}.
50. *
51. * The Cache package contains several other implementations of
52. * {@link ezcCacheStorageFile}. As there are:
53. *
54. * - ezcCacheStorageFileEvalArray
55. * - ezcCacheStorageFilePlain
56. *
57. * @package Cache
58. * @version //autogentag//
59. */
60. class ezcCacheStorageFileArray extends ezcCacheStorageFile
61. {
62. /**
63. * Fetch data from the cache.
64. * This method does the fetching of the data itself. In this case, the
65. * method simply includes the file and returns the value returned by the
66. * include (or false on failure).
67. *
68. * @param string $filename The file to fetch data from.
69. * @return mixed The fetched data or false on failure.
70. */
71. protected function fetchData ( $filename )
72. {
73. return ( include $filename );
74. }
76. /**
77. * Serialize the data for storing.
78. * Serializes a PHP variable (except type resource and object) to a
79. * executable PHP code representation string.
80. *
81. * @param mixed $data Simple type or array
82. * @return string The serialized data
83. *
84. * @throws ezcCacheInvalidDataException
85. * If the data submitted is an object or a resource, since this
86. * implementation of {@link ezcCacheStorageFile} can only deal with
87. * scalar and array values.
88. */
89. protected function prepareData ( $data )
90. {
91. if ( is_object ( $data ) || is_resource ( $data ) )
92. {
93. throw new ezcCacheInvalidDataException ( gettype ( $data ), array( 'simple', 'array' ) );
94. }
95. return "<?php\nreturn " . var_export ( $data, true ) . ";\n?>\n";
96. }
97. }
98. ?>

Documentation generated by phpDocumentor 1.4.3