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

Public Member Functions

 __construct ($options=null)
 
 getCallback ()
 
 setCallback ($callback)
 
 getArchive ()
 
 setArchive ($archive)
 
 getPassword ()
 
 setPassword ($password)
 
 getTarget ()
 
 setTarget ($target)
 
 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 Rar.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $options = null)

Class constructor

Parameters
array$options(Optional) Options to set

Definition at line 60 of file Rar.php.

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

Member Function Documentation

◆ compress()

compress (   $content)

Compresses the given content

Parameters
string | array$content
Returns
string

Implements Zend_Filter_Compress_CompressInterface.

Definition at line 176 of file Rar.php.

177  {
178  $callback = $this->getCallback();
179  if ($callback === null) {
180  #require_once 'Zend/Filter/Exception.php';
181  throw new Zend_Filter_Exception('No compression callback available');
182  }
183 
184  $options = $this->getOptions();
185  unset($options['callback']);
186 
187  $result = call_user_func($callback, $options, $content);
188  if ($result !== true) {
189  #require_once 'Zend/Filter/Exception.php';
190  throw new Zend_Filter_Exception('Error compressing the RAR Archive');
191  }
192 
193  return $this->getArchive();
194  }

◆ decompress()

decompress (   $content)

Decompresses the given content

Parameters
string$content
Returns
boolean

Implements Zend_Filter_Compress_CompressInterface.

Definition at line 202 of file Rar.php.

203  {
204  $archive = $this->getArchive();
205  if (file_exists($content)) {
206  $archive = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, realpath($content));
207  } elseif (empty($archive) || !file_exists($archive)) {
208  #require_once 'Zend/Filter/Exception.php';
209  throw new Zend_Filter_Exception('RAR Archive not found');
210  }
211 
212  $password = $this->getPassword();
213  if ($password !== null) {
214  $archive = rar_open($archive, $password);
215  } else {
216  $archive = rar_open($archive);
217  }
218 
219  if (!$archive) {
220  #require_once 'Zend/Filter/Exception.php';
221  throw new Zend_Filter_Exception("Error opening the RAR Archive");
222  }
223 
224  $target = $this->getTarget();
225  if (!is_dir($target)) {
226  $target = dirname($target);
227  }
228 
229  $filelist = rar_list($archive);
230  if (!$filelist) {
231  #require_once 'Zend/Filter/Exception.php';
232  throw new Zend_Filter_Exception("Error reading the RAR Archive");
233  }
234 
235  foreach($filelist as $file) {
236  $file->extract($target);
237  }
238 
239  rar_close($archive);
240  return true;
241  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$target
Definition: skip.phtml:8

◆ getArchive()

getArchive ( )

Returns the set archive

Returns
string

Definition at line 101 of file Rar.php.

102  {
103  return $this->_options['archive'];
104  }

◆ getCallback()

getCallback ( )

Returns the set callback for compression

Returns
string

Definition at line 74 of file Rar.php.

75  {
76  return $this->_options['callback'];
77  }

◆ getPassword()

getPassword ( )

Returns the set password

Returns
string

Definition at line 125 of file Rar.php.

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

◆ getTarget()

getTarget ( )

Returns the set targetpath

Returns
string

Definition at line 147 of file Rar.php.

148  {
149  return $this->_options['target'];
150  }

◆ setArchive()

setArchive (   $archive)

Sets the archive to use for de-/compression

Parameters
string$archiveArchive to use
Returns
Zend_Filter_Compress_Rar

Definition at line 112 of file Rar.php.

113  {
114  $archive = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $archive);
115  $this->_options['archive'] = (string) $archive;
116 
117  return $this;
118  }

◆ setCallback()

setCallback (   $callback)

Sets the callback to use

Parameters
string$callback
Returns
Zend_Filter_Compress_Rar

Definition at line 85 of file Rar.php.

86  {
87  if (!is_callable($callback)) {
88  #require_once 'Zend/Filter/Exception.php';
89  throw new Zend_Filter_Exception('Callback can not be accessed');
90  }
91 
92  $this->_options['callback'] = $callback;
93  return $this;
94  }

◆ setPassword()

setPassword (   $password)

Sets the password to use

Parameters
string$password
Returns
Zend_Filter_Compress_Rar

Definition at line 136 of file Rar.php.

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

◆ setTarget()

setTarget (   $target)

Sets the targetpath to use

Parameters
string$target
Returns
Zend_Filter_Compress_Rar

Definition at line 158 of file Rar.php.

159  {
160  if (!file_exists(dirname($target))) {
161  #require_once 'Zend/Filter/Exception.php';
162  throw new Zend_Filter_Exception("The directory '$target' does not exist");
163  }
164 
165  $target = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $target);
166  $this->_options['target'] = (string) $target;
167  return $this;
168  }
$target
Definition: skip.phtml:8

◆ toString()

toString ( )

Returns the adapter name

Returns
string

Implements Zend_Filter_Compress_CompressInterface.

Definition at line 248 of file Rar.php.

249  {
250  return 'Rar';
251  }

Field Documentation

◆ $_options

$_options
protected
Initial value:
= array(
'callback' => null,
'archive' => null,
'password' => null,
'target' => '.',
)

Definition at line 48 of file Rar.php.


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