1 | <?php |
||
20 | class Tar extends Abstraction implements Executable |
||
21 | { |
||
22 | /** |
||
23 | * Path to compress |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | private $path; |
||
28 | |||
29 | /** |
||
30 | * Compression to use |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | private $compression; |
||
35 | |||
36 | /** |
||
37 | * Path to dump file |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | private $tarPathname; |
||
42 | |||
43 | /** |
||
44 | * List of excluded path. |
||
45 | * --exclude='foo' |
||
46 | * |
||
47 | * @var array |
||
48 | */ |
||
49 | private $excludes = []; |
||
50 | |||
51 | /** |
||
52 | * Ignore failed reads |
||
53 | * --ignore-failed-read |
||
54 | * |
||
55 | * @var bool |
||
56 | */ |
||
57 | private $ignoreFailedRead; |
||
58 | |||
59 | /** |
||
60 | * Should the source directory be removed. |
||
61 | * |
||
62 | * @var boolean |
||
63 | */ |
||
64 | private $removeSourceDir = false; |
||
65 | 13 | ||
66 | /** |
||
67 | 13 | * List of available compressors |
|
68 | 13 | * |
|
69 | 13 | * @var array |
|
70 | */ |
||
71 | private static $availableCompressions = [ |
||
72 | 'bzip2' => 'j', |
||
73 | 'gzip' => 'z', |
||
74 | ]; |
||
75 | |||
76 | /** |
||
77 | 6 | * Constructor. |
|
78 | * |
||
79 | 6 | * @param string $path |
|
80 | */ |
||
81 | public function __construct(string $path = '') |
||
85 | |||
86 | /** |
||
87 | * Return 'tar' compressor option e.g. 'j' for bzip2. |
||
88 | 8 | * |
|
89 | * @param string $compressor |
||
90 | 8 | * @return string |
|
91 | 6 | */ |
|
92 | 6 | protected function getCompressionOption(string $compressor) : string |
|
96 | |||
97 | /** |
||
98 | * Compress tar. |
||
99 | * |
||
100 | * @param string $compression |
||
101 | 1 | * @return \phpbu\App\Cli\Executable\Tar |
|
102 | */ |
||
103 | 1 | public function useCompression(string $compression) : Tar |
|
110 | |||
111 | /** |
||
112 | * Add an path to exclude. |
||
113 | 11 | * |
|
114 | * @param string $path |
||
115 | 11 | * @return \phpbu\App\Cli\Executable\Tar |
|
116 | 1 | */ |
|
117 | public function addExclude(string $path) : Tar |
||
122 | |||
123 | /** |
||
124 | * Ignore failed reads setter. |
||
125 | * |
||
126 | * @param bool $bool |
||
127 | * @return \phpbu\App\Cli\Executable\Tar |
||
128 | 9 | */ |
|
129 | public function ignoreFailedRead(bool $bool) : Tar |
||
134 | |||
135 | /** |
||
136 | * Does the tar handle the compression. |
||
137 | * |
||
138 | * @return bool |
||
139 | */ |
||
140 | 2 | public function handlesCompression() : bool |
|
144 | |||
145 | /** |
||
146 | * Set folder to compress. |
||
147 | * |
||
148 | * @param string $path |
||
149 | 11 | * @return \phpbu\App\Cli\Executable\Tar |
|
150 | * @throws \phpbu\App\Exception |
||
151 | */ |
||
152 | 11 | public function archiveDirectory(string $path) : Tar |
|
158 | |||
159 | 9 | /** |
|
160 | 9 | * Set target filename. |
|
161 | * |
||
162 | * @param string $path |
||
163 | 9 | * @return \phpbu\App\Cli\Executable\Tar |
|
164 | 8 | */ |
|
165 | public function archiveTo(string $path) : Tar |
||
170 | 9 | ||
171 | 9 | /** |
|
172 | * Delete the source directory. |
||
173 | 9 | * |
|
174 | * @param boolean $bool |
||
175 | * @return \phpbu\App\Cli\Executable\Tar |
||
176 | 9 | */ |
|
177 | 2 | public function removeSourceDirectory(bool $bool) : Tar |
|
182 | |||
183 | /** |
||
184 | * Tar CommandLine generator. |
||
185 | * |
||
186 | * @return \SebastianFeldmann\Cli\CommandLine |
||
187 | */ |
||
188 | 2 | protected function createCommandLine() : CommandLine |
|
214 | |||
215 | /** |
||
216 | * Return 'rm' command. |
||
217 | * |
||
218 | * @return \SebastianFeldmann\Cli\Command\Executable |
||
219 | */ |
||
220 | protected function getRmCommand() : Cmd |
||
226 | |||
227 | /** |
||
228 | * Check directory to compress. |
||
229 | * |
||
230 | * @param string $path |
||
231 | * @throws \phpbu\App\Exception |
||
232 | */ |
||
233 | private function validateDirectory(string $path) |
||
239 | |||
240 | /** |
||
241 | * Check if source and target values are set. |
||
242 | * |
||
243 | * @throws \phpbu\App\Exception |
||
244 | */ |
||
245 | private function validateSetup() |
||
254 | |||
255 | /** |
||
256 | * Return true if a given compression is valid false otherwise. |
||
257 | * |
||
258 | * @param string $compression |
||
259 | * @return bool |
||
260 | */ |
||
261 | public static function isCompressionValid(string $compression) : bool |
||
265 | } |
||
266 |