|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
7 * This source file is subject to the new BSD license that is bundled |
|
8 * with this package in the file LICENSE.txt. |
|
9 * It is also available through the world-wide-web at this URL: |
|
10 * http://framework.zend.com/license/new-bsd |
|
11 * If you did not receive a copy of the license and are unable to |
|
12 * obtain it through the world-wide-web, please send an email |
|
13 * to license@zend.com so we can send you a copy immediately. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_Json |
|
17 * @subpackage Server |
|
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
20 * @version $Id: Cache.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
21 */ |
|
22 |
|
23 /** Zend_Server_Cache */ |
|
24 require_once 'Zend/Server/Cache.php'; |
|
25 |
|
26 /** |
|
27 * Zend_Json_Server_Cache: cache Zend_Json_Server server definition and SMD |
|
28 * |
|
29 * @category Zend |
|
30 * @package Zend_Json |
|
31 * @subpackage Server |
|
32 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
33 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
34 */ |
|
35 class Zend_Json_Server_Cache extends Zend_Server_Cache |
|
36 { |
|
37 /** |
|
38 * Cache a service map description (SMD) to a file |
|
39 * |
|
40 * Returns true on success, false on failure |
|
41 * |
|
42 * @param string $filename |
|
43 * @param Zend_Json_Server $server |
|
44 * @return boolean |
|
45 */ |
|
46 public static function saveSmd($filename, Zend_Json_Server $server) |
|
47 { |
|
48 if (!is_string($filename) |
|
49 || (!file_exists($filename) && !is_writable(dirname($filename)))) |
|
50 { |
|
51 return false; |
|
52 } |
|
53 |
|
54 if (0 === @file_put_contents($filename, $server->getServiceMap()->toJson())) { |
|
55 return false; |
|
56 } |
|
57 |
|
58 return true; |
|
59 } |
|
60 |
|
61 /** |
|
62 * Retrieve a cached SMD |
|
63 * |
|
64 * On success, returns the cached SMD (a JSON string); an failure, returns |
|
65 * boolean false. |
|
66 * |
|
67 * @param string $filename |
|
68 * @return string|false |
|
69 */ |
|
70 public static function getSmd($filename) |
|
71 { |
|
72 if (!is_string($filename) |
|
73 || !file_exists($filename) |
|
74 || !is_readable($filename)) |
|
75 { |
|
76 return false; |
|
77 } |
|
78 |
|
79 |
|
80 if (false === ($smd = @file_get_contents($filename))) { |
|
81 return false; |
|
82 } |
|
83 |
|
84 return $smd; |
|
85 } |
|
86 |
|
87 /** |
|
88 * Delete a file containing a cached SMD |
|
89 * |
|
90 * @param string $filename |
|
91 * @return bool |
|
92 */ |
|
93 public static function deleteSmd($filename) |
|
94 { |
|
95 if (is_string($filename) && file_exists($filename)) { |
|
96 unlink($filename); |
|
97 return true; |
|
98 } |
|
99 |
|
100 return false; |
|
101 } |
|
102 } |