1 | <?php |
||
12 | class FlysystemDestination implements DestinationInterface |
||
13 | { |
||
14 | protected $flysystem; |
||
15 | |||
16 | protected $backups; |
||
17 | |||
18 | public function __construct(FilesystemInterface $flysystem) |
||
22 | |||
23 | /** |
||
24 | * {@inheritdoc} |
||
25 | */ |
||
26 | public function push(BackupInterface $backup) |
||
27 | { |
||
28 | throw new DestinationException('Flysystem is not implemented yet.'); |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * {@inheritdoc} |
||
33 | */ |
||
34 | public function get($name) |
||
35 | { |
||
36 | if (is_null($this->backups)) { |
||
37 | $this->load(); |
||
38 | } |
||
39 | |||
40 | return $this->backups[$name]; |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * {@inheritdoc} |
||
45 | */ |
||
46 | public function has($name) |
||
47 | { |
||
48 | if (is_null($this->backups)) { |
||
49 | $this->load(); |
||
50 | } |
||
51 | |||
52 | return array_key_exists($name, $this->backups); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * {@inheritdoc} |
||
57 | */ |
||
58 | public function delete($name) |
||
59 | { |
||
60 | try { |
||
61 | $this->flysystem->deleteDir($name); |
||
62 | } catch (\Exception $e) { |
||
63 | throw new DestinationException(sprintf('Unable to remove backup "%s" from flysystem destination.', $name), 0, $e); |
||
64 | } |
||
65 | |||
66 | if (!is_null($this->backups)) { |
||
67 | unset($this->backups[$name]); |
||
68 | } |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | public function all() |
||
82 | |||
83 | /** |
||
84 | * {@inheritdoc} |
||
85 | */ |
||
86 | public function getIterator() |
||
94 | |||
95 | /** |
||
96 | * Load backups from destination. |
||
97 | * |
||
98 | * @return BackupInterface[] |
||
99 | */ |
||
100 | protected function load() |
||
128 | |||
129 | /** |
||
130 | * {@inheritdoc} |
||
131 | */ |
||
132 | public function count() |
||
136 | } |
||
137 |