File tree Expand file tree Collapse file tree 3 files changed +73
-55
lines changed
Expand file tree Collapse file tree 3 files changed +73
-55
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ namespace phpbu \App \Backup \Compressor ;
3+
4+ use phpbu \App \Backup \Cli ;
5+ use phpbu \App \Backup \Target ;
6+ use phpbu \App \Cli \Executable \Compressor ;
7+ use phpbu \App \Exception ;
8+ use phpbu \App \Result ;
9+
10+ /**
11+ * Compressor base class.
12+ *
13+ * @package phpbu
14+ * @subpackage Backup
15+ * @author Sebastian Feldmann <sebastian@phpbu.de>
16+ * @copyright Sebastian Feldmann <sebastian@phpbu.de>
17+ * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
18+ * @link http://phpbu.de/
19+ * @since Class available since Release 2.0.2
20+ */
21+ abstract class Abstraction extends Cli
22+ {
23+ /**
24+ * Path to cli binary.
25+ *
26+ * @var string
27+ */
28+ protected $ pathToCommand ;
29+
30+ /**
31+ * File to dir to compress.
32+ *
33+ * @var string
34+ */
35+ protected $ path ;
36+
37+ /**
38+ * Constructor.
39+ *
40+ * @param string $path
41+ * @param string $pathToCommand
42+ * @throws \phpbu\App\Exception
43+ */
44+ public function __construct ($ path , $ pathToCommand = null )
45+ {
46+ if (empty ($ path )) {
47+ throw new Exception ('no path to compress set ' );
48+ }
49+ if (!$ this ->isPathValid ($ path )) {
50+ throw new Exception ('path to compress should be a file ' );
51+ }
52+ $ this ->path = $ path ;
53+ $ this ->pathToCommand = $ pathToCommand ;
54+ }
55+
56+ /**
57+ * Validate path.
58+ *
59+ * @param string $path
60+ * @return boolean
61+ */
62+ abstract public function isPathValid ($ path );
63+ }
Original file line number Diff line number Diff line change 11<?php
22namespace phpbu \App \Backup \Compressor ;
33
4- use phpbu \App \Backup \Cli ;
54use phpbu \App \Backup \Target ;
65use phpbu \App \Cli \Executable \Tar ;
76use phpbu \App \Exception ;
1817 * @link http://phpbu.de/
1918 * @since Class available since Release 2.0.1
2019 */
21- class Directory extends Cli
20+ class Directory extends Abstraction
2221{
2322 /**
24- * Path to cli binary.
25- *
26- * @var string
27- */
28- private $ pathToCommand ;
29-
30- /**
31- * Path to dir to compress.
32- *
33- * @var string
34- */
35- private $ path ;
36-
37- /**
38- * Constructor.
23+ * Validate path.
3924 *
4025 * @param string $path
41- * @param string $pathToCommand
42- * @throws \phpbu\App\Exception
26+ * @return boolean
4327 */
44- public function __construct ($ path, $ pathToCommand = null )
28+ public function isPathValid ($ path )
4529 {
46- if (empty ($ path )) {
47- throw new Exception ('no path to compress set ' );
48- }
49- if (!is_dir ($ path )) {
50- throw new Exception ('path to compress should be a directory ' );
51- }
52- $ this ->path = $ path ;
53- $ this ->pathToCommand = $ pathToCommand ;
30+ return is_dir ($ path );
5431 }
5532
5633 /**
Original file line number Diff line number Diff line change 1818 * @link http://phpbu.de/
1919 * @since Class available since Release 2.0.2
2020 */
21- class File extends Cli
21+ class File extends Abstraction
2222{
2323 /**
24- * Path to cli binary.
25- *
26- * @var string
27- */
28- private $ pathToCommand ;
29-
30- /**
31- * File to dir to compress.
32- *
33- * @var string
34- */
35- private $ path ;
36-
37- /**
38- * Constructor.
24+ * Validate path.
3925 *
4026 * @param string $path
41- * @param string $pathToCommand
42- * @throws \phpbu\App\Exception
27+ * @return boolean
4328 */
44- public function __construct ($ path, $ pathToCommand = null )
29+ public function isPathValid ($ path )
4530 {
46- if (empty ($ path )) {
47- throw new Exception ('no path to compress set ' );
48- }
49- if (!is_file ($ path )) {
50- throw new Exception ('path to compress should be a file ' );
51- }
52- $ this ->path = $ path ;
53- $ this ->pathToCommand = $ pathToCommand ;
31+ return is_file ($ path );
5432 }
5533
5634 /**
You can’t perform that action at this time.
0 commit comments