Storage::getStorageDir()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
         * @throws \Exception
99
         */
100
        public function __construct($storageDir, $imagesDir, $filesDir)
101
        {
102
            $this->storageDir = $storageDir;
103
            $this->imagesDir = $imagesDir;
104
            $this->filesDir = $filesDir;
105
            $this->config();
106
        }
107
108
        /**
109
         * Retrieve the data from the storagepath
110
         * so it can be interacted with
111
         *
112
         * @throws \Exception
113
         */
114
        private function config()
115
        {
116
            $storagePath = $this->storageDir;
117
            if (realpath($storagePath) === false) {
118
                throw new \Exception('Storage doesnt seem to be initialized, consider running composer install to do so. Current given storagePath: "' . $storagePath . '"');
119
            } else {
120
                $this->repository = new Repository($storagePath);
121
            }
122
123
        }
124
125
        /**
126
         * @return \CloudControl\Cms\storage\storage\UsersStorage
127
         */
128
        public function getUsers()
129
        {
130
            if (!$this->users instanceof UsersStorage) {
0 ignored issues
show
introduced by
$this->users is always a sub-type of CloudControl\Cms\storage\storage\UsersStorage.
Loading history...
131
                $this->users = new UsersStorage($this->repository);
132
            }
133
            return $this->users;
134
        }
135
136
        /**
137
         * Get documents
138
         *
139
         * @return DocumentStorage
140
         */
141
        public function getDocuments()
142
        {
143
            if (!$this->documents instanceof DocumentStorage) {
0 ignored issues
show
introduced by
$this->documents is always a sub-type of CloudControl\Cms\storage\storage\DocumentStorage.
Loading history...
144
                $this->documents = new DocumentStorage($this->repository);
145
            }
146
            return $this->documents;
147
        }
148
149
        /**
150
         * @return SitemapStorage
151
         */
152
        public function getSitemap()
153
        {
154
            if (!$this->sitemap instanceof SitemapStorage) {
0 ignored issues
show
introduced by
$this->sitemap is always a sub-type of CloudControl\Cms\storage\storage\SitemapStorage.
Loading history...
155
                $this->sitemap = new SitemapStorage($this->repository);
156
            }
157
            return $this->sitemap;
158
        }
159
160
        /**
161
         * Get all images
162
         *
163
         * @return ImagesStorage
164
         */
165
        public function getImages()
166
        {
167
            if (!$this->images instanceof ImagesStorage) {
0 ignored issues
show
introduced by
$this->images is always a sub-type of CloudControl\Cms\storage\storage\ImagesStorage.
Loading history...
168
169
                $this->images = new ImagesStorage($this->repository, $this->imagesDir);
170
            }
171
            return $this->images;
172
        }
173
174
        /**
175
         * Get all files
176
         *
177
         * @return FilesStorage
178
         */
179
        public function getFiles()
180
        {
181
            if (!$this->files instanceof FilesStorage) {
0 ignored issues
show
introduced by
$this->files is always a sub-type of CloudControl\Cms\storage\storage\FilesStorage.
Loading history...
182
                $this->files = new FilesStorage($this->repository, $this->filesDir);
183
            }
184
            return $this->files;
185
        }
186
187
        /**
188
         * @return string
189
         */
190
        public function getStorageDir()
191
        {
192
            return $this->storageDir;
193
        }
194
195
        /**
196
         * @return \PDO
197
         */
198
        public function getContentDbHandle()
199
        {
200
            return $this->repository->getContentRepository()->getContentDbHandle();
201
        }
202
203
        /**
204
         * @return DocumentTypesStorage
205
         */
206
        public function getDocumentTypes()
207
        {
208
            if (!$this->documentTypes instanceof DocumentTypesStorage) {
0 ignored issues
show
introduced by
$this->documentTypes is always a sub-type of CloudControl\Cms\storage...ge\DocumentTypesStorage.
Loading history...
209
                $this->documentTypes = new DocumentTypesStorage($this->repository);
210
            }
211
            return $this->documentTypes;
212
        }
213
214
        /**
215
         * @return BricksStorage
216
         */
217
        public function getBricks()
218
        {
219
            if (!$this->bricks instanceof BricksStorage) {
0 ignored issues
show
introduced by
$this->bricks is always a sub-type of CloudControl\Cms\storage\storage\BricksStorage.
Loading history...
220
                $this->bricks = new BricksStorage($this->repository);
221
            }
222
            return $this->bricks;
223
        }
224
225
        /**
226
         * Get the image set
227
         *
228
         * @return ImageSetStorage
229
         */
230
        public function getImageSet()
231
        {
232
            if (!$this->imageSet instanceof ImageSetStorage) {
0 ignored issues
show
introduced by
$this->imageSet is always a sub-type of CloudControl\Cms\storage\storage\ImageSetStorage.
Loading history...
233
                $this->imageSet = new ImageSetStorage($this->repository);
234
            }
235
            return $this->imageSet;
236
        }
237
238
        /**
239
         * @return ApplicationComponentsStorage
240
         */
241
        public function getApplicationComponents()
242
        {
243
            if (!$this->applicationComponents instanceof ApplicationComponentsStorage) {
0 ignored issues
show
introduced by
$this->applicationComponents is always a sub-type of CloudControl\Cms\storage...cationComponentsStorage.
Loading history...
244
                $this->applicationComponents = new ApplicationComponentsStorage($this->repository);
245
            }
246
            return $this->applicationComponents;
247
        }
248
249
        /**
250
         * @return \CloudControl\Cms\storage\Repository
251
         */
252
        public function getRepository()
253
        {
254
            return $this->repository;
255
        }
256
257
        /**
258
         * @return \CloudControl\Cms\storage\storage\ValuelistsStorage
259
         */
260
        public function getValuelists()
261
        {
262
            if (!$this->valuelists instanceof ValuelistsStorage) {
0 ignored issues
show
introduced by
$this->valuelists is always a sub-type of CloudControl\Cms\storage\storage\ValuelistsStorage.
Loading history...
263
                $this->valuelists = new ValuelistsStorage($this->repository);
264
            }
265
            return $this->valuelists;
266
        }
267
268
        /**
269
         * @return \CloudControl\Cms\storage\storage\RedirectsStorage
270
         */
271
        public function getRedirects()
272
        {
273
            if (!$this->redirects instanceof RedirectsStorage) {
0 ignored issues
show
introduced by
$this->redirects is always a sub-type of CloudControl\Cms\storage\storage\RedirectsStorage.
Loading history...
274
                $this->redirects = new RedirectsStorage($this->repository);
275
            }
276
            return $this->redirects;
277
        }
278
279
        /**
280
         * @return ActivityLogStorage
281
         */
282
        public function getActivityLog()
283
        {
284
            if (!$this->activityLog instanceof ActivityLogStorage) {
0 ignored issues
show
introduced by
$this->activityLog is always a sub-type of CloudControl\Cms\storage...rage\ActivityLogStorage.
Loading history...
285
                $this->activityLog = new ActivityLogStorage($this->repository);
286
            }
287
            return $this->activityLog;
288
        }
289
290
291
    }
292
}