forked from netgen/ezplatform-site-api
/
Repository.php
208 lines (170 loc) · 5.65 KB
/
Repository.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
namespace Netgen\EzPlatformSiteApi\Core\Repository\Aggregate;
use eZ\Publish\API\Repository\Repository as RepositoryInterface;
use eZ\Publish\API\Repository\Values\ValueObject;
use eZ\Publish\API\Repository\Values\User\UserReference;
use Closure;
use RuntimeException;
/**
* Aggregate implementation of Repository interface.
*
* When current Repository User is changed, any custom instance of Repository will not be updated.
* This implementation takes care of it by aggregating custom instances to update current User when
* necessary. For that to work, it must be registered as the top one, meaning that service alias
* 'ezpublish.api.repository' must point to it. This is taken care of by AggregateRepositoryPass.
*
* @see \Netgen\Bundle\EzPlatformSiteApiBundle\DependencyInjection\Compiler\AggregateRepositoryPass
*/
class Repository implements RepositoryInterface
{
/**
* @var \eZ\Publish\API\Repository\Repository
*/
private $ezRepository;
/**
* @var \eZ\Publish\API\Repository\Repository[]
*/
private $customRepositories;
/**
* Construct repository object from top eZ Platform Repository and
* an array of custom Repositories
*
* @param \eZ\Publish\API\Repository\Repository $ezRepository
* @param \eZ\Publish\API\Repository\Repository[] $customRepositories
*/
public function __construct(
RepositoryInterface $ezRepository,
array $customRepositories = []
) {
$this->ezRepository = $ezRepository;
$this->customRepositories = $customRepositories;
}
public function getCurrentUser()
{
return $this->ezRepository->getCurrentUser();
}
public function getCurrentUserReference()
{
return $this->ezRepository->getCurrentUserReference();
}
public function setCurrentUser(UserReference $user)
{
foreach ($this->customRepositories as $customRepository) {
$customRepository->setCurrentUser($user);
}
return $this->ezRepository->setCurrentUser($user);
}
public function sudo(Closure $callback)
{
return $this->ezRepository->sudo($callback, $this);
}
public function hasAccess($module, $function, UserReference $user = null)
{
return $this->ezRepository->hasAccess($module, $function, $user);
}
public function canUser($module, $function, ValueObject $object, $targets = null)
{
return $this->ezRepository->canUser($module, $function, $object, $targets);
}
public function getBookmarkService()
{
if (!method_exists($this->ezRepository, 'getBookmarkService')) {
throw new RuntimeException(sprintf('getBookmarkService method does not exist in %s class', get_class($this->ezRepository)));
}
return $this->ezRepository->getBookmarkService();
}
public function getNotificationService()
{
if (!method_exists($this->ezRepository, 'getNotificationService')) {
throw new RuntimeException(sprintf('getNotificationService method does not exist in %s class', get_class($this->ezRepository)));
}
return $this->ezRepository->getNotificationService();
}
public function getUserPreferenceService()
{
if (!method_exists($this->ezRepository, 'getUserPreferenceService')) {
throw new RuntimeException(sprintf('getUserPreferenceService method does not exist in %s class', get_class($this->ezRepository)));
}
return $this->ezRepository->getUserPreferenceService();
}
public function getContentService()
{
return $this->ezRepository->getContentService();
}
public function getContentLanguageService()
{
return $this->ezRepository->getContentLanguageService();
}
public function getContentTypeService()
{
return $this->ezRepository->getContentTypeService();
}
public function getLocationService()
{
return $this->ezRepository->getLocationService();
}
public function getTrashService()
{
return $this->ezRepository->getTrashService();
}
public function getSectionService()
{
return $this->ezRepository->getSectionService();
}
public function getUserService()
{
return $this->ezRepository->getUserService();
}
public function getURLAliasService()
{
return $this->ezRepository->getURLAliasService();
}
public function getURLWildcardService()
{
return $this->ezRepository->getURLWildcardService();
}
public function getObjectStateService()
{
return $this->ezRepository->getObjectStateService();
}
public function getRoleService()
{
return $this->ezRepository->getRoleService();
}
public function getSearchService()
{
return $this->ezRepository->getSearchService();
}
public function getFieldTypeService()
{
return $this->ezRepository->getFieldTypeService();
}
public function getURLService()
{
return $this->ezRepository->getURLService();
}
public function getPermissionResolver()
{
return $this->ezRepository->getPermissionResolver();
}
public function beginTransaction()
{
return $this->ezRepository->beginTransaction();
}
public function commit()
{
return $this->ezRepository->commit();
}
public function rollback()
{
return $this->ezRepository->rollback();
}
public function commitEvent($event)
{
return $this->ezRepository->commitEvent($event);
}
public function createDateTime($timestamp = null)
{
return $this->ezRepository->createDateTime($timestamp);
}
}