File indexing completed on 2024-12-22 05:36:48
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Json 0017 * @subpackage Server 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** Zend_Server_Cache */ 0024 // require_once 'Zend/Server/Cache.php'; 0025 0026 /** 0027 * Zend_Json_Server_Cache: cache Zend_Json_Server server definition and SMD 0028 * 0029 * @category Zend 0030 * @package Zend_Json 0031 * @subpackage Server 0032 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0033 * @license http://framework.zend.com/license/new-bsd New BSD License 0034 */ 0035 class Zend_Json_Server_Cache extends Zend_Server_Cache 0036 { 0037 /** 0038 * Cache a service map description (SMD) to a file 0039 * 0040 * Returns true on success, false on failure 0041 * 0042 * @param string $filename 0043 * @param Zend_Json_Server $server 0044 * @return boolean 0045 */ 0046 public static function saveSmd($filename, Zend_Json_Server $server) 0047 { 0048 if (!is_string($filename) 0049 || (!file_exists($filename) && !is_writable(dirname($filename)))) 0050 { 0051 return false; 0052 } 0053 0054 if (0 === @file_put_contents($filename, $server->getServiceMap()->toJson())) { 0055 return false; 0056 } 0057 0058 return true; 0059 } 0060 0061 /** 0062 * Retrieve a cached SMD 0063 * 0064 * On success, returns the cached SMD (a JSON string); an failure, returns 0065 * boolean false. 0066 * 0067 * @param string $filename 0068 * @return string|false 0069 */ 0070 public static function getSmd($filename) 0071 { 0072 if (!is_string($filename) 0073 || !file_exists($filename) 0074 || !is_readable($filename)) 0075 { 0076 return false; 0077 } 0078 0079 0080 if (false === ($smd = @file_get_contents($filename))) { 0081 return false; 0082 } 0083 0084 return $smd; 0085 } 0086 0087 /** 0088 * Delete a file containing a cached SMD 0089 * 0090 * @param string $filename 0091 * @return bool 0092 */ 0093 public static function deleteSmd($filename) 0094 { 0095 if (is_string($filename) && file_exists($filename)) { 0096 unlink($filename); 0097 return true; 0098 } 0099 0100 return false; 0101 } 0102 }