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\Destination; |
14
|
|
|
|
15
|
|
|
use RunOpenCode\Backup\Contract\BackupInterface; |
16
|
|
|
use RunOpenCode\Backup\Contract\DestinationInterface; |
17
|
|
|
/** |
18
|
|
|
* Class BaseDestination |
19
|
|
|
* |
20
|
|
|
* BaseDestination provides prototype for concrete destination implementation. |
21
|
|
|
* |
22
|
|
|
* @package RunOpenCode\Backup\Destination |
23
|
|
|
*/ |
24
|
|
|
abstract class BaseDestination implements DestinationInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var BackupInterface[] |
28
|
|
|
*/ |
29
|
|
|
protected $backups; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
public function getIterator() |
35
|
|
|
{ |
36
|
|
|
if (is_null($this->backups)) { |
37
|
|
|
$this->load(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
return new \ArrayIterator($this->backups); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
*/ |
46
|
14 |
|
public function get($name) |
47
|
|
|
{ |
48
|
14 |
|
if (is_null($this->backups)) { |
49
|
|
|
$this->load(); |
50
|
|
|
} |
51
|
|
|
|
52
|
14 |
|
return $this->backups[$name]; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritdoc} |
57
|
|
|
*/ |
58
|
16 |
|
public function has($name) |
59
|
|
|
{ |
60
|
16 |
|
if (is_null($this->backups)) { |
61
|
14 |
|
$this->load(); |
62
|
14 |
|
} |
63
|
|
|
|
64
|
16 |
|
return array_key_exists($name, $this->backups); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
2 |
|
public function all() |
71
|
|
|
{ |
72
|
2 |
|
if (is_null($this->backups)) { |
73
|
2 |
|
$this->load(); |
74
|
2 |
|
} |
75
|
|
|
|
76
|
2 |
|
return $this->backups; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* {@inheritdoc} |
81
|
|
|
*/ |
82
|
6 |
|
public function count() |
83
|
|
|
{ |
84
|
6 |
|
if (is_null($this->backups)) { |
85
|
|
|
$this->load(); |
86
|
|
|
} |
87
|
|
|
|
88
|
6 |
|
return count($this->backups); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Load backups from destination. |
93
|
|
|
* |
94
|
|
|
* @return BackupInterface[] |
95
|
|
|
*/ |
96
|
|
|
abstract protected function load(); |
97
|
|
|
} |
98
|
|
|
|