PageRenderTime 34ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/framework/vendor/zend/Zend/Pdf/Filter/Compression/Flate.php

http://zoop.googlecode.com/
PHP | 102 lines | 47 code | 12 blank | 43 comment | 10 complexity | 8b184cad6d551ddcfa95a53b8e862bc5 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_Pdf
  17. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id: Flate.php 20096 2010-01-06 02:05:09Z bkarwin $
  20. */
  21. /** Zend_Pdf_Filter_Compression */
  22. require_once 'Zend/Pdf/Filter/Compression.php';
  23. /**
  24. * Flate stream filter
  25. *
  26. * @package Zend_Pdf
  27. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  28. * @license http://framework.zend.com/license/new-bsd New BSD License
  29. */
  30. class Zend_Pdf_Filter_Compression_Flate extends Zend_Pdf_Filter_Compression
  31. {
  32. /**
  33. * Encode data
  34. *
  35. * @param string $data
  36. * @param array $params
  37. * @return string
  38. * @throws Zend_Pdf_Exception
  39. */
  40. public static function encode($data, $params = null)
  41. {
  42. if ($params != null) {
  43. $data = self::_applyEncodeParams($data, $params);
  44. }
  45. if (extension_loaded('zlib')) {
  46. $trackErrors = ini_get( "track_errors");
  47. ini_set('track_errors', '1');
  48. if (($output = @gzcompress($data)) === false) {
  49. ini_set('track_errors', $trackErrors);
  50. require_once 'Zend/Pdf/Exception.php';
  51. throw new Zend_Pdf_Exception($php_errormsg);
  52. }
  53. ini_set('track_errors', $trackErrors);
  54. } else {
  55. require_once 'Zend/Pdf/Exception.php';
  56. throw new Zend_Pdf_Exception('Not implemented yet. You have to use zlib extension.');
  57. }
  58. return $output;
  59. }
  60. /**
  61. * Decode data
  62. *
  63. * @param string $data
  64. * @param array $params
  65. * @return string
  66. * @throws Zend_Pdf_Exception
  67. */
  68. public static function decode($data, $params = null)
  69. {
  70. global $php_errormsg;
  71. if (extension_loaded('zlib')) {
  72. $trackErrors = ini_get( "track_errors");
  73. ini_set('track_errors', '1');
  74. if (($output = @gzuncompress($data)) === false) {
  75. ini_set('track_errors', $trackErrors);
  76. require_once 'Zend/Pdf/Exception.php';
  77. throw new Zend_Pdf_Exception($php_errormsg);
  78. }
  79. ini_set('track_errors', $trackErrors);
  80. } else {
  81. require_once 'Zend/Pdf/Exception.php';
  82. throw new Zend_Pdf_Exception('Not implemented yet');
  83. }
  84. if ($params !== null) {
  85. return self::_applyDecodeParams($output, $params);
  86. } else {
  87. return $output;
  88. }
  89. }
  90. }