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 | 'pipeable' => true, |
||
55 | 'suffix' => 'gz', |
||
56 | 'mime' => 'application/x-gzip' |
||
57 | ], |
||
58 | 'bzip2' => [ |
||
59 | 'pipeable' => true, |
||
60 | 'suffix' => 'bz2', |
||
61 | 'mime' => 'application/x-bzip2' |
||
62 | ], |
||
63 | 'zip' => [ |
||
64 | 'pipeable' => false, |
||
65 | 'suffix' => 'zip', |
||
66 | 'mime' => 'application/zip' |
||
67 | ] |
||
68 | ]; |
||
69 | |||
70 | /** |
||
71 | * Constructor. |
||
72 | * |
||
73 | * @param string $cmd |
||
74 | * @param string $pathToCmd without trailing slash |
||
75 | */ |
||
76 | public function __construct($cmd, $pathToCmd = null) |
||
83 | |||
84 | /** |
||
85 | * Return the cli command. |
||
86 | * |
||
87 | * @return string |
||
88 | */ |
||
89 | public function getCommand() |
||
93 | |||
94 | /** |
||
95 | * Path getter. |
||
96 | * |
||
97 | * @return string |
||
98 | */ |
||
99 | public function getPath() |
||
103 | |||
104 | /** |
||
105 | * Returns the compressor suffix e.g. 'bzip2' |
||
106 | * |
||
107 | * @return string |
||
108 | */ |
||
109 | public function getSuffix() |
||
113 | |||
114 | /** |
||
115 | * Is the compression app pipeable. |
||
116 | * |
||
117 | * @return bool |
||
118 | */ |
||
119 | public function isPipeable() |
||
123 | |||
124 | /** |
||
125 | * Returns the compressor mime type. |
||
126 | * |
||
127 | * @return string |
||
128 | */ |
||
129 | public function getMimeType() |
||
133 | |||
134 | /** |
||
135 | * Factory method. |
||
136 | * |
||
137 | * @param string $name |
||
138 | * @return \phpbu\App\Backup\Target\Compression |
||
139 | * @throws \phpbu\App\Exception |
||
140 | */ |
||
141 | public static function create($name) |
||
155 | } |
||
156 |