*prechod na novsiu verziu ZF
[sport-group.git] / library / Zend / Json / Server / Cache.php
blobca47e2fb7eb385b8a55d639fa46399302ac624ba
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
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.
15 * @category Zend
16 * @package Zend_Json
17 * @subpackage Server
18 * @copyright Copyright (c) 2005-2009 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 16971 2009-07-22 18:05:45Z mikaelkael $
23 /** Zend_Server_Cache */
24 require_once 'Zend/Server/Cache.php';
26 /**
27 * Zend_Json_Server_Cache: cache Zend_Json_Server server definition and SMD
29 * @category Zend
30 * @package Zend_Json
31 * @subpackage Server
32 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
33 * @license http://framework.zend.com/license/new-bsd New BSD License
35 class Zend_Json_Server_Cache extends Zend_Server_Cache
37 /**
38 * Cache a service map description (SMD) to a file
40 * Returns true on success, false on failure
42 * @param string $filename
43 * @param Zend_Json_Server $server
44 * @return boolean
46 public static function saveSmd($filename, Zend_Json_Server $server)
48 if (!is_string($filename)
49 || (!file_exists($filename) && !is_writable(dirname($filename))))
51 return false;
54 if (0 === @file_put_contents($filename, $server->getServiceMap()->toJson())) {
55 return false;
58 return true;
61 /**
62 * Retrieve a cached SMD
64 * On success, returns the cached SMD (a JSON string); an failure, returns
65 * boolean false.
67 * @param string $filename
68 * @return string|false
70 public static function getSmd($filename)
72 if (!is_string($filename)
73 || !file_exists($filename)
74 || !is_readable($filename))
76 return false;
80 if (false === ($smd = @file_get_contents($filename))) {
81 return false;
84 return $smd;
87 /**
88 * Delete a file containing a cached SMD
90 * @param string $filename
91 * @return bool
93 public static function deleteSmd($filename)
95 if (is_string($filename) && file_exists($filename)) {
96 unlink($filename);
97 return true;
100 return false;