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 | * Should the source directory be removed. |
||
45 | * |
||
46 | * @var boolean |
||
47 | */ |
||
48 | private $removeSourceDir = false; |
||
49 | |||
50 | /** |
||
51 | * List of available compressors |
||
52 | * |
||
53 | * @var array |
||
54 | */ |
||
55 | private static $availableCompressors = array( |
||
56 | 'bzip2' => 'j', |
||
57 | 'gzip' => 'z', |
||
58 | ); |
||
59 | |||
60 | /** |
||
61 | * Constructor. |
||
62 | * |
||
63 | * @param string $path |
||
64 | */ |
||
65 | 13 | public function __construct($path = null) |
|
66 | { |
||
67 | 13 | $this->cmd = 'tar'; |
|
68 | 13 | parent::__construct($path); |
|
69 | 13 | } |
|
70 | |||
71 | /** |
||
72 | * Return 'tar' compressor option e.g. 'j' for bzip2. |
||
73 | * |
||
74 | * @param $compressor |
||
75 | * @return string |
||
76 | */ |
||
77 | 6 | protected function getCompressorOption($compressor) |
|
81 | |||
82 | /** |
||
83 | * Compress tar. |
||
84 | * |
||
85 | * @param string $compressor |
||
86 | * @return \phpbu\App\Cli\Executable\Tar |
||
87 | */ |
||
88 | 8 | public function useCompression($compressor) |
|
89 | { |
||
90 | 8 | if ($this->isCompressorValid($compressor)) { |
|
91 | 6 | $this->compression = $this->getCompressorOption($compressor); |
|
92 | 6 | } |
|
93 | 8 | return $this; |
|
94 | } |
||
95 | |||
96 | /** |
||
97 | * Doe the tar handle the compression. |
||
98 | * |
||
99 | * @return boolean |
||
100 | */ |
||
101 | 1 | public function handlesCompression() |
|
105 | |||
106 | /** |
||
107 | * Set folder to compress. |
||
108 | * |
||
109 | * @param string $path |
||
110 | * @return \phpbu\App\Cli\Executable\Tar |
||
111 | * @throws \phpbu\App\Exception |
||
112 | */ |
||
113 | 11 | public function archiveDirectory($path) |
|
119 | 10 | ||
120 | /** |
||
121 | * Set target filename. |
||
122 | * |
||
123 | * @param string $path |
||
124 | * @return \phpbu\App\Cli\Executable\Tar |
||
125 | */ |
||
126 | public function archiveTo($path) |
||
131 | 9 | ||
132 | /** |
||
133 | * Delete the source directory. |
||
134 | * |
||
135 | * @param boolean $bool |
||
136 | * @return \phpbu\App\Cli\Executable\Tar |
||
137 | */ |
||
138 | public function removeSourceDirectory($bool) |
||
143 | 2 | ||
144 | /** |
||
145 | * Process generator |
||
146 | */ |
||
147 | protected function createProcess() |
||
168 | 9 | ||
169 | 9 | /** |
|
170 | 9 | * Return 'rm' command. |
|
171 | 9 | * |
|
172 | * @return \phpbu\App\Cli\Cmd |
||
173 | 9 | */ |
|
174 | protected function getRmCommand() |
||
180 | 9 | ||
181 | /** |
||
182 | * Check directory to compress. |
||
183 | * |
||
184 | * @param string $path |
||
185 | * @throws \phpbu\App\Exception |
||
186 | */ |
||
187 | private function validateDirectory($path) |
||
196 | |||
197 | /** |
||
198 | * Check if source and target values are set. |
||
199 | * |
||
200 | * @throws \phpbu\App\Exception |
||
201 | */ |
||
202 | private function validateSetup() |
||
211 | |||
212 | /** |
||
213 | * Return true if a given compressor is valid false otherwise. |
||
214 | * |
||
215 | * @param string $compressor |
||
216 | * @return boolean |
||
217 | */ |
||
218 | public static function isCompressorValid($compressor) |
||
222 | } |
||
223 |