1
|
|
|
<?php |
2
|
|
|
namespace phpbu\App; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Runner actually executes all backup jobs. |
6
|
|
|
* |
7
|
|
|
* @package phpbu |
8
|
|
|
* @subpackage App |
9
|
|
|
* @author Sebastian Feldmann <[email protected]> |
10
|
|
|
* @copyright Sebastian Feldmann <[email protected]> |
11
|
|
|
* @license https://opensource.org/licenses/MIT The MIT License (MIT) |
12
|
|
|
* @link https://phpbu.de/ |
13
|
|
|
* @since Class available since Release 1.0.0 |
14
|
|
|
*/ |
15
|
|
|
class Runner |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* phpbu Factory |
19
|
|
|
* |
20
|
|
|
* @var \phpbu\App\Factory |
21
|
|
|
*/ |
22
|
|
|
protected $factory; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Constructor |
26
|
|
|
* |
27
|
|
|
* @param \phpbu\App\Factory $factory |
28
|
|
|
*/ |
29
|
|
|
public function __construct(Factory $factory) |
30
|
|
|
{ |
31
|
|
|
$this->factory = $factory; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Factory getter |
36
|
|
|
* |
37
|
|
|
* @return \phpbu\App\Factory |
38
|
|
|
*/ |
39
|
|
|
public function getFactory() |
40
|
|
|
{ |
41
|
|
|
return $this->factory; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Run phpbu |
46
|
|
|
* |
47
|
|
|
* @param \phpbu\App\Configuration $configuration |
48
|
|
|
* @param \phpbu\App\Factory |
49
|
|
|
* @return \phpbu\App\Result |
50
|
|
|
* @throws \phpbu\App\Exception |
51
|
|
|
*/ |
52
|
|
|
public function run(Configuration $configuration) |
53
|
|
|
{ |
54
|
|
|
$result = new Result(); |
55
|
|
|
$this->setupLoggers($configuration, $result); |
56
|
|
|
|
57
|
|
|
$backupRunner = new Runner\Backup($this->factory, $result); |
58
|
|
|
return $backupRunner->run($configuration); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Create and register all configured loggers. |
63
|
|
|
* |
64
|
|
|
* @param \phpbu\App\Configuration $configuration |
65
|
|
|
* @param \phpbu\App\Result $result |
66
|
|
|
* @throws \phpbu\App\Exception |
67
|
|
|
*/ |
68
|
|
|
protected function setupLoggers(Configuration $configuration, Result $result) |
69
|
|
|
{ |
70
|
|
|
foreach ($configuration->getLoggers() as $log) { |
71
|
|
|
// this is a already fully setup Listener so just add it |
72
|
|
|
if ($log instanceof Listener) { |
73
|
|
|
$logger = $log; |
74
|
|
|
} else { |
75
|
|
|
// this is a configuration blueprint for a logger, so create and add it |
76
|
|
|
/** @var \phpbu\App\Configuration\Logger $log */ |
77
|
|
|
/** @var \phpbu\App\Listener $logger */ |
78
|
|
|
$logger = $this->factory->createLogger($log->type, $log->options); |
79
|
|
|
} |
80
|
|
|
$result->addListener($logger); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|