PageRenderTime 34ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/framework/vendor/zend/Zend/Json/Server/Cache.php

http://zoop.googlecode.com/
PHP | 102 lines | 38 code | 10 blank | 54 comment | 10 complexity | f0c83e556711f956fc4d43fb252f70c4 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  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. /** Zend_Server_Cache */
  23. require_once 'Zend/Server/Cache.php';
  24. /**
  25. * Zend_Json_Server_Cache: cache Zend_Json_Server server definition and SMD
  26. *
  27. * @category Zend
  28. * @package Zend_Json
  29. * @subpackage Server
  30. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_Json_Server_Cache extends Zend_Server_Cache
  34. {
  35. /**
  36. * Cache a service map description (SMD) to a file
  37. *
  38. * Returns true on success, false on failure
  39. *
  40. * @param string $filename
  41. * @param Zend_Json_Server $server
  42. * @return boolean
  43. */
  44. public static function saveSmd($filename, Zend_Json_Server $server)
  45. {
  46. if (!is_string($filename)
  47. || (!file_exists($filename) && !is_writable(dirname($filename))))
  48. {
  49. return false;
  50. }
  51. if (0 === @file_put_contents($filename, $server->getServiceMap()->toJson())) {
  52. return false;
  53. }
  54. return true;
  55. }
  56. /**
  57. * Retrieve a cached SMD
  58. *
  59. * On success, returns the cached SMD (a JSON string); an failure, returns
  60. * boolean false.
  61. *
  62. * @param string $filename
  63. * @return string|false
  64. */
  65. public static function getSmd($filename)
  66. {
  67. if (!is_string($filename)
  68. || !file_exists($filename)
  69. || !is_readable($filename))
  70. {
  71. return false;
  72. }
  73. if (false === ($smd = @file_get_contents($filename))) {
  74. return false;
  75. }
  76. return $smd;
  77. }
  78. /**
  79. * Delete a file containing a cached SMD
  80. *
  81. * @param string $filename
  82. * @return bool
  83. */
  84. public static function deleteSmd($filename)
  85. {
  86. if (is_string($filename) && file_exists($filename)) {
  87. unlink($filename);
  88. return true;
  89. }
  90. return false;
  91. }
  92. }