PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/horde-3.3.13/lib/Horde/Compress.php

#
PHP | 121 lines | 44 code | 11 blank | 66 comment | 7 complexity | b69e066e237ce7ab87f4924bfd0ff516 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /**
  3. * The Horde_Compress:: class provides an API for various compression
  4. * techniques that can be used by Horde applications.
  5. *
  6. * $Horde: framework/Compress/Compress.php,v 1.7.12.14 2009/01/06 15:22:58 jan Exp $
  7. *
  8. * Copyright 2003-2009 The Horde Project (http://www.horde.org/)
  9. *
  10. * See the enclosed file COPYING for license information (LGPL). If you
  11. * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  12. *
  13. * @author Michael Slusarz <slusarz@horde.org>
  14. * @since Horde 3.0
  15. * @package Horde_Compress
  16. */
  17. class Horde_Compress {
  18. /**
  19. * Attempts to return a concrete Horde_Compress instance based on $driver.
  20. *
  21. * @param mixed $driver The type of concrete Horde_Compress subclass to
  22. * return. If $driver is an array, then we will look
  23. * in $driver[0]/lib/Compress/ for the subclass
  24. * implementation named $driver[1].php.
  25. * @param array $params A hash containing any additional configuration or
  26. * parameters a subclass might need.
  27. *
  28. * @return Horde_Compress The newly created concrete Horde_Compress
  29. * instance, or false on an error.
  30. */
  31. function &factory($driver, $params = array())
  32. {
  33. if (is_array($driver)) {
  34. list($app, $driver) = $driver;
  35. }
  36. $driver = basename($driver);
  37. $class = 'Horde_Compress_' . $driver;
  38. if (!class_exists($class)) {
  39. if (!empty($app)) {
  40. include_once $app . '/lib/Compress/' . $driver . '.php';
  41. } else {
  42. include_once 'Horde/Compress/' . $driver . '.php';
  43. }
  44. }
  45. if (class_exists($class)) {
  46. $compress = new $class($params);
  47. } else {
  48. $compress = false;
  49. }
  50. return $compress;
  51. }
  52. /**
  53. * Attempts to return a reference to a concrete Horde_Compress instance
  54. * based on $driver. It will only create a new instance if no
  55. * Horde_Compress instance with the same parameters currently exists.
  56. *
  57. * This method must be invoked as:
  58. * $var = &Horde_Compress::singleton();
  59. *
  60. * @param mixed $driver See Horde_Compress::factory().
  61. * @param array $params See Horde_Compress::factory().
  62. *
  63. * @return Horde_Compress The concrete Horde_Compress reference, or false
  64. * on an error.
  65. */
  66. function &singleton($driver, $params = array())
  67. {
  68. static $instances = array();
  69. $signature = md5(serialize(array($driver, $params)));
  70. if (!isset($instances[$signature])) {
  71. $instances[$signature] = &Horde_Compress::factory($driver, $params);
  72. }
  73. return $instances[$signature];
  74. }
  75. /**
  76. * Constructor.
  77. *
  78. * @param array $params Parameter array.
  79. */
  80. function Horde_Compress($params = array())
  81. {
  82. }
  83. /**
  84. * Compress the data.
  85. *
  86. * @param string $data The data to compress.
  87. * @param array $params An array of arguments needed to compress the data.
  88. *
  89. * @return mixed The compressed data.
  90. * Returns PEAR_Error object on error.
  91. */
  92. function compress($data, $params = array())
  93. {
  94. return PEAR::raiseError('Unsupported');
  95. }
  96. /**
  97. * Decompress the data.
  98. *
  99. * @param string $data The data to decompress.
  100. * @param array $params An array of arguments needed to decompress the
  101. * data.
  102. *
  103. * @return array The decompressed data.
  104. * Returns PEAR_Error object on error.
  105. */
  106. function decompress($data, $params = array())
  107. {
  108. return PEAR::raiseError('Unsupported');
  109. }
  110. }