PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_akeeba/liveupdate/classes/storage/storage.php

https://bitbucket.org/organicdevelopment/joomla-2.5
PHP | 99 lines | 58 code | 11 blank | 30 comment | 13 complexity | 634b83ad26ac9719558d70a44d15351b MD5 | raw file
Possible License(s): LGPL-3.0, GPL-2.0, MIT, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /**
  3. * @package LiveUpdate
  4. * @copyright Copyright (c)2010-2012 Nicholas K. Dionysopoulos / AkeebaBackup.com
  5. * @license GNU LGPLv3 or later <http://www.gnu.org/copyleft/lesser.html>
  6. */
  7. defined('_JEXEC') or die();
  8. /**
  9. * Abstract class for the update parameters storage
  10. * @author nicholas
  11. *
  12. */
  13. class LiveUpdateStorage
  14. {
  15. /**
  16. * The update data registry
  17. * @var JRegistry
  18. */
  19. public static $registry = null;
  20. /**
  21. *
  22. * @param string $type
  23. * @param array $config
  24. * @return LiveUpdateStorage
  25. */
  26. public static function getInstance($type, $config)
  27. {
  28. static $instances = array();
  29. $sig = md5($type, serialize($config));
  30. if(!array_key_exists($sig, $instances)) {
  31. require_once dirname(__FILE__).'/'.strtolower($type).'.php';
  32. $className = 'LiveUpdateStorage'.ucfirst($type);
  33. $object = new $className($config);
  34. $object->load($config);
  35. $newRegistry = clone(self::$registry);
  36. $object->setRegistry($newRegistry);
  37. $instances[$sig] = $object;
  38. }
  39. return $instances[$sig];
  40. }
  41. /**
  42. * Returns the internally used registry
  43. *
  44. * @return JRegistry
  45. */
  46. public function &getRegistry()
  47. {
  48. return self::$registry;
  49. }
  50. /**
  51. * Replaces the internally used registry with the one supplied
  52. *
  53. * @param JRegistry $registry
  54. */
  55. public function setRegistry($registry)
  56. {
  57. self::$registry = $registry;
  58. }
  59. public final function set($key, $value)
  60. {
  61. if($key == 'updatedata') {
  62. if(function_exists('json_encode') && function_exists('json_decode')) {
  63. $value = json_encode($value);
  64. } elseif(function_exists('base64_encode') && function_exists('base64_decode')) {
  65. $value = base64_encode(serialize($value));
  66. } else {
  67. $value = serialize($value);
  68. }
  69. }
  70. self::$registry->setValue("update.$key", $value);
  71. }
  72. public final function get($key, $default)
  73. {
  74. $value = self::$registry->getValue("update.$key", $default);
  75. if($key == 'updatedata') {
  76. if(function_exists('json_encode') && function_exists('json_decode')) {
  77. $value = json_decode($value);
  78. } elseif(function_exists('base64_encode') && function_exists('base64_decode')) {
  79. $value = unserialize(base64_decode($value));
  80. } else {
  81. $value = unserialize($value);
  82. }
  83. }
  84. return $value;
  85. }
  86. public function save() {}
  87. public function load($config) {}
  88. }