PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/magento/zendframework1/library/Zend/Filter/Compress.php

https://gitlab.com/yousafsyed/easternglamor
PHP | 197 lines | 88 code | 16 blank | 93 comment | 12 complexity | 17af88fb4588855a0fa2ad0c747e567c 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_Filter
  17. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /**
  22. * @see Zend_Filter_Interface
  23. */
  24. #require_once 'Zend/Filter/Interface.php';
  25. /**
  26. * Compresses a given string
  27. *
  28. * @category Zend
  29. * @package Zend_Filter
  30. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_Filter_Compress implements Zend_Filter_Interface
  34. {
  35. /**
  36. * Compression adapter
  37. */
  38. protected $_adapter = 'Gz';
  39. /**
  40. * Compression adapter constructor options
  41. */
  42. protected $_adapterOptions = array();
  43. /**
  44. * Class constructor
  45. *
  46. * @param string|array $options (Optional) Options to set
  47. */
  48. public function __construct($options = null)
  49. {
  50. if ($options instanceof Zend_Config) {
  51. $options = $options->toArray();
  52. }
  53. if (is_string($options)) {
  54. $this->setAdapter($options);
  55. } elseif ($options instanceof Zend_Filter_Compress_CompressInterface) {
  56. $this->setAdapter($options);
  57. } elseif (is_array($options)) {
  58. $this->setOptions($options);
  59. }
  60. }
  61. /**
  62. * Set filter setate
  63. *
  64. * @param array $options
  65. * @return Zend_Filter_Compress
  66. */
  67. public function setOptions(array $options)
  68. {
  69. foreach ($options as $key => $value) {
  70. if ($key == 'options') {
  71. $key = 'adapterOptions';
  72. }
  73. $method = 'set' . ucfirst($key);
  74. if (method_exists($this, $method)) {
  75. $this->$method($value);
  76. }
  77. }
  78. return $this;
  79. }
  80. /**
  81. * Returns the current adapter, instantiating it if necessary
  82. *
  83. * @return string
  84. */
  85. public function getAdapter()
  86. {
  87. if ($this->_adapter instanceof Zend_Filter_Compress_CompressInterface) {
  88. return $this->_adapter;
  89. }
  90. $adapter = $this->_adapter;
  91. $options = $this->getAdapterOptions();
  92. if (!class_exists($adapter)) {
  93. #require_once 'Zend/Loader.php';
  94. if (Zend_Loader::isReadable('Zend/Filter/Compress/' . ucfirst($adapter) . '.php')) {
  95. $adapter = 'Zend_Filter_Compress_' . ucfirst($adapter);
  96. }
  97. Zend_Loader::loadClass($adapter);
  98. }
  99. $this->_adapter = new $adapter($options);
  100. if (!$this->_adapter instanceof Zend_Filter_Compress_CompressInterface) {
  101. #require_once 'Zend/Filter/Exception.php';
  102. throw new Zend_Filter_Exception("Compression adapter '" . $adapter . "' does not implement Zend_Filter_Compress_CompressInterface");
  103. }
  104. return $this->_adapter;
  105. }
  106. /**
  107. * Retrieve adapter name
  108. *
  109. * @return string
  110. */
  111. public function getAdapterName()
  112. {
  113. return $this->getAdapter()->toString();
  114. }
  115. /**
  116. * Sets compression adapter
  117. *
  118. * @param string|Zend_Filter_Compress_CompressInterface $adapter Adapter to use
  119. * @return Zend_Filter_Compress
  120. */
  121. public function setAdapter($adapter)
  122. {
  123. if ($adapter instanceof Zend_Filter_Compress_CompressInterface) {
  124. $this->_adapter = $adapter;
  125. return $this;
  126. }
  127. if (!is_string($adapter)) {
  128. #require_once 'Zend/Filter/Exception.php';
  129. throw new Zend_Filter_Exception('Invalid adapter provided; must be string or instance of Zend_Filter_Compress_CompressInterface');
  130. }
  131. $this->_adapter = $adapter;
  132. return $this;
  133. }
  134. /**
  135. * Retrieve adapter options
  136. *
  137. * @return array
  138. */
  139. public function getAdapterOptions()
  140. {
  141. return $this->_adapterOptions;
  142. }
  143. /**
  144. * Set adapter options
  145. *
  146. * @param array $options
  147. * @return void
  148. */
  149. public function setAdapterOptions(array $options)
  150. {
  151. $this->_adapterOptions = $options;
  152. return $this;
  153. }
  154. /**
  155. * Calls adapter methods
  156. *
  157. * @param string $method Method to call
  158. * @param string|array $options Options for this method
  159. */
  160. public function __call($method, $options)
  161. {
  162. $adapter = $this->getAdapter();
  163. if (!method_exists($adapter, $method)) {
  164. #require_once 'Zend/Filter/Exception.php';
  165. throw new Zend_Filter_Exception("Unknown method '{$method}'");
  166. }
  167. return call_user_func_array(array($adapter, $method), $options);
  168. }
  169. /**
  170. * Defined by Zend_Filter_Interface
  171. *
  172. * Compresses the content $value with the defined settings
  173. *
  174. * @param string $value Content to compress
  175. * @return string The compressed content
  176. */
  177. public function filter($value)
  178. {
  179. return $this->getAdapter()->compress($value);
  180. }
  181. }