1 | <?php |
||
18 | class CompressionFactory |
||
19 | { |
||
20 | const TYPE_NONE = 'none'; |
||
21 | const TYPE_UNKNOWN = 'unknown'; |
||
22 | |||
23 | /** |
||
24 | * @var CompressorInterface[] |
||
25 | */ |
||
26 | private $compressors; |
||
27 | |||
28 | /** |
||
29 | * @var DeCompressorInterface[] |
||
30 | */ |
||
31 | private $deCompressors; |
||
32 | |||
33 | 11 | public function __construct() |
|
42 | |||
43 | /** |
||
44 | * @param CompressionTypeInterface $type |
||
45 | * |
||
46 | * @return static |
||
47 | */ |
||
48 | 11 | public function addCompressor(CompressionTypeInterface $type) |
|
49 | { |
||
50 | 11 | if ($type instanceof CompressorInterface) { |
|
51 | 11 | $this->compressors[$type->getName()] = $type; |
|
52 | 11 | } |
|
53 | 11 | if ($type instanceof DeCompressorInterface) { |
|
54 | 11 | $this->deCompressors[$type->getName()] = $type; |
|
55 | 11 | } |
|
56 | |||
57 | 11 | return $this; |
|
58 | } |
||
59 | |||
60 | /** |
||
61 | * Check if the specified $compression is valid or not |
||
62 | * |
||
63 | * @param string $compression |
||
64 | * |
||
65 | * @return bool |
||
66 | */ |
||
67 | 1 | public function isCompression($compression) |
|
71 | |||
72 | /** |
||
73 | * @param string $compression |
||
74 | * |
||
75 | * @return CompressorInterface |
||
76 | * @throws InvalidCompressionTypeException |
||
77 | */ |
||
78 | 5 | public function getCompressor($compression) |
|
86 | |||
87 | /** |
||
88 | * @param string $compression |
||
89 | * |
||
90 | * @return DeCompressorInterface |
||
91 | * @throws InvalidCompressionTypeException |
||
92 | */ |
||
93 | 7 | public function getDeCompressor($compression) |
|
101 | } |
||
102 |