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 | * Ignore failed reads |
||
45 | * --ignore-failed-reads |
||
46 | * |
||
47 | * @var bool |
||
48 | */ |
||
49 | private $ignoreFailedReads; |
||
50 | |||
51 | /** |
||
52 | * Should the source directory be removed. |
||
53 | * |
||
54 | * @var boolean |
||
55 | */ |
||
56 | private $removeSourceDir = false; |
||
57 | |||
58 | /** |
||
59 | * List of available compressors |
||
60 | * |
||
61 | * @var array |
||
62 | */ |
||
63 | private static $availableCompressors = array( |
||
64 | 'bzip2' => 'j', |
||
65 | 13 | 'gzip' => 'z', |
|
66 | ); |
||
67 | 13 | ||
68 | 13 | /** |
|
69 | 13 | * Constructor. |
|
70 | * |
||
71 | * @param string $path |
||
72 | */ |
||
73 | public function __construct($path = null) |
||
77 | 6 | ||
78 | /** |
||
79 | 6 | * Return 'tar' compressor option e.g. 'j' for bzip2. |
|
80 | * |
||
81 | * @param $compressor |
||
82 | * @return string |
||
83 | */ |
||
84 | protected function getCompressorOption($compressor) |
||
88 | 8 | ||
89 | /** |
||
90 | 8 | * Compress tar. |
|
91 | 6 | * |
|
92 | 6 | * @param string $compressor |
|
93 | 8 | * @return \phpbu\App\Cli\Executable\Tar |
|
94 | */ |
||
95 | public function useCompression($compressor) |
||
102 | |||
103 | 1 | /** |
|
104 | * Ignore failed reads setter. |
||
105 | * |
||
106 | * @param bool $bool |
||
107 | * @return \phpbu\App\Cli\Executable\Tar |
||
108 | */ |
||
109 | public function ignoreFailedReads($bool) |
||
114 | |||
115 | 11 | /** |
|
116 | 1 | * Doe the tar handle the compression. |
|
117 | * |
||
118 | 10 | * @return boolean |
|
119 | 10 | */ |
|
120 | public function handlesCompression() |
||
124 | |||
125 | /** |
||
126 | * Set folder to compress. |
||
127 | * |
||
128 | 9 | * @param string $path |
|
129 | * @return \phpbu\App\Cli\Executable\Tar |
||
130 | 9 | * @throws \phpbu\App\Exception |
|
131 | 9 | */ |
|
132 | public function archiveDirectory($path) |
||
138 | |||
139 | /** |
||
140 | 2 | * Set target filename. |
|
141 | * |
||
142 | 2 | * @param string $path |
|
143 | 2 | * @return \phpbu\App\Cli\Executable\Tar |
|
144 | */ |
||
145 | public function archiveTo($path) |
||
150 | |||
151 | /** |
||
152 | 11 | * Delete the source directory. |
|
153 | 1 | * |
|
154 | * @param boolean $bool |
||
155 | 10 | * @return \phpbu\App\Cli\Executable\Tar |
|
156 | 1 | */ |
|
157 | public function removeSourceDirectory($bool) |
||
162 | |||
163 | 9 | /** |
|
164 | 8 | * Process generator |
|
165 | */ |
||
166 | 8 | protected function createProcess() |
|
188 | 2 | ||
189 | /** |
||
190 | 2 | * Return 'rm' command. |
|
191 | 2 | * |
|
192 | 2 | * @return \phpbu\App\Cli\Cmd |
|
193 | 2 | */ |
|
194 | 2 | protected function getRmCommand() |
|
200 | |||
201 | /** |
||
202 | * Check directory to compress. |
||
203 | * |
||
204 | 9 | * @param string $path |
|
205 | * @throws \phpbu\App\Exception |
||
206 | 9 | */ |
|
207 | private function validateDirectory($path) |
||
213 | |||
214 | /** |
||
215 | * Check if source and target values are set. |
||
216 | * |
||
217 | * @throws \phpbu\App\Exception |
||
218 | */ |
||
219 | private function validateSetup() |
||
228 | |||
229 | /** |
||
230 | * Return true if a given compressor is valid false otherwise. |
||
231 | * |
||
232 | * @param string $compressor |
||
233 | * @return boolean |
||
234 | */ |
||
235 | public static function isCompressorValid($compressor) |
||
239 | } |
||
240 |