Passed
Push — develop ( 7ee7eb...278ae4 )
by Jens
02:44
created
cloudcontrol/library/storage/JsonStorage.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -892,6 +892,9 @@
 block discarded – undo
892 892
 			}
893 893
 		}
894 894
 
895
+		/**
896
+		 * @param string $path
897
+		 */
895 898
 		private function validateFilename($filename, $path)
896 899
 		{
897 900
 			$fileParts = explode('.', $filename);
Please login to merge, or discard this patch.
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -121,9 +121,9 @@  discard block
 block discarded – undo
121 121
 			if (!empty($doesItExist)) {
122 122
 				throw new \Exception('Trying to add username that already exists.');
123 123
 			}
124
-            $users = $this->repository->users;
125
-            $users[] = $userObj;
126
-            $this->repository->users = $users;
124
+			$users = $this->repository->users;
125
+			$users[] = $userObj;
126
+			$this->repository->users = $users;
127 127
 			$this->save();
128 128
 		}
129 129
 
@@ -795,9 +795,9 @@  discard block
 block discarded – undo
795 795
 				$imageObject->size = $postValues['size'];
796 796
 				$imageObject->set = $fileNames;
797 797
 
798
-                $images = $this->repository->images;
798
+				$images = $this->repository->images;
799 799
 				$images[] = $imageObject;
800
-                $this->repository->images = $images;
800
+				$this->repository->images = $images;
801 801
 
802 802
 				$this->save();
