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\Source; |
14
|
|
|
|
15
|
|
|
use RunOpenCode\Backup\Contract\SourceInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class SourceCollection |
19
|
|
|
* |
20
|
|
|
* Source collection enables fetching of backups from multiple sources. |
21
|
|
|
* |
22
|
|
|
* @package RunOpenCode\Backup\Source |
23
|
|
|
*/ |
24
|
|
|
final class SourceCollection implements SourceInterface, \IteratorAggregate |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var SourceInterface[] |
28
|
|
|
*/ |
29
|
|
|
private $sources; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Constructor. |
33
|
|
|
* |
34
|
|
|
* @param SourceInterface[] $sources Initial sources to add. |
35
|
|
|
*/ |
36
|
4 |
|
public function __construct(array $sources = array()) |
37
|
|
|
{ |
38
|
4 |
|
$this->sources = array(); |
39
|
|
|
|
40
|
4 |
|
foreach ($sources as $source) { |
41
|
|
|
$this->add($source); |
42
|
2 |
|
} |
43
|
4 |
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Add source to collection. |
47
|
|
|
* |
48
|
|
|
* @param SourceInterface $source Source to add. |
49
|
|
|
* @return SourceCollection $this Fluent interface. |
50
|
|
|
*/ |
51
|
4 |
|
public function add(SourceInterface $source) |
52
|
|
|
{ |
53
|
4 |
|
$this->sources[] = $source; |
54
|
4 |
|
return $this; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritdoc} |
59
|
|
|
*/ |
60
|
4 |
|
public function fetch() |
61
|
|
|
{ |
62
|
4 |
|
$files = array(); |
63
|
|
|
/** |
64
|
|
|
* @var SourceInterface $source |
65
|
|
|
*/ |
66
|
4 |
|
foreach ($this->sources as $source) { |
67
|
4 |
|
$files = array_merge($files, $source->fetch()); |
68
|
2 |
|
} |
69
|
|
|
|
70
|
2 |
|
return $files; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritdoc} |
75
|
|
|
*/ |
76
|
|
|
public function getIterator() |
77
|
|
|
{ |
78
|
|
|
return new \ArrayIterator($this->sources); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|