1 | <?php |
||
17 | class Compression |
||
18 | { |
||
19 | /** |
||
20 | * Path to command binary |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $path; |
||
25 | |||
26 | /** |
||
27 | * Command name |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $cmd; |
||
32 | |||
33 | /** |
||
34 | * Suffix for compressed files |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $suffix; |
||
39 | |||
40 | /** |
||
41 | * MIME type for compressed files |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $mimeType; |
||
46 | |||
47 | /** |
||
48 | * List of available compressors |
||
49 | * |
||
50 | * @var array |
||
51 | */ |
||
52 | protected static $availableCompressors = [ |
||
53 | 'gzip' => [ |
||
54 | 'suffix' => 'gz', |
||
55 | 'mime' => 'application/x-gzip' |
||
56 | ], |
||
57 | 'bzip2' => [ |
||
58 | 'suffix' => 'bz2', |
||
59 | 'mime' => 'application/x-bzip2' |
||
60 | ], |
||
61 | 'zip' => [ |
||
62 | 'suffix' => 'zip', |
||
63 | 'mime' => 'application/zip' |
||
64 | ] |
||
65 | ]; |
||
66 | |||
67 | /** |
||
68 | * Constructor. |
||
69 | * |
||
70 | * @param string $cmd |
||
71 | * @param string $pathToCmd without trailing slash |
||
72 | */ |
||
73 | public function __construct($cmd, $pathToCmd = null) |
||
74 | { |
||
75 | $this->path = $pathToCmd; |
||
76 | $this->cmd = $cmd; |
||
77 | $this->suffix = self::$availableCompressors[$cmd]['suffix']; |
||
78 | $this->mimeType = self::$availableCompressors[$cmd]['mime']; |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * Return the cli command. |
||
83 | * |
||
84 | * @return string |
||
85 | */ |
||
86 | public function getCommand() |
||
90 | |||
91 | /** |
||
92 | * Path getter. |
||
93 | * |
||
94 | * @return string |
||
95 | */ |
||
96 | public function getPath() |
||
100 | |||
101 | /** |
||
102 | * Returns the compressor suffix e.g. 'bzip2' |
||
103 | * |
||
104 | * @return string |
||
105 | */ |
||
106 | public function getSuffix() |
||
110 | |||
111 | /** |
||
112 | * Returns the compressor mime type. |
||
113 | * |
||
114 | * @return string |
||
115 | */ |
||
116 | public function getMimeType() |
||
120 | |||
121 | /** |
||
122 | * Factory method. |
||
123 | * |
||
124 | * @param string $name |
||
125 | * @return \phpbu\App\Backup\Compressor |
||
126 | * @throws \phpbu\App\Exception |
||
127 | */ |
||
128 | public static function create($name) |
||
142 | } |
||
143 |