Skip to content

Commit 923b330

Browse files
Massive refactoring: separated backup actions (source, sync, crypter) from cli execution logic
1 parent 62cbee3 commit 923b330

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+4883
-2647
lines changed

src/Backup/Cli.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
namespace phpbu\App\Backup;
3+
4+
use phpbu\App\Cli\Executable;
5+
6+
/**
7+
* Base class for Actions using cli tools.
8+
*
9+
* @package phpbu
10+
* @subpackage Backup
11+
* @author Sebastian Feldmann <sebastian@phpbu.de>
12+
* @copyright Sebastian Feldmann <sebastian@phpbu.de>
13+
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
14+
* @link http://phpbu.de/
15+
* @since Class available since Release 2.0.2
16+
*/
17+
abstract class Cli
18+
{
19+
/**
20+
* Command to execute
21+
*
22+
* @var \phpbu\App\Cli\Executable
23+
*/
24+
protected $executable;
25+
26+
/**
27+
* Exec setter, mostly for test purposes.
28+
*
29+
* @param \phpbu\App\Cli\Executable $exec
30+
*/
31+
public function setExecutable(Executable $exec)
32+
{
33+
$this->executable = $exec;
34+
}
35+
36+
/**
37+
* Executes the cli commands and handles compression
38+
*
39+
* @param \phpbu\App\Backup\Target $target
40+
* @return \phpbu\App\Cli\Result
41+
* @throws \phpbu\App\Exception
42+
*/
43+
protected function execute(Target $target)
44+
{
45+
return $this->getExecutable($target)->run();
46+
}
47+
48+
/**
49+
* Returns the executable for this action.
50+
*
51+
* @param \phpbu\App\Backup\Target $target
52+
* @return \phpbu\App\Cli\Executable
53+
*/
54+
public abstract function getExecutable(Target $target);
55+
}

src/Backup/Cli/Binary.php

Lines changed: 0 additions & 206 deletions
This file was deleted.

src/Backup/Cli/Exec.php

Lines changed: 0 additions & 71 deletions
This file was deleted.

src/Backup/Compressor.php

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
namespace phpbu\App\Backup;
33

44
use phpbu\App\Exception;
5-
use phpbu\App\Backup\Cli\Cmd;
6-
use phpbu\App\Backup\Cli\Exec;
75

86
/**
97
* Compressor
@@ -83,33 +81,11 @@ public function __construct($cmd, $pathToCmd = null)
8381
/**
8482
* Return the cli command.
8583
*
86-
* @param boolean $includingPath
8784
* @return string
8885
*/
89-
public function getCommand($includingPath = true)
86+
public function getCommand()
9087
{
91-
return ($includingPath ? $this->path : '') . $this->cmd;
92-
}
93-
94-
/**
95-
* Return Exec to actually execute the compressor command.
96-
*
97-
* @param string $fileToCompress
98-
* @param array $options
99-
* @return \phpbu\App\Backup\CLi\Exec
100-
*/
101-
public function getExec($fileToCompress, array $options = array())
102-
{
103-
$cmd = new Cmd($this->getCommand());
104-
foreach ($options as $opt) {
105-
$cmd->addOption($opt);
106-
}
107-
$cmd->addArgument($fileToCompress);
108-
109-
$exec = new Exec();
110-
$exec->addCommand($cmd);
111-
112-
return $exec;
88+
return $this->cmd;
11389
}
11490

11591
/**

0 commit comments

Comments
 (0)