Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Zend_Filter_Compress_Gz Class Reference
Inheritance diagram for Zend_Filter_Compress_Gz:
Zend_Filter_Compress_CompressAbstract Zend_Filter_Compress_CompressInterface

Public Member Functions

 __construct ($options=null)
 
 getLevel ()
 
 setLevel ($level)
 
 getMode ()
 
 setMode ($mode)
 
 getArchive ()
 
 setArchive ($archive)
 
 compress ($content)
 
 decompress ($content)
 
 toString ()
 
- Public Member Functions inherited from Zend_Filter_Compress_CompressAbstract
 __construct ($options=null)
 
 getOptions ($option=null)
 
 setOptions (array $options)
 

Protected Attributes

 $_options
 

Detailed Description

Definition at line 35 of file Gz.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $options = null)

Class constructor

Parameters
array | Zend_Config | null$options(Optional) Options to set

Definition at line 58 of file Gz.php.

59  {
60  if (!extension_loaded('zlib')) {
61  #require_once 'Zend/Filter/Exception.php';
62  throw new Zend_Filter_Exception('This filter needs the zlib extension');
63  }
64  parent::__construct($options);
65  }

Member Function Documentation

◆ compress()

compress (   $content)

Compresses the given content

Parameters
string$content
Returns
string

Implements Zend_Filter_Compress_CompressInterface.

Definition at line 148 of file Gz.php.

149  {
150  $archive = $this->getArchive();
151  if (!empty($archive)) {
152  $file = gzopen($archive, 'w' . $this->getLevel());
153  if (!$file) {
154  #require_once 'Zend/Filter/Exception.php';
155  throw new Zend_Filter_Exception("Error opening the archive '" . $this->_options['archive'] . "'");
156  }
157 
158  gzwrite($file, $content);
159  gzclose($file);
160  $compressed = true;
161  } else if ($this->_options['mode'] == 'deflate') {
162  $compressed = gzdeflate($content, $this->getLevel());
163  } else {
164  $compressed = gzcompress($content, $this->getLevel());
165  }
166 
167  if (!$compressed) {
168  #require_once 'Zend/Filter/Exception.php';
169  throw new Zend_Filter_Exception('Error during compression');
170  }
171 
172  return $compressed;
173  }

◆ decompress()

decompress (   $content)

Decompresses the given content

Parameters
string$content
Returns
string

Implements Zend_Filter_Compress_CompressInterface.

Definition at line 181 of file Gz.php.

182  {
183  $archive = $this->getArchive();
184  $mode = $this->getMode();
185  if (@file_exists($content)) {
186  $archive = $content;
187  }
188 
189  if (@file_exists($archive)) {
190  $handler = fopen($archive, "rb");
191  if (!$handler) {
192  #require_once 'Zend/Filter/Exception.php';
193  throw new Zend_Filter_Exception("Error opening the archive '" . $archive . "'");
194  }
195 
196  fseek($handler, -4, SEEK_END);
197  $packet = fread($handler, 4);
198  $bytes = unpack("V", $packet);
199  $size = end($bytes);
200  fclose($handler);
201 
202  $file = gzopen($archive, 'r');
203  $compressed = gzread($file, $size);
204  gzclose($file);
205  } else if ($mode == 'deflate') {
206  $compressed = gzinflate($content);
207  } else {
208  $compressed = gzuncompress($content);
209  }
210 
211  if (!$compressed) {
212  #require_once 'Zend/Filter/Exception.php';
213  throw new Zend_Filter_Exception('Error during compression');
214  }
215 
216  return $compressed;
217  }
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
Definition: grid.phtml:15
catch(\Exception $e) $handler
Definition: index.php:30

◆ getArchive()

getArchive ( )

Returns the set archive

Returns
string

Definition at line 125 of file Gz.php.

126  {
127  return $this->_options['archive'];
128  }

◆ getLevel()

getLevel ( )

Returns the set compression level

Returns
integer

Definition at line 72 of file Gz.php.

73  {
74  return $this->_options['level'];
75  }

◆ getMode()

getMode ( )

Returns the set compression mode

Returns
string

Definition at line 99 of file Gz.php.

100  {
101  return $this->_options['mode'];
102  }

◆ setArchive()

setArchive (   $archive)

Sets the archive to use for de-/compression

Parameters
string$archiveArchive to use
Returns
Zend_Filter_Compress_Gz

Definition at line 136 of file Gz.php.

137  {
138  $this->_options['archive'] = (string) $archive;
139  return $this;
140  }

◆ setLevel()

setLevel (   $level)

Sets a new compression level

Parameters
integer$level
Returns
Zend_Filter_Compress_Gz

Definition at line 83 of file Gz.php.

84  {
85  if (($level < 0) || ($level > 9)) {
86  #require_once 'Zend/Filter/Exception.php';
87  throw new Zend_Filter_Exception('Level must be between 0 and 9');
88  }
89 
90  $this->_options['level'] = (int) $level;
91  return $this;
92  }

◆ setMode()

setMode (   $mode)

Sets a new compression mode

Parameters
string$modeSupported are 'compress', 'deflate' and 'file'

Definition at line 109 of file Gz.php.

110  {
111  if (($mode != 'compress') && ($mode != 'deflate')) {
112  #require_once 'Zend/Filter/Exception.php';
113  throw new Zend_Filter_Exception('Given compression mode not supported');
114  }
115 
116  $this->_options['mode'] = $mode;
117  return $this;
118  }
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
Definition: grid.phtml:15

◆ toString()

toString ( )

Returns the adapter name

Returns
string

Implements Zend_Filter_Compress_CompressInterface.

Definition at line 224 of file Gz.php.

225  {
226  return 'Gz';
227  }

Field Documentation

◆ $_options

$_options
protected
Initial value:
= array(
'level' => 9,
'mode' => 'compress',
'archive' => null,
)

Definition at line 47 of file Gz.php.


The documentation for this class was generated from the following file: