PageRenderTime 41ms CodeModel.GetById 33ms app.highlight 5ms RepoModel.GetById 1ms 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
  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
 22
 23/** Zend_Pdf_Filter_Compression */
 24require_once 'Zend/Pdf/Filter/Compression.php';
 25
 26/**
 27 * Flate stream filter
 28 *
 29 * @package    Zend_Pdf
 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 */
 33class Zend_Pdf_Filter_Compression_Flate extends Zend_Pdf_Filter_Compression
 34{
 35    /**
 36     * Encode data
 37     *
 38     * @param string $data
 39     * @param array $params
 40     * @return string
 41     * @throws Zend_Pdf_Exception
 42     */
 43    public static function encode($data, $params = null)
 44    {
 45        if ($params != null) {
 46            $data = self::_applyEncodeParams($data, $params);
 47        }
 48
 49        if (extension_loaded('zlib')) {
 50            $trackErrors = ini_get( "track_errors");
 51            ini_set('track_errors', '1');
 52
 53            if (($output = @gzcompress($data)) === false) {
 54                ini_set('track_errors', $trackErrors);
 55                require_once 'Zend/Pdf/Exception.php';
 56                throw new Zend_Pdf_Exception($php_errormsg);
 57            }
 58
 59            ini_set('track_errors', $trackErrors);
 60        } else {
 61            require_once 'Zend/Pdf/Exception.php';
 62            throw new Zend_Pdf_Exception('Not implemented yet. You have to use zlib extension.');
 63        }
 64
 65        return $output;
 66    }
 67
 68    /**
 69     * Decode data
 70     *
 71     * @param string $data
 72     * @param array $params
 73     * @return string
 74     * @throws Zend_Pdf_Exception
 75     */
 76    public static function decode($data, $params = null)
 77    {
 78        global $php_errormsg;
 79
 80        if (extension_loaded('zlib')) {
 81            $trackErrors = ini_get( "track_errors");
 82            ini_set('track_errors', '1');
 83
 84            if (($output = @gzuncompress($data)) === false) {
 85                ini_set('track_errors', $trackErrors);
 86                require_once 'Zend/Pdf/Exception.php';
 87                throw new Zend_Pdf_Exception($php_errormsg);
 88            }
 89
 90            ini_set('track_errors', $trackErrors);
 91        } else {
 92            require_once 'Zend/Pdf/Exception.php';
 93            throw new Zend_Pdf_Exception('Not implemented yet');
 94        }
 95
 96        if ($params !== null) {
 97            return self::_applyDecodeParams($output, $params);
 98        } else {
 99            return $output;
100        }
101    }
102}