This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
AbstractCompressionAlgorithm.php
77 lines (67 loc) · 1.71 KB
/
AbstractCompressionAlgorithm.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Filter\Compress;
use Traversable;
use Zend\Stdlib\ArrayUtils;
/**
* Abstract compression adapter
*/
abstract class AbstractCompressionAlgorithm implements CompressionAlgorithmInterface
{
/**
* @var array
*/
protected $options = [];
/**
* Class constructor
*
* @param null|array|Traversable $options (Optional) Options to set
*/
public function __construct($options = null)
{
if ($options instanceof Traversable) {
$options = ArrayUtils::iteratorToArray($options);
}
if (is_array($options)) {
$this->setOptions($options);
}
}
/**
* Returns one or all set options
*
* @param string|null $option Option to return
* @return mixed
*/
public function getOptions($option = null)
{
if ($option === null) {
return $this->options;
}
if (! isset($this->options[$option])) {
return null;
}
return $this->options[$option];
}
/**
* Sets all or one option
*
* @param array $options
* @return self
*/
public function setOptions(array $options)
{
foreach ($options as $key => $option) {
$method = 'set' . $key;
if (method_exists($this, $method)) {
$this->$method($option);
}
}
return $this;
}
}