Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Compress.php
Go to the documentation of this file.
1 <?php
25 #require_once 'Zend/Filter/Interface.php';
26 
36 {
40  protected $_adapter = 'Gz';
41 
45  protected $_adapterOptions = array();
46 
52  public function __construct($options = null)
53  {
54  if ($options instanceof Zend_Config) {
55  $options = $options->toArray();
56  }
57  if (is_string($options)) {
58  $this->setAdapter($options);
60  $this->setAdapter($options);
61  } elseif (is_array($options)) {
62  $this->setOptions($options);
63  }
64  }
65 
72  public function setOptions(array $options)
73  {
74  foreach ($options as $key => $value) {
75  if ($key == 'options') {
76  $key = 'adapterOptions';
77  }
78  $method = 'set' . ucfirst($key);
79  if (method_exists($this, $method)) {
80  $this->$method($value);
81  }
82  }
83  return $this;
84  }
85 
91  public function getAdapter()
92  {
93  if ($this->_adapter instanceof Zend_Filter_Compress_CompressInterface) {
94  return $this->_adapter;
95  }
96 
98  $options = $this->getAdapterOptions();
99  if (!class_exists($adapter)) {
100  #require_once 'Zend/Loader.php';
101  if (Zend_Loader::isReadable('Zend/Filter/Compress/' . ucfirst($adapter) . '.php')) {
102  $adapter = 'Zend_Filter_Compress_' . ucfirst($adapter);
103  }
105  }
106 
107  $this->_adapter = new $adapter($options);
108  if (!$this->_adapter instanceof Zend_Filter_Compress_CompressInterface) {
109  #require_once 'Zend/Filter/Exception.php';
110  throw new Zend_Filter_Exception("Compression adapter '" . $adapter . "' does not implement Zend_Filter_Compress_CompressInterface");
111  }
112  return $this->_adapter;
113  }
114 
120  public function getAdapterName()
121  {
122  return $this->getAdapter()->toString();
123  }
124 
131  public function setAdapter($adapter)
132  {
134  $this->_adapter = $adapter;
135  return $this;
136  }
137  if (!is_string($adapter)) {
138  #require_once 'Zend/Filter/Exception.php';
139  throw new Zend_Filter_Exception('Invalid adapter provided; must be string or instance of Zend_Filter_Compress_CompressInterface');
140  }
141  $this->_adapter = $adapter;
142 
143  return $this;
144  }
145 
151  public function getAdapterOptions()
152  {
153  return $this->_adapterOptions;
154  }
155 
162  public function setAdapterOptions(array $options)
163  {
164  $this->_adapterOptions = $options;
165  return $this;
166  }
167 
174  public function __call($method, $options)
175  {
176  $adapter = $this->getAdapter();
177  if (!method_exists($adapter, $method)) {
178  #require_once 'Zend/Filter/Exception.php';
179  throw new Zend_Filter_Exception("Unknown method '{$method}'");
180  }
181 
182  return call_user_func_array(array($adapter, $method), $options);
183  }
184 
193  public function filter($value)
194  {
195  return $this->getAdapter()->compress($value);
196  }
197 }
__construct($options=null)
Definition: Compress.php:52
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
static loadClass($class, $dirs=null)
Definition: Loader.php:52
setOptions(array $options)
Definition: Compress.php:72
setAdapterOptions(array $options)
Definition: Compress.php:162
$adapter
Definition: webapi_user.php:16
static isReadable($filename)
Definition: Loader.php:162
$value
Definition: gender.phtml:16
__call($method, $options)
Definition: Compress.php:174
$method
Definition: info.phtml:13
setAdapter($adapter)
Definition: Compress.php:131