803 803
 			} else {
@@ -832,7 +832,7 @@  discard block
 block discarded – undo
832 832
 		/**
833 833
 		 * @param $filename
834 834
 		 * @return null
835
-         */
835
+		 */
836 836
 		public function getImageByName($filename)
837 837
 		{
838 838
 			$images = $this->getImages();
@@ -883,9 +883,9 @@  discard block
 block discarded – undo
883 883
 				$file->type = $postValues['type'];
884 884
 				$file->size = $postValues['size'];
885 885
 
886
-                $files = $this->repository->files;
886
+				$files = $this->repository->files;
887 887
 				$files[] = $file;
888
-                $this->repository->files = $files;
888
+				$this->repository->files = $files;
889 889
 				$this->save();
890 890
 			} else {
891 891
 				throw new \Exception('Error moving uploaded file');
@@ -924,7 +924,7 @@  discard block
 block discarded – undo
924 924
 		/**
925 925
 		 * @param $filename
926 926
 		 * @return null
927
-         */
927
+		 */
928 928
 		public function getFileByName($filename)
929 929
 		{
930 930
 			$files = $this->getFiles();
@@ -939,7 +939,7 @@  discard block
 block discarded – undo
939 939
 		/**
940 940
 		 * @param $filename
941 941
 		 * @throws \Exception
942
-         */
942
+		 */
943 943
 		public function deleteFileByName($filename)
944 944
 		{
945 945
 			$destinationPath = realpath(__DIR__ . '/../../www/files/');
@@ -984,9 +984,9 @@  discard block
 block discarded – undo
984 984
 		{
985 985
 			$documentTypeObject = $this->createDocumentTypeFromPostValues($postValues);
986 986
 
987
-            $documentTypes = $this->repository->documentTypes;
988
-            $documentTypes[] = $documentTypeObject;
989
-            $this->repository->documentTypes = $documentTypes;
987
+			$documentTypes = $this->repository->documentTypes;
988
+			$documentTypes[] = $documentTypeObject;
989
+			$this->repository->documentTypes = $documentTypes;
990 990
 
991 991
 			$this->save();
992 992
 		}
@@ -1132,9 +1132,9 @@  discard block
 block discarded – undo
1132 1132
 		{
1133 1133
 			$brickObject = $this->createBrickFromPostValues($postValues);
1134 1134
 
1135
-            $bricks = $this->repository->bricks;
1136
-            $bricks[] = $brickObject;
1137
-            $this->repository->bricks = $bricks;
1135
+			$bricks = $this->repository->bricks;
1136
+			$bricks[] = $brickObject;
1137
+			$this->repository->bricks = $bricks;
1138 1138
 
1139 1139
 			$this->save();
1140 1140
 		}
@@ -1339,9 +1339,9 @@  discard block
 block discarded – undo
1339 1339
 		{
1340 1340
 			$imageSetObject = $this->createImageSetFromPostValues($postValues);
1341 1341
 
1342
-            $imageSet = $this->repository->imageSet;
1343
-            $imageSet[] = $imageSetObject;
1344
-            $this->repository->imageSet = $imageSet;
1342
+			$imageSet = $this->repository->imageSet;
1343
+			$imageSet[] = $imageSetObject;
1344
+			$this->repository->imageSet = $imageSet;
1345 1345
 
1346 1346
 			$this->save();
1347 1347
 		}
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 		 */
34 34
 		private function config()
35 35
 		{
36
-			$storagePath = __DIR__ . '/../../' . $this->storageDir;
36
+			$storagePath = __DIR__.'/../../'.$this->storageDir;
37 37
 			if (realpath($storagePath) === false) {
38 38
 				initFramework($storagePath);
39 39
 				if (Repository::create($storagePath)) {
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 					$repository->init();
42 42
 					$this->repository = $repository;
43 43
 				} else {
44
-					throw new \Exception('Could not create repository directory: ' . $storagePath);
44
+					throw new \Exception('Could not create repository directory: '.$storagePath);
45 45
 				}
46 46
 			} else {
47 47
 				$this->repository = new Repository($storagePath);
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 		 */
192 192
 		public function getDocumentBySlug($slug)
193 193
 		{
194
-			$documentContainer = $this->getDocumentContainerByPath('/' . $slug);
194
+			$documentContainer = $this->getDocumentContainerByPath('/'.$slug);
195 195
 			$indices = $documentContainer['indices'];
196 196
 
197 197
 			if ($indices === null) {
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
 				// Check for duplicates
237 237
 				foreach ($this->repository->documents as $index => $document) {
238 238
 					if (end($indices) !== $index && $document->slug == $documentFolderObject->slug && $document->type == 'document') {
239
-						throw new \Exception('Duplicate slug: ' . $document->slug . ' in folder ' . $postValues['path']);
239
+						throw new \Exception('Duplicate slug: '.$document->slug.' in folder '.$postValues['path']);
240 240
 					}
241 241
 				}
242 242
 				$this->repository->documents[end($indices)] = $documentFolderObject;
@@ -244,10 +244,10 @@  discard block
 block discarded – undo
244 244
 				// Check for duplicates
245 245
 				foreach ($previousFolder->content as $index => $document) {
246 246
 					if (end($indices) !== $index && $document->slug == $documentFolderObject->slug && $document->type == 'document') {
247
-						throw new \Exception('Duplicate slug: ' . $document->slug . ' in folder ' . $postValues['path']);
247
+						throw new \Exception('Duplicate slug: '.$document->slug.' in folder '.$postValues['path']);
248 248
 					}
249 249
 				}
250
-				$previousFolder->content[end($indices)] = $documentFolderObject ;
250
+				$previousFolder->content[end($indices)] = $documentFolderObject;
251 251
 			}
252 252
 
253 253
 			$this->save();
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 				foreach ($this->repository->documents as $document) {
262 262
 					if ($document->slug == $documentFolderObject->slug && $document->type == 'document') {
263 263
 						// TODO make it so it doesnt throw an exception, but instead shows a warning
264
-						throw new \Exception('Duplicate slug: ' . $document->slug . ' in folder ' . $postValues['path']);
264
+						throw new \Exception('Duplicate slug: '.$document->slug.' in folder '.$postValues['path']);
265 265
 					}
266 266
 				}
267 267
 				$this->repository->documents[] = $documentFolderObject;
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 					foreach ($containerFolder->content as $document) {
273 273
 						if ($document->slug == $documentFolderObject->slug && $document->type == 'document') {
274 274
 							// TODO make it so it doesnt throw an exception, but instead shows a warning
275
-							throw new \Exception('Duplicate slug: ' . $document->slug . ' in folder ' . $postValues['path']);
275
+							throw new \Exception('Duplicate slug: '.$document->slug.' in folder '.$postValues['path']);
276 276
 						}
277 277
 					}
278 278
 				}
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
 				foreach ($this->repository->documents as $document) {
391 391
 					if ($document->slug == $documentFolderObject->slug && $document->type == 'folder') {
392 392
 						// TODO make it so it doesnt throw an exception, but instead shows a warning
393
-						throw new \Exception('Duplicate slug: ' . $document->slug . ' in folder ' . $postValues['path']);
393
+						throw new \Exception('Duplicate slug: '.$document->slug.' in folder '.$postValues['path']);
394 394
 					}
395 395
 				}
396 396
 				$this->repository->documents[] = $documentFolderObject;
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
 				foreach ($containerFolder->content as $document) {
412 412
 					if ($document->slug == $documentFolderObject->slug && $document->type == 'folder') {
413 413
 						// TODO make it so it doesnt throw an exception, but instead shows a warning
414
-						throw new \Exception('Duplicate slug: ' . $document->slug . ' in folder ' . $postValues['path']);
414
+						throw new \Exception('Duplicate slug: '.$document->slug.' in folder '.$postValues['path']);
415 415
 					}
416 416
 				}
417 417
 				$folder->content[] = $documentFolderObject;
@@ -463,12 +463,12 @@  discard block
 block discarded – undo
463 463
 		 */
464 464
 		public function getDocumentFolderBySlug($slug)
465 465
 		{
466
-			$documentContainer = $this->getDocumentContainerByPath('/' . $slug);
466
+			$documentContainer = $this->getDocumentContainerByPath('/'.$slug);
467 467
 			$indices = $documentContainer['indices'];
468 468
 
469 469
 			$folder = $this->repository->documents;
470 470
 			if ($indices === null) {
471
-				throw new \Exception('Can\'t find folder with slug `' . $slug . '`');
471
+				throw new \Exception('Can\'t find folder with slug `'.$slug.'`');
472 472
 			}
473 473
 			foreach ($indices as $index) {
474 474
 				if ($folder === $this->repository->documents) {
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
 				// Check for duplicates
511 511
 				foreach ($this->repository->documents as $index => $document) {
512 512
 					if (end($indices) !== $index && $document->slug == $documentFolderObject->slug && $document->type == 'folder') {
513
-						throw new \Exception('Duplicate slug: ' . $document->slug . ' in folder ' . $postValues['path']);
513
+						throw new \Exception('Duplicate slug: '.$document->slug.' in folder '.$postValues['path']);
514 514
 					}
515 515
 				}
516 516
 				$this->repository->documents[end($indices)] = $documentFolderObject;
@@ -518,10 +518,10 @@  discard block
 block discarded – undo
518 518
 				// Check for duplicates
519 519
 				foreach ($previousFolder->content as $index => $document) {
520 520
 					if (end($indices) !== $index && $document->slug == $documentFolderObject->slug && $document->type == 'folder') {
521
-						throw new \Exception('Duplicate slug: ' . $document->slug . ' in folder ' . $postValues['path']);
521
+						throw new \Exception('Duplicate slug: '.$document->slug.' in folder '.$postValues['path']);
522 522
 					}
523 523
 				}
524
-				$previousFolder->content[end($indices)] = $documentFolderObject ;
524
+				$previousFolder->content[end($indices)] = $documentFolderObject;
525 525
 			}
526 526
 
527 527
 			$this->save();
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
 					'previousDocument' => $previousDocument
591 591
 				);
592 592
 			} else {
593
-				throw new \Exception('Invalid path: ' . $path);
593
+				throw new \Exception('Invalid path: '.$path);
594 594
 			}
595 595
 		}
596 596
 
@@ -776,13 +776,13 @@  discard block
 block discarded – undo
776 776
 
777 777
 		public function addImage($postValues)
778 778
 		{
779
-			$destinationPath = realpath(__DIR__ . '/../../www/images/');
779
+			$destinationPath = realpath(__DIR__.'/../../www/images/');
780 780
 
781 781
 			$filename = $this->validateFilename($postValues['name'], $destinationPath);
782
-			$destination = $destinationPath . '/' . $filename;
782
+			$destination = $destinationPath.'/'.$filename;
783 783
 
784 784
 			if ($postValues['error'] != '0') {
785
-				throw new \Exception('Error uploading file. Error code: ' . $postValues['error']);
785
+				throw new \Exception('Error uploading file. Error code: '.$postValues['error']);
786 786
 			}
787 787
 
788 788
 			if (move_uploaded_file($postValues['tmp_name'], $destination)) {
@@ -807,14 +807,14 @@  discard block
 block discarded – undo
807 807
 
808 808
 		public function deleteImageByName($filename)
809 809
 		{
810
-			$destinationPath = realpath(__DIR__ . '/../../www/images/');
810
+			$destinationPath = realpath(__DIR__.'/../../www/images/');
811 811
 
812 812
 			$images = $this->getImages();
813 813
 
814 814
 			foreach ($images as $key => $image) {
815 815
 				if ($image->file == $filename) {
816 816
 					foreach ($image->set as $imageSetFilename) {
817
-						$destination = $destinationPath . '/' . $imageSetFilename;
817
+						$destination = $destinationPath.'/'.$imageSetFilename;
818 818
 						if (file_exists($destination)) {
819 819
 							unlink($destination);
820 820
 						} else {
@@ -856,7 +856,7 @@  discard block
 block discarded – undo
856 856
 		 */
857 857
 		public function getFiles()
858 858
 		{
859
-			$files =  $this->repository->files;
859
+			$files = $this->repository->files;
860 860
 			usort($files, array($this, 'compareFiles'));
861 861
 			return $files;
862 862
 		}
@@ -868,13 +868,13 @@  discard block
 block discarded – undo
868 868
 
869 869
 		public function addFile($postValues)
870 870
 		{
871
-			$destinationPath = realpath(__DIR__ . '/../../www/files/');
871
+			$destinationPath = realpath(__DIR__.'/../../www/files/');
872 872
 
873 873
 			$filename = $this->validateFilename($postValues['name'], $destinationPath);
874
-			$destination = $destinationPath . '/' . $filename;
874
+			$destination = $destinationPath.'/'.$filename;
875 875
 
876 876
 			if ($postValues['error'] != '0') {
877
-				throw new \Exception('Error uploading file. Error code: ' . $postValues['error']);
877
+				throw new \Exception('Error uploading file. Error code: '.$postValues['error']);
878 878
 			}
879 879
 
880 880
 			if (move_uploaded_file($postValues['tmp_name'], $destination)) {
@@ -900,23 +900,23 @@  discard block
 block discarded – undo
900 900
 				array_pop($fileParts);
901 901
 				$fileNameWithoutExtension = implode('-', $fileParts);
902 902
 				$fileNameWithoutExtension = slugify($fileNameWithoutExtension);
903
-				$filename = $fileNameWithoutExtension . '.' . $extension;
903
+				$filename = $fileNameWithoutExtension.'.'.$extension;
904 904
 			} else {
905 905
 				$filename = slugify($filename);
906 906
 			}
907 907
 
908
-			if (file_exists($path . '/' . $filename)) {
908
+			if (file_exists($path.'/'.$filename)) {
909 909
 				$fileParts = explode('.', $filename);
910 910
 				if (count($fileParts) > 1) {
911 911
 					$extension = end($fileParts);
912 912
 					array_pop($fileParts);
913 913
 					$fileNameWithoutExtension = implode('-', $fileParts);
914 914
 					$fileNameWithoutExtension .= '-copy';
915
-					$filename = $fileNameWithoutExtension . '.' . $extension;
915
+					$filename = $fileNameWithoutExtension.'.'.$extension;
916 916
 				} else {
917 917
 					$filename .= '-copy';
918 918
 				}
919
-				return $this->validateFilename($filename,$path);
919
+				return $this->validateFilename($filename, $path);
920 920
 			}
921 921
 			return $filename;
922 922
 		}
@@ -942,8 +942,8 @@  discard block
 block discarded – undo
942 942
          */
943 943
 		public function deleteFileByName($filename)
944 944
 		{
945
-			$destinationPath = realpath(__DIR__ . '/../../www/files/');
946
-			$destination = $destinationPath . '/' . $filename;
945
+			$destinationPath = realpath(__DIR__.'/../../www/files/');
946
+			$destination = $destinationPath.'/'.$filename;
947 947
 
948 948
 			if (file_exists($destination)) {
949 949
 				$files = $this->getFiles();
Please login to merge, or discard this patch.
cloudcontrol/library/cc/cc.php 2 patches
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -38,14 +38,14 @@  discard block
 block discarded – undo
38 38
 		return '0 seconds';
39 39
 	}
40 40
 
41
-	$a = array( 365 * 24 * 60 * 60  =>  'year',
41
+	$a = array(365 * 24 * 60 * 60  =>  'year',
42 42
 				30 * 24 * 60 * 60  =>  'month',
43 43
 				24 * 60 * 60  =>  'day',
44 44
 				60 * 60  =>  'hour',
45 45
 				60  =>  'minute',
46 46
 				1  =>  'second'
47 47
 	);
48
-	$a_plural = array( 'year'   => 'years',
48
+	$a_plural = array('year'   => 'years',
49 49
 					   'month'  => 'months',
50 50
 					   'day'    => 'days',
51 51
 					   'hour'   => 'hours',
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 		if ($d >= 1)
60 60
 		{
61 61
 			$r = round($d);
62
-			return $r . ' ' . ($r > 1 ? $a_plural[$str] : $str) . ' ago';
62
+			return $r.' '.($r > 1 ? $a_plural[$str] : $str).' ago';
63 63
 		}
64 64
 	}
65 65
 	return 0;
@@ -73,13 +73,13 @@  discard block
 block discarded – undo
73 73
  * @param string $unit
74 74
  * @return string
75 75
  */
76
-function humanFileSize($size,$unit="") {
77
-	if( (!$unit && $size >= 1<<30) || $unit == "GB")
78
-		return number_format($size/(1<<30),2)."GB";
79
-	if( (!$unit && $size >= 1<<20) || $unit == "MB")
80
-		return number_format($size/(1<<20),2)."MB";
81
-	if( (!$unit && $size >= 1<<10) || $unit == "KB")
82
-		return number_format($size/(1<<10),2)."KB";
76
+function humanFileSize($size, $unit = "") {
77
+	if ((!$unit && $size >= 1 << 30) || $unit == "GB")
78
+		return number_format($size / (1 << 30), 2)."GB";
79
+	if ((!$unit && $size >= 1 << 20) || $unit == "MB")
80
+		return number_format($size / (1 << 20), 2)."MB";
81
+	if ((!$unit && $size >= 1 << 10) || $unit == "KB")
82
+		return number_format($size / (1 << 10), 2)."KB";
83 83
 	return number_format($size)." bytes";
84 84
 }
85 85
 
@@ -133,9 +133,9 @@  discard block
 block discarded – undo
133 133
  *
134 134
  * @return mixed|string
135 135
  */
136
-function slugify($str, $replace=array(), $delimiter='-') {
137
-	if( !empty($replace) ) {
138
-		$str = str_replace((array)$replace, ' ', $str);
136
+function slugify($str, $replace = array(), $delimiter = '-') {
137
+	if (!empty($replace)) {
138
+		$str = str_replace((array) $replace, ' ', $str);
139 139
 	}
140 140
 
141 141
 	$clean = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $str);
@@ -158,13 +158,13 @@  discard block
 block discarded – undo
158 158
 {
159 159
 	$debug_backtrace = current(debug_backtrace());
160 160
 	if (PHP_SAPI == 'cli') {
161
-		echo 'Dump: ' . $debug_backtrace['file'] . ':' . $debug_backtrace['line'] . "\n";
161
+		echo 'Dump: '.$debug_backtrace['file'].':'.$debug_backtrace['line']."\n";
162 162
 		foreach (func_get_args() as $data) {
163 163
 			var_dump($data);
164 164
 		}
165 165
 	} else {
166 166
 		ob_clean();
167
-		echo '<div>Dump: ' . $debug_backtrace['file'] . ':<b>' . $debug_backtrace['line'] . "</b></div>";
167
+		echo '<div>Dump: '.$debug_backtrace['file'].':<b>'.$debug_backtrace['line']."</b></div>";
168 168
 		echo '<pre>';
169 169
 		foreach (func_get_args() as $data) {
170 170
 			echo "<code>";
@@ -214,8 +214,8 @@  discard block
 block discarded – undo
214 214
  */
215 215
 function utf8Convert($array)
216 216
 {
217
-	array_walk_recursive($array, function(&$item, $key){
218
-		if(!mb_detect_encoding($item, 'utf-8', true)){
217
+	array_walk_recursive($array, function(&$item, $key) {
218
+		if (!mb_detect_encoding($item, 'utf-8', true)) {
219 219
 			$item = utf8_encode($item);
220 220
 		}
221 221
 	});
Please login to merge, or discard this patch.
Braces   +9 added lines, -6 removed lines patch added patch discarded remove patch
@@ -74,12 +74,15 @@
 block discarded – undo
74 74
  * @return string
75 75
  */
76 76
 function humanFileSize($size,$unit="") {
77
-	if( (!$unit && $size >= 1<<30) || $unit == "GB")
78
-		return number_format($size/(1<<30),2)."GB";
79
-	if( (!$unit && $size >= 1<<20) || $unit == "MB")
80
-		return number_format($size/(1<<20),2)."MB";
81
-	if( (!$unit && $size >= 1<<10) || $unit == "KB")
82
-		return number_format($size/(1<<10),2)."KB";
77
+	if( (!$unit && $size >= 1<<30) || $unit == "GB") {
78
+			return number_format($size/(1<<30),2)."GB";
79
+	}
80
+	if( (!$unit && $size >= 1<<20) || $unit == "MB") {
81
+			return number_format($size/(1<<20),2)."MB";
82
+	}
83
+	if( (!$unit && $size >= 1<<10) || $unit == "KB") {
84
+			return number_format($size/(1<<10),2)."KB";
85
+	}
83 86
 	return number_format($size)." bytes";
84 87
 }
85 88
 
Please login to merge, or discard this patch.
cloudcontrol/library/storage/Repository.php 2 patches
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -10,131 +10,131 @@
 block discarded – undo
10 10
 
11 11
 class Repository
12 12
 {
13
-    protected $storagePath;
14
-
15
-    protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users');
16
-
17
-    protected $sitemap;
18
-    protected $sitemapChanges = false;
19
-
20
-    protected $applicationComponents;
21
-    protected $applicationComponentsChanges = false;
22
-
23
-    protected $documentTypes;
24
-    protected $documentTypesChanges = false;
25
-
26
-    protected $bricks;
27
-    protected $bricksChanges = false;
28
-
29
-    protected $imageSet;
30
-    protected $imageSetChanges = false;
31
-
32
-    protected $images;
33
-    protected $imagesChanges = false;
34
-
35
-    protected $files;
36
-    protected $filesChanges = false;
37
-
38
-    protected $users;
39
-    protected $usersChanges = false;
40
-
41
-    /**
42
-     * Repository constructor.
43
-     */
44
-    public function __construct($storagePath)
45
-    {
46
-        $storagePath = realpath($storagePath);
47
-        if (is_dir($storagePath) && $storagePath !== false) {
48
-            $this->storagePath = $storagePath;
49
-        } else {
50
-            throw new \Exception('Repository not yet initialized.');
51
-        }
52
-    }
53
-
54
-    public static function create($storagePath)
55
-    {
56
-        return mkdir($storagePath);
57
-    }
58
-
59
-    public function init()
60
-    {
61
-        $storageDefaultPath = realpath('../library/cc/install/_storage.json');
62
-        $json = file_get_contents($storageDefaultPath);
63
-        $json = json_decode($json);
64
-        $this->sitemap = $json->sitemap;
65
-        $this->sitemapChanges = true;
66
-        $this->applicationComponents = $json->applicationComponents;
67
-        $this->applicationComponentsChanges = true;
68
-        $this->documentTypes = $json->documentTypes;
69
-        $this->documentTypesChanges = true;
70
-        $this->bricks = $json->bricks;
71
-        $this->bricksChanges = true;
72
-        $this->imageSet = $json->imageSet;
73
-        $this->imageSetChanges = true;
74
-        $this->images = $json->images;
75
-        $this->imagesChanges = true;
76
-        $this->files = $json->files;
77
-        $this->filesChanges = true;
78
-        $this->users = $json->users;
79
-        $this->usersChanges = true;
80
-        $this->save();
81
-    }
82
-
83
-    public function __get($name)
84
-    {
85
-        if (isset($this->$name)) {
86
-            if (in_array($name, $this->fileBasedSubsets)) {
87
-                return $this->$name;
88
-            } else {
89
-                dump();
90
-            }
91
-        } else {
92
-            if (in_array($name, $this->fileBasedSubsets)) {
93
-                return $this->loadSubset($name);
94
-            } else {
95
-                throw new \Exception('Trying to get undefined property from Repository: ' . $name);
96
-            }
97
-        }
98
-    }
99
-
100
-    public function __set($name, $value)
101
-    {
102
-        if (in_array($name, $this->fileBasedSubsets)) {
103
-            $this->$name = $value;
104
-            $changes = $name . 'Changes';
105
-            $this->$changes = true;
106
-        } else {
107
-            throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>');
108
-        }
109
-    }
110
-
111
-    public function save()
112
-    {
113
-        $this->sitemapChanges ? $this->saveSubset('sitemap') : null;
114
-        $this->applicationComponentsChanges ? $this->saveSubset('applicationComponents') : null;
115
-        $this->documentTypesChanges ? $this->saveSubset('documentTypes') : null;
116
-        $this->bricksChanges ? $this->saveSubset('bricks') : null;
117
-        $this->imageSetChanges ? $this->saveSubset('imageSet') : null;
118
-        $this->imagesChanges ? $this->saveSubset('images') : null;
119
-        $this->filesChanges ? $this->saveSubset('files') : null;
120
-        $this->usersChanges ? $this->saveSubset('users') : null;
121
-    }
122
-
123
-    protected function saveSubset($subset)
124
-    {
125
-        $json = json_encode($this->$subset);
126
-        $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json';
127
-        file_put_contents($subsetStoragePath, $json);
128
-        $changes = $subset . 'Changes';
129
-        $this->$changes = false;
130
-    }
131
-
132
-    protected function loadSubset($subset)
133
-    {
134
-        $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json';
135
-        $json = file_get_contents($subsetStoragePath);
136
-        $json = json_decode($json);
137
-        $this->$subset = $json;
138
-        return $json;
139
-    }
13
+	protected $storagePath;
14
+
15
+	protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users');
16
+
17
+	protected $sitemap;
18
+	protected $sitemapChanges = false;
19
+
20
+	protected $applicationComponents;
21
+	protected $applicationComponentsChanges = false;
22
+
23
+	protected $documentTypes;
24
+	protected $documentTypesChanges = false;
25
+
26
+	protected $bricks;
27
+	protected $bricksChanges = false;
28
+
29
+	protected $imageSet;
30
+	protected $imageSetChanges = false;
31
+
32
+	protected $images;
33
+	protected $imagesChanges = false;
34
+
35
+	protected $files;
36
+	protected $filesChanges = false;
37
+
38
+	protected $users;
39
+	protected $usersChanges = false;
40
+
41
+	/**
42
+	 * Repository constructor.
43
+	 */
44
+	public function __construct($storagePath)
45
+	{
46
+		$storagePath = realpath($storagePath);
47
+		if (is_dir($storagePath) && $storagePath !== false) {
48
+			$this->storagePath = $storagePath;
49
+		} else {
50
+			throw new \Exception('Repository not yet initialized.');
51
+		}
52
+	}
53
+
54
+	public static function create($storagePath)
55
+	{
56
+		return mkdir($storagePath);
57
+	}
58
+
59
+	public function init()
60
+	{
61
+		$storageDefaultPath = realpath('../library/cc/install/_storage.json');
62
+		$json = file_get_contents($storageDefaultPath);
63
+		$json = json_decode($json);
64
+		$this->sitemap = $json->sitemap;
65
+		$this->sitemapChanges = true;
66
+		$this->applicationComponents = $json->applicationComponents;
67
+		$this->applicationComponentsChanges = true;
68
+		$this->documentTypes = $json->documentTypes;
69
+		$this->documentTypesChanges = true;
70
+		$this->bricks = $json->bricks;
71
+		$this->bricksChanges = true;
72
+		$this->imageSet = $json->imageSet;
73
+		$this->imageSetChanges = true;
74
+		$this->images = $json->images;
75
+		$this->imagesChanges = true;
76
+		$this->files = $json->files;
77
+		$this->filesChanges = true;
78
+		$this->users = $json->users;
79
+		$this->usersChanges = true;
80
+		$this->save();
81
+	}
82
+
83
+	public function __get($name)
84
+	{
85
+		if (isset($this->$name)) {
86
+			if (in_array($name, $this->fileBasedSubsets)) {
87
+				return $this->$name;
88
+			} else {
89
+				dump();
90
+			}
91
+		} else {
92
+			if (in_array($name, $this->fileBasedSubsets)) {
93
+				return $this->loadSubset($name);
94
+			} else {
95
+				throw new \Exception('Trying to get undefined property from Repository: ' . $name);
96
+			}
97
+		}
98
+	}
99
+
100
+	public function __set($name, $value)
101
+	{
102
+		if (in_array($name, $this->fileBasedSubsets)) {
103
+			$this->$name = $value;
104
+			$changes = $name . 'Changes';
105
+			$this->$changes = true;
106
+		} else {
107
+			throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>');
108
+		}
109
+	}
110
+
111
+	public function save()
112
+	{
113
+		$this->sitemapChanges ? $this->saveSubset('sitemap') : null;
114
+		$this->applicationComponentsChanges ? $this->saveSubset('applicationComponents') : null;
115
+		$this->documentTypesChanges ? $this->saveSubset('documentTypes') : null;
116
+		$this->bricksChanges ? $this->saveSubset('bricks') : null;
117
+		$this->imageSetChanges ? $this->saveSubset('imageSet') : null;
118
+		$this->imagesChanges ? $this->saveSubset('images') : null;
119
+		$this->filesChanges ? $this->saveSubset('files') : null;
120
+		$this->usersChanges ? $this->saveSubset('users') : null;
121
+	}
122
+
123
+	protected function saveSubset($subset)
124
+	{
125
+		$json = json_encode($this->$subset);
126
+		$subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json';
127
+		file_put_contents($subsetStoragePath, $json);
128
+		$changes = $subset . 'Changes';
129
+		$this->$changes = false;
130
+	}
131
+
132
+	protected function loadSubset($subset)
133
+	{
134
+		$subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json';
135
+		$json = file_get_contents($subsetStoragePath);
136
+		$json = json_decode($json);
137
+		$this->$subset = $json;
138
+		return $json;
139
+	}
140 140
 }
141 141
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
             if (in_array($name, $this->fileBasedSubsets)) {
93 93
                 return $this->loadSubset($name);
94 94
             } else {
95
-                throw new \Exception('Trying to get undefined property from Repository: ' . $name);
95
+                throw new \Exception('Trying to get undefined property from Repository: '.$name);
96 96
             }
97 97
         }
98 98
     }
@@ -101,10 +101,10 @@  discard block
 block discarded – undo
101 101
     {
102 102
         if (in_array($name, $this->fileBasedSubsets)) {
103 103
             $this->$name = $value;
104
-            $changes = $name . 'Changes';
104
+            $changes = $name.'Changes';
105 105
             $this->$changes = true;
106 106
         } else {
107
-            throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>');
107
+            throw new \Exception('Trying to persist unknown subset in repository: '.$name.' <br /><pre>'.print_r($value, true).'</pre>');
108 108
         }
109 109
     }
110 110
 
@@ -123,15 +123,15 @@  discard block
 block discarded – undo
123 123
     protected function saveSubset($subset)
124 124
     {
125 125
         $json = json_encode($this->$subset);
126
-        $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json';
126
+        $subsetStoragePath = $this->storagePath.DIRECTORY_SEPARATOR.$subset.'.json';
127 127
         file_put_contents($subsetStoragePath, $json);
128
-        $changes = $subset . 'Changes';
128
+        $changes = $subset.'Changes';
129 129
         $this->$changes = false;
130 130
     }
131 131
 
132 132
     protected function loadSubset($subset)
133 133
     {
134
-        $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json';
134
+        $subsetStoragePath = $this->storagePath.DIRECTORY_SEPARATOR.$subset.'.json';
135 135
         $json = file_get_contents($subsetStoragePath);
136 136
         $json = json_decode($json);
137 137
         $this->$subset = $json;
Please login to merge, or discard this patch.