/
Application.php
100 lines (94 loc) · 2.53 KB
/
Application.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* Copyright 2017 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (BSD). If you
* did not receive this file, see http://www.horde.org/licenses/bsd.
*
* @author Jan Schneider <jan@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/bsd BSD
* @package Backup
* @subpackage UnitTests
*/
namespace Horde\Backup\Stub;
use ArrayIterator;
use Horde\Backup\Collection;
use Horde\Backup\User;
use Horde\Backup\Users;
/**
* Horde_Registry_Application stub.
*
* @author Jan Schneider <jan@horde.org>
* @category Horde
* @copyright 2017 Horde LLC
* @license http://www.horde.org/licenses/bsd BSD
* @package Backup
* @subpackage UnitTests
*/
class Application
{
public $userData = array(
'john' => array(
'calendars' => array(
array(
'id' => 'id1',
'name' => 'Calendar 1',
'desc' => 'The first calendar.'
),
array(
'id' => 'id2',
'name' => 'Calendar 2',
'desc' => 'The second calendar.'
),
),
'events' => array(
array(
'id' => 'event1',
'name' => 'John\'s Event',
'calendar' => 'id1'
)
)
),
'jane' => array(
'events' => array(
array(
'id' => 'event2',
'name' => 'Jane\'s Event',
'calendar' => 'id1'
)
)
)
);
public function backup(array $users = array())
{
if (!$users) {
$users = array_keys($this->userData);
}
return new Users(
new ArrayIterator($users),
array($this, 'getUserBackup')
);
}
public function getUserBackup($user)
{
$backup = new User($user);
foreach ($this->userData[$user] as $type => $data) {
$backup->collections[] = new Collection(
new ArrayIterator($data), $user, $type
);
}
return $backup;
}
public function restore(Collection $data)
{
foreach ($data as $backup) {
foreach ($this->userData[$data->getUser()][$data->getType()] as $original) {
if ($original == $backup) {
return true;
}
}
}
return false;
}
}