1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Backup package, an RunOpenCode project. |
4
|
|
|
* |
5
|
|
|
* (c) 2015 RunOpenCode |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* This project is fork of "kbond/php-backup", for full credits info, please |
11
|
|
|
* view CREDITS file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
namespace RunOpenCode\Backup; |
14
|
|
|
|
15
|
|
|
use RunOpenCode\Backup\Contract\ManagerInterface; |
16
|
|
|
use RunOpenCode\Backup\Contract\ProfileInterface; |
17
|
|
|
use RunOpenCode\Backup\Contract\WorkflowInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class Manager |
21
|
|
|
* |
22
|
|
|
* Backup manager. |
23
|
|
|
* |
24
|
|
|
* @package RunOpenCode\Backup |
25
|
|
|
*/ |
26
|
|
|
final class Manager implements ManagerInterface |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var ProfileInterface[] |
30
|
|
|
*/ |
31
|
|
|
private $profiles; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var WorkflowInterface |
35
|
|
|
*/ |
36
|
|
|
private $workflow; |
37
|
|
|
|
38
|
2 |
|
public function __construct(WorkflowInterface $workflow, $profiles = array()) |
39
|
|
|
{ |
40
|
2 |
|
$this->profiles = array(); |
41
|
2 |
|
$this->workflow = $workflow; |
42
|
|
|
|
43
|
2 |
|
if (!empty($profiles)) { |
44
|
|
|
|
45
|
2 |
|
foreach ($profiles as $profile) { |
46
|
2 |
|
$this->add($profile); |
47
|
2 |
|
} |
48
|
2 |
|
} |
49
|
2 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
2 |
|
public function add(ProfileInterface $profile) |
55
|
|
|
{ |
56
|
2 |
|
$this->profiles[$profile->getName()] = $profile; |
57
|
2 |
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
2 |
|
public function has($name) |
64
|
|
|
{ |
65
|
2 |
|
return (isset($this->profiles[$name])); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritdoc} |
70
|
|
|
*/ |
71
|
2 |
|
public function get($name) |
72
|
|
|
{ |
73
|
2 |
|
return $this->profiles[$name]; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* {@inheritdoc} |
78
|
|
|
*/ |
79
|
2 |
|
public function execute($name) |
80
|
|
|
{ |
81
|
2 |
|
if (!$this->has($name)) { |
82
|
|
|
throw new \RuntimeException(sprintf('Unknown profile: "%s".', $name)); |
83
|
|
|
} |
84
|
|
|
|
85
|
2 |
|
$profile = $this->get($name); |
86
|
2 |
|
$this->workflow->execute($profile); |
87
|
|
|
|
88
|
2 |
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritdoc} |
93
|
|
|
*/ |
94
|
|
|
public function getIterator() |
95
|
|
|
{ |
96
|
|
|
return new \ArrayIterator($this->profiles); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|