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

## Source for file object.php

Documentation is available at object.php

1. <?php
2. /**
3. * File containing the ezcCacheStorageObject 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, scalar values
30. * (int, float, string, bool) and objects implementing ezcBaseExportable in
31. * files on your hard disk as PHP code. This makes
32. * the restoring of cache data extremly fast, since the stored data is simply
33. * included and parsed by the PHP interpreter. It takes its base methods from
34. * the extended storage base class {@link ezcCacheStorageFile}.
35. *
36. * This cache storage deprecates {@link ezcCacheStorageFileArray}, since it is
37. * also capable of storing exportable objects in addition to arrays and scalar
38. * values.
39. *
40. * For example code of using a cache storage, see {@link ezcCacheManager}.
41. *
42. * The Cache package contains several other implementations of
43. * {@link ezcCacheStorageFile}. As there are:
44. *
45. * - ezcCacheStorageFileEvalArray
46. * - ezcCacheStorageFilePlain
47. *
48. * Both of these use different methods for actually storing the data, which are
49. * basically not superior to the implementation in this class.
50. *
51. * @package Cache
52. * @version //autogentag//
53. */
54. class ezcCacheStorageFileObject extends ezcCacheStorageFile
55. {
56. /**
57. * Fetch data from the cache.
58. *
59. * This method fetches the desired data from the file with $filename from
60. * disk. This implementation uses an include statement for fetching. The
61. * return value depends on the stored data and might either be an object
62. * implementing {@link ezcBaseExportable}, an array or a scalar value.
63. *
64. * @param string $filename
65. * @return mixed
66. */
67. protected function fetchData ( $filename )
68. {
69. return ( include $filename );
70. }
72. /**
73. * Serialize the data for storing.
74. *
75. * Serializes the given $data to a executable PHP code representation
76. * string. This works with objects implementing {@link ezcBaseExportable},
77. * arrays and scalar values (int, bool, float, string). The return value is
78. * executable PHP code to be stored to disk. The data can be unserialized
79. * using the {@link fetchData()} method.
80. *
81. * @param mixed $data
82. * @return string
83. *
84. * @throws ezcCacheInvalidDataException
85. * if the $data can not be serialized (e.g. an object that does not
86. * implement ezcBaseExportable, a resource, ...).
87. */
88. protected function prepareData ( $data )
89. {
90. if ( ( is_object ( $data ) && !( $data instanceof ezcBaseExportable ) )
91. || is_resource ( $data ) )
92. {
93. throw new ezcCacheInvalidDataException ( gettype ( $data ), array( 'simple', 'array', 'ezcBaseExportable' ) );
94. }
95. return "<?php\nreturn " . var_export ( $data, true ) . ";\n?>\n";
96. }
97. }
98. ?>

Documentation generated by phpDocumentor 1.4.3