1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CloudControl\Cms\storage { |
4
|
|
|
|
5
|
|
|
use CloudControl\Cms\storage\storage\ActivityLogStorage; |
6
|
|
|
use CloudControl\Cms\storage\storage\ApplicationComponentsStorage; |
7
|
|
|
use CloudControl\Cms\storage\storage\BricksStorage; |
8
|
|
|
use CloudControl\Cms\storage\storage\DocumentStorage; |
9
|
|
|
use CloudControl\Cms\storage\storage\DocumentTypesStorage; |
10
|
|
|
use CloudControl\Cms\storage\storage\FilesStorage; |
11
|
|
|
use CloudControl\Cms\storage\storage\ImageSetStorage; |
12
|
|
|
use CloudControl\Cms\storage\storage\ImagesStorage; |
13
|
|
|
use CloudControl\Cms\storage\storage\RedirectsStorage; |
14
|
|
|
use CloudControl\Cms\storage\storage\SitemapStorage; |
15
|
|
|
use CloudControl\Cms\storage\storage\UsersStorage; |
16
|
|
|
use CloudControl\Cms\storage\storage\ValuelistsStorage; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class JsonStorage |
20
|
|
|
* @package CloudControl\Cms\storage |
21
|
|
|
*/ |
22
|
|
|
class Storage |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var SitemapStorage |
26
|
|
|
*/ |
27
|
|
|
protected $sitemap; |
28
|
|
|
/** |
29
|
|
|
* @var ImagesStorage |
30
|
|
|
*/ |
31
|
|
|
protected $images; |
32
|
|
|
/** |
33
|
|
|
* @var ImageSetStorage |
34
|
|
|
*/ |
35
|
|
|
protected $imageSet; |
36
|
|
|
/** |
37
|
|
|
* @var FilesStorage |
38
|
|
|
*/ |
39
|
|
|
protected $files; |
40
|
|
|
/** |
41
|
|
|
* @var UsersStorage |
42
|
|
|
*/ |
43
|
|
|
protected $users; |
44
|
|
|
/** |
45
|
|
|
* @var DocumentTypesStorage |
46
|
|
|
*/ |
47
|
|
|
protected $documentTypes; |
48
|
|
|
/** |
49
|
|
|
* @var BricksStorage |
50
|
|
|
*/ |
51
|
|
|
protected $bricks; |
52
|
|
|
/** |
53
|
|
|
* @var ApplicationComponentsStorage |
54
|
|
|
*/ |
55
|
|
|
protected $applicationComponents; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var ValuelistsStorage |
59
|
|
|
*/ |
60
|
|
|
protected $valuelists; |
61
|
|
|
/** |
62
|
|
|
* @var DocumentStorage |
63
|
|
|
*/ |
64
|
|
|
protected $documents; |
65
|
|
|
/** |
66
|
|
|
* @var RedirectsStorage |
67
|
|
|
*/ |
68
|
|
|
protected $redirects; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var ActivityLogStorage |
72
|
|
|
*/ |
73
|
|
|
protected $activityLog; |
74
|
|
|
/** |
75
|
|
|
* @var String |
76
|
|
|
*/ |
77
|
|
|
protected $imagesDir; |
78
|
|
|
/** |
79
|
|
|
* @var String |
80
|
|
|
*/ |
81
|
|
|
protected $filesDir; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @var String |
85
|
|
|
*/ |
86
|
|
|
private $storageDir; |
87
|
|
|
/** |
88
|
|
|
* @var Repository |
89
|
|
|
*/ |
90
|
|
|
private $repository; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* JsonStorage constructor. |
94
|
|
|
* |
95
|
|
|
* @param string $storageDir |
96
|
|
|
* @param $imagesDir |
97
|
|
|
* @param $filesDir |
98
|
|
|
*/ |
99
|
|
|
public function __construct($storageDir, $imagesDir, $filesDir) |
100
|
|
|
{ |
101
|
|
|
$this->storageDir = $storageDir; |
102
|
|
|
$this->imagesDir = $imagesDir; |
103
|
|
|
$this->filesDir = $filesDir; |
104
|
|
|
$this->config(); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Retrieve the data from the storagepath |
109
|
|
|
* so it can be interacted with |
110
|
|
|
* |
111
|
|
|
* @throws \Exception |
112
|
|
|
*/ |
113
|
|
|
private function config() |
114
|
|
|
{ |
115
|
|
|
$storagePath = $this->storageDir; |
116
|
|
|
if (realpath($storagePath) === false) { |
117
|
|
|
throw new \Exception('Storage doesnt seem to be initialized, consider running composer install to do so.'); |
118
|
|
|
} else { |
119
|
|
|
$this->repository = new Repository($storagePath); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return \CloudControl\Cms\storage\storage\UsersStorage |
126
|
|
|
*/ |
127
|
|
|
public function getUsers() |
128
|
|
|
{ |
129
|
|
|
if (!$this->users instanceof UsersStorage) { |
130
|
|
|
$this->users = new UsersStorage($this->repository); |
131
|
|
|
} |
132
|
|
|
return $this->users; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Get documents |
137
|
|
|
* |
138
|
|
|
* @return DocumentStorage |
139
|
|
|
*/ |
140
|
|
|
public function getDocuments() |
141
|
|
|
{ |
142
|
|
|
if (!$this->documents instanceof DocumentStorage) { |
143
|
|
|
$this->documents = new DocumentStorage($this->repository); |
144
|
|
|
} |
145
|
|
|
return $this->documents; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @return SitemapStorage |
150
|
|
|
*/ |
151
|
|
|
public function getSitemap() |
152
|
|
|
{ |
153
|
|
|
if (!$this->sitemap instanceof SitemapStorage) { |
154
|
|
|
$this->sitemap = new SitemapStorage($this->repository); |
155
|
|
|
} |
156
|
|
|
return $this->sitemap; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Get all images |
161
|
|
|
* |
162
|
|
|
* @return ImagesStorage |
163
|
|
|
*/ |
164
|
|
|
public function getImages() |
165
|
|
|
{ |
166
|
|
|
if (!$this->images instanceof ImagesStorage) { |
167
|
|
|
|
168
|
|
|
$this->images = new ImagesStorage($this->repository, $this->imagesDir); |
169
|
|
|
} |
170
|
|
|
return $this->images; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Get all files |
175
|
|
|
* |
176
|
|
|
* @return FilesStorage |
177
|
|
|
*/ |
178
|
|
|
public function getFiles() |
179
|
|
|
{ |
180
|
|
|
if (!$this->files instanceof FilesStorage) { |
181
|
|
|
$this->files = new FilesStorage($this->repository, $this->filesDir); |
182
|
|
|
} |
183
|
|
|
return $this->files; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @return string |
188
|
|
|
*/ |
189
|
|
|
public function getStorageDir() |
190
|
|
|
{ |
191
|
|
|
return $this->storageDir; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @return \PDO |
196
|
|
|
*/ |
197
|
|
|
public function getContentDbHandle() |
198
|
|
|
{ |
199
|
|
|
return $this->repository->getContentRepository()->getContentDbHandle(); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @return DocumentTypesStorage |
204
|
|
|
*/ |
205
|
|
|
public function getDocumentTypes() |
206
|
|
|
{ |
207
|
|
|
if (!$this->documentTypes instanceof DocumentTypesStorage) { |
208
|
|
|
$this->documentTypes = new DocumentTypesStorage($this->repository); |
209
|
|
|
} |
210
|
|
|
return $this->documentTypes; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* @return BricksStorage |
215
|
|
|
*/ |
216
|
|
View Code Duplication |
public function getBricks() |
|
|
|
|
217
|
|
|
{ |
218
|
|
|
if (!$this->bricks instanceof BricksStorage) { |
219
|
|
|
$this->bricks = new BricksStorage($this->repository); |
220
|
|
|
} |
221
|
|
|
return $this->bricks; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* Get the image set |
226
|
|
|
* |
227
|
|
|
* @return ImageSetStorage |
228
|
|
|
*/ |
229
|
|
View Code Duplication |
public function getImageSet() |
|
|
|
|
230
|
|
|
{ |
231
|
|
|
if (!$this->imageSet instanceof ImageSetStorage) { |
232
|
|
|
$this->imageSet = new ImageSetStorage($this->repository); |
233
|
|
|
} |
234
|
|
|
return $this->imageSet; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @return ApplicationComponentsStorage |
239
|
|
|
*/ |
240
|
|
|
public function getApplicationComponents() |
241
|
|
|
{ |
242
|
|
|
if (!$this->applicationComponents instanceof ApplicationComponentsStorage) { |
243
|
|
|
$this->applicationComponents = new ApplicationComponentsStorage($this->repository); |
244
|
|
|
} |
245
|
|
|
return $this->applicationComponents; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* @return \CloudControl\Cms\storage\Repository |
250
|
|
|
*/ |
251
|
|
|
public function getRepository() |
252
|
|
|
{ |
253
|
|
|
return $this->repository; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* @return \CloudControl\Cms\storage\storage\ValuelistsStorage |
258
|
|
|
*/ |
259
|
|
|
public function getValuelists() |
260
|
|
|
{ |
261
|
|
|
if (!$this->valuelists instanceof ValuelistsStorage) { |
262
|
|
|
$this->valuelists = new ValuelistsStorage($this->repository); |
263
|
|
|
} |
264
|
|
|
return $this->valuelists; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* @return \CloudControl\Cms\storage\storage\RedirectsStorage |
269
|
|
|
*/ |
270
|
|
|
public function getRedirects() |
271
|
|
|
{ |
272
|
|
|
if (!$this->redirects instanceof RedirectsStorage) { |
273
|
|
|
$this->redirects = new RedirectsStorage($this->repository); |
274
|
|
|
} |
275
|
|
|
return $this->redirects; |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* @return ActivityLogStorage |
280
|
|
|
*/ |
281
|
|
|
public function getActivityLog() |
282
|
|
|
{ |
283
|
|
|
if (!$this->activityLog instanceof ActivityLogStorage) { |
284
|
|
|
$this->activityLog = new ActivityLogStorage($this->repository); |
285
|
|
|
} |
286
|
|
|
return $this->activityLog; |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
|
290
|
|
|
} |
291
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.