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

## Source for file eval_array.php

Documentation is available at eval_array.php

1. <?php
2. /**
3. * File containing the ezcCacheStorageEvalarray 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 (int,
30. * float, string, bool) in files on your hard disk as PHP code. In contrast to
31. * its sibling class {@link ezcCacheStorageFileArray}, the stored PHP code is
32. * not simply required to restore the cache data, but is evaluated using PHP's
33. * eval() function. It takes its base methods from the extended storage base
34. * class {@link ezcCacheStorageFile}.
35. *
36. * Main purpose behind these 2 similar implementations is the following:
37. * Most byte code caches are capable of caching code for included files,
38. * but not for eval()'ed strings. Therefore the
39. * {@link ezcCacheStorageFileEvalarray} class will permit you to get your cached
40. * data not cached a second time by an accellerator like APC, whereas the
41. * {@link ezcCacheStorageFileArray} class will permit you to explicitly allow
42. * this. ATTENTION: If you do not use a byte code cache with your PHP
43. * installation, the use of {@link ezcCacheStorageFileArray} is recommended over
44. * the usage of {@link ezcCacheStorageEvalarray}, since eval() is much slower
45. * than directly requiring the stored PHP code.
46. *
47. * For example code of using a cache storage, see {@link ezcCacheManager}.
48. *
49. * The Cache package contains several other implementations of
50. * {@link ezcCacheStorageFile}. As there are:
51. *
52. * - ezcCacheStorageFileArray
53. * - ezcCacheStorageFilePlain
54. *
55. * @package Cache
56. * @version //autogentag//
57. */
58. class ezcCacheStorageFileEvalArray extends ezcCacheStorageFile
59. {
60. /**
61. * Fetch data from a given file name.
62. *
63. * @see ezcCacheStorageFile::restore()
64. *
65. * @param string $filename The file to fetch data from.
66. * @return mixed The data read from the file.
67. */
68. protected function fetchData ( $filename )
69. {
70. return eval( file_get_contents ( $filename ) );
71. }
73. /**
74. * Serialize the data for storing.
75. * Serializes a PHP variable (except type resource and object) to a
76. * executable PHP code representation string.
77. *
78. * @param mixed $data Simple type or array to serialize.
79. * @return string The serialized data
80. *
81. * @throws ezcCacheInvalidDataException
82. * If the data submitted is an object or a resource, since this
83. * implementation of {@link ezcCacheStorageFile} can only deal with
84. * scalar and array values.
85. */
86. protected function prepareData ( $data )
87. {
88. if ( is_object ( $data ) || is_resource ( $data ) )
89. {
90. throw new ezcCacheInvalidDataException ( gettype ( $data ), array( 'simple', 'array' ) );
91. }
92. return "return " . var_export ( $data, true ) . ";\n?>\n";
93. }
94. }
95. ?>

Documentation generated by phpDocumentor 1.4.3