Passed
Push — develop ( 0cf906...cb779b )
by Jens
06:50
created
src/cc/Application.php 3 patches
Doc Comments   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -83,6 +83,9 @@  discard block
 block discarded – undo
83 83
             $this->storage = new Storage($this->config->rootDir . DIRECTORY_SEPARATOR . $this->config->storageDir, $this->config->imagesDir, $this->config->filesDir);
84 84
         }
85 85
 
86
+        /**
87
+         * @param Request $request
88
+         */
86 89
         private function redirectMatching($request)
87 90
         {
88 91
             $redirects = $this->storage->getRedirects()->getRedirects();
@@ -112,7 +115,7 @@  discard block
 block discarded – undo
112 115
          * Loop through sitemap items and see if one matches the requestUri.
113 116
          * If it does, add it tot the matchedSitemapItems array
114 117
          *
115
-         * @param $request
118
+         * @param Request $request
116 119
          */
117 120
         private function sitemapMatching($request)
118 121
         {
@@ -177,7 +180,7 @@  discard block
 block discarded – undo
177 180
          * @param array $parameters
178 181
          * @param \stdClass|null $matchedSitemapItem
179 182
          *
180
-         * @return mixed
183
+         * @return Component
181 184
          * @throws \Exception
182 185
          */
183 186
         private function getComponentObject($class = '', $template = '', $parameters = array(), $matchedSitemapItem)
Please login to merge, or discard this patch.
Indentation   +273 added lines, -273 removed lines patch added patch discarded remove patch
@@ -2,277 +2,277 @@
 block discarded – undo
2 2
 
3 3
 namespace CloudControl\Cms\cc {
4 4
 
5
-    use CloudControl\Cms\components\Component;
6
-    use CloudControl\Cms\storage\Storage;
7
-    use Whoops\Handler\PrettyPageHandler;
8
-    use Whoops\Run;
9
-
10
-    class Application
11
-    {
12
-        /**
13
-         * @var \stdClass
14
-         */
15
-        private $config;
16
-        /**
17
-         * @var \CloudControl\Cms\storage\Storage
18
-         */
19
-        private $storage;
20
-
21
-        /**
22
-         * @var \CloudControl\Cms\cc\Request
23
-         */
24
-        private $request;
25
-
26
-        /**
27
-         * @var array
28
-         */
29
-        private $matchedSitemapItems = array();
30
-
31
-        /**
32
-         * @var array
33
-         */
34
-        private $applicationComponents = array();
35
-
36
-        /**
37
-         * Application constructor.
38
-         */
39
-        public function __construct()
40
-        {
41
-            $this->config();
42
-            $this->storage();
43
-
44
-            $this->request = new Request();
45
-
46
-            $whoops = new Run;
47
-            $whoops->pushHandler(new PrettyPageHandler);
48
-            $whoops->register();
49
-
50
-            $this->redirectMatching($this->request);
51
-            $this->sitemapMatching($this->request);
52
-
53
-            $this->getApplicationComponents();
54
-
55
-            $this->runApplicationComponents();
56
-            $this->runSitemapComponents();
57
-
58
-            $this->renderApplicationComponents();
59
-            $this->renderSitemapComponents();
60
-        }
61
-
62
-        /**
63
-         * Initialize the config
64
-         *
65
-         * @throws \Exception
66
-         */
67
-        private function config()
68
-        {
69
-            $configPath = __DIR__ . '/../../config.json';
70
-            if (realpath($configPath) !== false) {
71
-                $json = file_get_contents($configPath);
72
-                $this->config = json_decode($json);
73
-            } else {
74
-                throw new \Exception('Framework not initialized yet. Consider running composer install');
75
-            }
76
-        }
77
-
78
-        /**
79
-         * Initialize the storage
80
-         */
81
-        private function storage()
82
-        {
83
-            $this->storage = new Storage($this->config->rootDir . DIRECTORY_SEPARATOR . $this->config->storageDir, $this->config->imagesDir, $this->config->filesDir);
84
-        }
85
-
86
-        private function redirectMatching($request)
87
-        {
88
-            $redirects = $this->storage->getRedirects()->getRedirects();
89
-            $relativeUri = '/' . $request::$relativeUri;
90
-
91
-            foreach ($redirects as $redirect) {
92
-                if (preg_match_all($redirect->fromUrl, $relativeUri, $matches)) {
93
-                    $toUrl = preg_replace($redirect->fromUrl, $redirect->toUrl, $relativeUri);
94
-                    if (substr($toUrl, 0, 1) == '/') {
95
-                        $toUrl = substr($toUrl, 1);
96
-                    }
97
-                    if ($redirect->type == '301') {
98
-                        header('HTTP/1.1 301 Moved Permanently');
99
-                        header('Location: ' . $request::$subfolders . $toUrl);
100
-                        exit;
101
-                    } elseif ($redirect->type == '302') {
102
-                        header('Location: ' . $request::$subfolders . $toUrl, true, 302);
103
-                        exit;
104
-                    } else {
105
-                        throw new \Exception('Invalid redirect type.');
106
-                    }
107
-                }
108
-            }
109
-        }
110
-
111
-        /**
112
-         * Loop through sitemap items and see if one matches the requestUri.
113
-         * If it does, add it tot the matchedSitemapItems array
114
-         *
115
-         * @param $request
116
-         */
117
-        private function sitemapMatching($request)
118
-        {
119
-            $sitemap = $this->storage->getSitemap()->getSitemap();
120
-            $relativeUri = '/' . $request::$relativeUri;
121
-
122
-            foreach ($sitemap as $sitemapItem) {
123
-                if ($sitemapItem->regex) {
124
-                    $matches = array();
125
-                    if (preg_match_all($sitemapItem->url, $relativeUri, $matches)) {
126
-                        // Make a clone, so it doesnt add the matches to the original
127
-                        $matchedClone = clone $sitemapItem;
128
-                        $matchedClone->matches = $matches;
129
-                        $this->matchedSitemapItems[] = $matchedClone;
130
-                        return;
131
-                    }
132
-                } else {
133
-                    if ($sitemapItem->url == $relativeUri) {
134
-                        $this->matchedSitemapItems[] = $sitemapItem;
135
-                        return;
136
-                    }
137
-                }
138
-            }
139
-        }
140
-
141
-        /**
142
-         * Loop through all application components and run them
143
-         *
144
-         * @throws \Exception
145
-         */
146
-        private function runApplicationComponents()
147
-        {
148
-            foreach ($this->applicationComponents as $key => $applicationComponent) {
149
-                $class = $applicationComponent->component;
150
-                $parameters = $applicationComponent->parameters;
151
-                $this->applicationComponents[$key]->{'object'} = $this->getComponentObject($class, null, $parameters, null);
152
-                $this->applicationComponents[$key]->{'object'}->run($this->storage);
153
-            }
154
-        }
155
-
156
-        /**
157
-         * Loop through all (matched) sitemap components and run them
158
-         *
159
-         * @throws \Exception
160
-         */
161
-        private function runSitemapComponents()
162
-        {
163
-            foreach ($this->matchedSitemapItems as $key => $sitemapItem) {
164
-                $class = $sitemapItem->component;
165
-                $template = $sitemapItem->template;
166
-                $parameters = $sitemapItem->parameters;
167
-
168
-                $this->matchedSitemapItems[$key]->object = $this->getComponentObject($class, $template, $parameters, $sitemapItem);
169
-
170
-                $this->matchedSitemapItems[$key]->object->run($this->storage);
171
-            }
172
-        }
173
-
174
-        /**
175
-         * @param string $class
176
-         * @param string $template
177
-         * @param array $parameters
178
-         * @param \stdClass|null $matchedSitemapItem
179
-         *
180
-         * @return mixed
181
-         * @throws \Exception
182
-         */
183
-        private function getComponentObject($class = '', $template = '', $parameters = array(), $matchedSitemapItem)
184
-        {
185
-            $libraryComponentName = '\\CloudControl\Cms\\components\\' . $class;
186
-            $userComponentName = '\\components\\' . $class;
187
-
188
-            if (!class_exists($libraryComponentName, false)) {
189
-                $component = new $libraryComponentName($template, $this->request, $parameters, $matchedSitemapItem);
190
-            } elseif (!class_exists($userComponentName, false)) {
191
-                $component = new $userComponentName($template, $this->request, $parameters, $matchedSitemapItem);
192
-            } else {
193
-                throw new \Exception('Could not load component ' . $class);
194
-            }
195
-
196
-            if (!$component instanceof Component) {
197
-                throw new \Exception('Component not of type Component. Must inherit \CloudControl\Cms\components\Component');
198
-            }
199
-
200
-            return $component;
201
-        }
202
-
203
-        /**
204
-         * Loop through all application components and render them
205
-         */
206
-        private function renderApplicationComponents()
207
-        {
208
-            foreach ($this->applicationComponents as $applicationComponent) {
209
-                $applicationComponent->{'object'}->render();
210
-            }
211
-        }
212
-
213
-        /**
214
-         * Loop through all (matched) sitemap components and render them
215
-         */
216
-        private function renderSitemapComponents()
217
-        {
218
-            foreach ($this->matchedSitemapItems as $sitemapItem) {
219
-                $this->setCachingHeaders();
220
-                $sitemapItem->object->render($this);
221
-                ob_clean();
222
-                echo $sitemapItem->object->get();
223
-                ob_end_flush();
224
-                exit;
225
-            }
226
-        }
227
-
228
-        public function getAllApplicationComponentParameters()
229
-        {
230
-            $allParameters = array();
231
-            foreach ($this->applicationComponents as $applicationComponent) {
232
-                $parameters = $applicationComponent->{'object'}->getParameters();
233
-                $allParameters[] = $parameters;
234
-            }
235
-            return $allParameters;
236
-        }
237
-
238
-        public function unlockApplicationComponentParameters()
239
-        {
240
-            foreach ($this->applicationComponents as $applicationComponent) {
241
-                $parameters = $applicationComponent->{'object'}->getParameters();
242
-                extract($parameters);
243
-            }
244
-        }
245
-
246
-        /**
247
-         * Set the default caching of pages to 2 days
248
-         */
249
-        public function setCachingHeaders()
250
-        {
251
-            header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60 * 24 * 2))); // 2 days
252
-            header("Cache-Control: max-age=" . (60 * 60 * 24 * 2));
253
-        }
254
-
255
-        /**
256
-         * @return string
257
-         */
258
-        public function getTemplateDir()
259
-        {
260
-            return $this->config->templateDir;
261
-        }
262
-
263
-        public function getStorageDir()
264
-        {
265
-            return $this->config->storageDir;
266
-        }
267
-
268
-        public function getApplicationComponents()
269
-        {
270
-            $this->applicationComponents = $this->storage->getApplicationComponents()->getApplicationComponents();
271
-        }
272
-
273
-        public function getRootDir()
274
-        {
275
-            return $this->config->rootDir;
276
-        }
277
-    }
5
+	use CloudControl\Cms\components\Component;
6
+	use CloudControl\Cms\storage\Storage;
7
+	use Whoops\Handler\PrettyPageHandler;
8
+	use Whoops\Run;
9
+
10
+	class Application
11
+	{
12
+		/**
13
+		 * @var \stdClass
14
+		 */
15
+		private $config;
16
+		/**
17
+		 * @var \CloudControl\Cms\storage\Storage
18
+		 */
19
+		private $storage;
20
+
21
+		/**
22
+		 * @var \CloudControl\Cms\cc\Request
23
+		 */
24
+		private $request;
25
+
26
+		/**
27
+		 * @var array
28
+		 */
29
+		private $matchedSitemapItems = array();
30
+
31
+		/**
32
+		 * @var array
33
+		 */
34
+		private $applicationComponents = array();
35
+
36
+		/**
37
+		 * Application constructor.
38
+		 */
39
+		public function __construct()
40
+		{
41
+			$this->config();
42
+			$this->storage();
43
+
44
+			$this->request = new Request();
45
+
46
+			$whoops = new Run;
47
+			$whoops->pushHandler(new PrettyPageHandler);
48
+			$whoops->register();
49
+
50
+			$this->redirectMatching($this->request);
51
+			$this->sitemapMatching($this->request);
52
+
53
+			$this->getApplicationComponents();
54
+
55
+			$this->runApplicationComponents();
56
+			$this->runSitemapComponents();
57
+
58
+			$this->renderApplicationComponents();
59
+			$this->renderSitemapComponents();
60
+		}
61
+
62
+		/**
63
+		 * Initialize the config
64
+		 *
65
+		 * @throws \Exception
66
+		 */
67
+		private function config()
68
+		{
69
+			$configPath = __DIR__ . '/../../config.json';
70
+			if (realpath($configPath) !== false) {
71
+				$json = file_get_contents($configPath);
72
+				$this->config = json_decode($json);
73
+			} else {
74
+				throw new \Exception('Framework not initialized yet. Consider running composer install');
75
+			}
76
+		}
77
+
78
+		/**
79
+		 * Initialize the storage
80
+		 */
81
+		private function storage()
82
+		{
83
+			$this->storage = new Storage($this->config->rootDir . DIRECTORY_SEPARATOR . $this->config->storageDir, $this->config->imagesDir, $this->config->filesDir);
84
+		}
85
+
86
+		private function redirectMatching($request)
87
+		{
88
+			$redirects = $this->storage->getRedirects()->getRedirects();
89
+			$relativeUri = '/' . $request::$relativeUri;
90
+
91
+			foreach ($redirects as $redirect) {
92
+				if (preg_match_all($redirect->fromUrl, $relativeUri, $matches)) {
93
+					$toUrl = preg_replace($redirect->fromUrl, $redirect->toUrl, $relativeUri);
94
+					if (substr($toUrl, 0, 1) == '/') {
95
+						$toUrl = substr($toUrl, 1);
96
+					}
97
+					if ($redirect->type == '301') {
98
+						header('HTTP/1.1 301 Moved Permanently');
99
+						header('Location: ' . $request::$subfolders . $toUrl);
100
+						exit;
101
+					} elseif ($redirect->type == '302') {
102
+						header('Location: ' . $request::$subfolders . $toUrl, true, 302);
103
+						exit;
104
+					} else {
105
+						throw new \Exception('Invalid redirect type.');
106
+					}
107
+				}
108
+			}
109
+		}
110
+
111
+		/**
112
+		 * Loop through sitemap items and see if one matches the requestUri.
113
+		 * If it does, add it tot the matchedSitemapItems array
114
+		 *
115
+		 * @param $request
116
+		 */
117
+		private function sitemapMatching($request)
118
+		{
119
+			$sitemap = $this->storage->getSitemap()->getSitemap();
120
+			$relativeUri = '/' . $request::$relativeUri;
121
+
122
+			foreach ($sitemap as $sitemapItem) {
123
+				if ($sitemapItem->regex) {
124
+					$matches = array();
125
+					if (preg_match_all($sitemapItem->url, $relativeUri, $matches)) {
126
+						// Make a clone, so it doesnt add the matches to the original
127
+						$matchedClone = clone $sitemapItem;
128
+						$matchedClone->matches = $matches;
129
+						$this->matchedSitemapItems[] = $matchedClone;
130
+						return;
131
+					}
132
+				} else {
133
+					if ($sitemapItem->url == $relativeUri) {
134
+						$this->matchedSitemapItems[] = $sitemapItem;
135
+						return;
136
+					}
137
+				}
138
+			}
139
+		}
140
+
141
+		/**
142
+		 * Loop through all application components and run them
143
+		 *
144
+		 * @throws \Exception
145
+		 */
146
+		private function runApplicationComponents()
147
+		{
148
+			foreach ($this->applicationComponents as $key => $applicationComponent) {
149
+				$class = $applicationComponent->component;
150
+				$parameters = $applicationComponent->parameters;
151
+				$this->applicationComponents[$key]->{'object'} = $this->getComponentObject($class, null, $parameters, null);
152
+				$this->applicationComponents[$key]->{'object'}->run($this->storage);
153
+			}
154
+		}
155
+
156
+		/**
157
+		 * Loop through all (matched) sitemap components and run them
158
+		 *
159
+		 * @throws \Exception
160
+		 */
161
+		private function runSitemapComponents()
162
+		{
163
+			foreach ($this->matchedSitemapItems as $key => $sitemapItem) {
164
+				$class = $sitemapItem->component;
165
+				$template = $sitemapItem->template;
166
+				$parameters = $sitemapItem->parameters;
167
+
168
+				$this->matchedSitemapItems[$key]->object = $this->getComponentObject($class, $template, $parameters, $sitemapItem);
169
+
170
+				$this->matchedSitemapItems[$key]->object->run($this->storage);
171
+			}
172
+		}
173
+
174
+		/**
175
+		 * @param string $class
176
+		 * @param string $template
177
+		 * @param array $parameters
178
+		 * @param \stdClass|null $matchedSitemapItem
179
+		 *
180
+		 * @return mixed
181
+		 * @throws \Exception
182
+		 */
183
+		private function getComponentObject($class = '', $template = '', $parameters = array(), $matchedSitemapItem)
184
+		{
185
+			$libraryComponentName = '\\CloudControl\Cms\\components\\' . $class;
186
+			$userComponentName = '\\components\\' . $class;
187
+
188
+			if (!class_exists($libraryComponentName, false)) {
189
+				$component = new $libraryComponentName($template, $this->request, $parameters, $matchedSitemapItem);
190
+			} elseif (!class_exists($userComponentName, false)) {
191
+				$component = new $userComponentName($template, $this->request, $parameters, $matchedSitemapItem);
192
+			} else {
193
+				throw new \Exception('Could not load component ' . $class);
194
+			}
195
+
196
+			if (!$component instanceof Component) {
197
+				throw new \Exception('Component not of type Component. Must inherit \CloudControl\Cms\components\Component');
198
+			}
199
+
200
+			return $component;
201
+		}
202
+
203
+		/**
204
+		 * Loop through all application components and render them
205
+		 */
206
+		private function renderApplicationComponents()
207
+		{
208
+			foreach ($this->applicationComponents as $applicationComponent) {
209
+				$applicationComponent->{'object'}->render();
210
+			}
211
+		}
212
+
213
+		/**
214
+		 * Loop through all (matched) sitemap components and render them
215
+		 */
216
+		private function renderSitemapComponents()
217
+		{
218
+			foreach ($this->matchedSitemapItems as $sitemapItem) {
219
+				$this->setCachingHeaders();
220
+				$sitemapItem->object->render($this);
221
+				ob_clean();
222
+				echo $sitemapItem->object->get();
223
+				ob_end_flush();
224
+				exit;
225
+			}
226
+		}
227
+
228
+		public function getAllApplicationComponentParameters()
229
+		{
230
+			$allParameters = array();
231
+			foreach ($this->applicationComponents as $applicationComponent) {
232
+				$parameters = $applicationComponent->{'object'}->getParameters();
233
+				$allParameters[] = $parameters;
234
+			}
235
+			return $allParameters;
236
+		}
237
+
238
+		public function unlockApplicationComponentParameters()
239
+		{
240
+			foreach ($this->applicationComponents as $applicationComponent) {
241
+				$parameters = $applicationComponent->{'object'}->getParameters();
242
+				extract($parameters);
243
+			}
244
+		}
245
+
246
+		/**
247
+		 * Set the default caching of pages to 2 days
248
+		 */
249
+		public function setCachingHeaders()
250
+		{
251
+			header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60 * 24 * 2))); // 2 days
252
+			header("Cache-Control: max-age=" . (60 * 60 * 24 * 2));
253
+		}
254
+
255
+		/**
256
+		 * @return string
257
+		 */
258
+		public function getTemplateDir()
259
+		{
260
+			return $this->config->templateDir;
261
+		}
262
+
263
+		public function getStorageDir()
264
+		{
265
+			return $this->config->storageDir;
266
+		}
267
+
268
+		public function getApplicationComponents()
269
+		{
270
+			$this->applicationComponents = $this->storage->getApplicationComponents()->getApplicationComponents();
271
+		}
272
+
273
+		public function getRootDir()
274
+		{
275
+			return $this->config->rootDir;
276
+		}
277
+	}
278 278
 }
279 279
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
          */
67 67
         private function config()
68 68
         {
69
-            $configPath = __DIR__ . '/../../config.json';
69
+            $configPath = __DIR__.'/../../config.json';
70 70
             if (realpath($configPath) !== false) {
71 71
                 $json = file_get_contents($configPath);
72 72
                 $this->config = json_decode($json);
@@ -80,13 +80,13 @@  discard block
 block discarded – undo
80 80
          */
81 81
         private function storage()
82 82
         {
83
-            $this->storage = new Storage($this->config->rootDir . DIRECTORY_SEPARATOR . $this->config->storageDir, $this->config->imagesDir, $this->config->filesDir);
83
+            $this->storage = new Storage($this->config->rootDir.DIRECTORY_SEPARATOR.$this->config->storageDir, $this->config->imagesDir, $this->config->filesDir);
84 84
         }
85 85
 
86 86
         private function redirectMatching($request)
87 87
         {
88 88
             $redirects = $this->storage->getRedirects()->getRedirects();
89
-            $relativeUri = '/' . $request::$relativeUri;
89
+            $relativeUri = '/'.$request::$relativeUri;
90 90
 
91 91
             foreach ($redirects as $redirect) {
92 92
                 if (preg_match_all($redirect->fromUrl, $relativeUri, $matches)) {
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
                     }
97 97
                     if ($redirect->type == '301') {
98 98
                         header('HTTP/1.1 301 Moved Permanently');
99
-                        header('Location: ' . $request::$subfolders . $toUrl);
99
+                        header('Location: '.$request::$subfolders.$toUrl);
100 100
                         exit;
101 101
                     } elseif ($redirect->type == '302') {
102
-                        header('Location: ' . $request::$subfolders . $toUrl, true, 302);
102
+                        header('Location: '.$request::$subfolders.$toUrl, true, 302);
103 103
                         exit;
104 104
                     } else {
105 105
                         throw new \Exception('Invalid redirect type.');
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
         private function sitemapMatching($request)
118 118
         {
119 119
             $sitemap = $this->storage->getSitemap()->getSitemap();
120
-            $relativeUri = '/' . $request::$relativeUri;
120
+            $relativeUri = '/'.$request::$relativeUri;
121 121
 
122 122
             foreach ($sitemap as $sitemapItem) {
123 123
                 if ($sitemapItem->regex) {
@@ -182,15 +182,15 @@  discard block
 block discarded – undo
182 182
          */
183 183
         private function getComponentObject($class = '', $template = '', $parameters = array(), $matchedSitemapItem)
184 184
         {
185
-            $libraryComponentName = '\\CloudControl\Cms\\components\\' . $class;
186
-            $userComponentName = '\\components\\' . $class;
185
+            $libraryComponentName = '\\CloudControl\Cms\\components\\'.$class;
186
+            $userComponentName = '\\components\\'.$class;
187 187
 
188 188
             if (!class_exists($libraryComponentName, false)) {
189 189
                 $component = new $libraryComponentName($template, $this->request, $parameters, $matchedSitemapItem);
190 190
             } elseif (!class_exists($userComponentName, false)) {
191 191
                 $component = new $userComponentName($template, $this->request, $parameters, $matchedSitemapItem);
192 192
             } else {
193
-                throw new \Exception('Could not load component ' . $class);
193
+                throw new \Exception('Could not load component '.$class);
194 194
             }
195 195
 
196 196
             if (!$component instanceof Component) {
@@ -248,8 +248,8 @@  discard block
 block discarded – undo
248 248
          */
249 249
         public function setCachingHeaders()
250 250
         {
251
-            header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60 * 24 * 2))); // 2 days
252
-            header("Cache-Control: max-age=" . (60 * 60 * 24 * 2));
251
+            header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60 * 24 * 2))); // 2 days
252
+            header("Cache-Control: max-age=".(60 * 60 * 24 * 2));
253 253
         }
254 254
 
255 255
         /**
Please login to merge, or discard this patch.
src/storage/storage/FilesStorage.php 2 patches
Doc Comments   +5 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,6 +10,10 @@  discard block
 block discarded – undo
10 10
 {
11 11
     protected $filesDir;
12 12
 
13
+    /**
14
+     * @param \CloudControl\Cms\storage\Repository $repository
15
+     * @param string $filesDir
16
+     */
13 17
     public function __construct($repository, $filesDir)
14 18
     {
15 19
         parent::__construct($repository);
@@ -101,7 +105,7 @@  discard block
 block discarded – undo
101 105
 	}
102 106
 
103 107
     /**
104
-     * @return mixed
108
+     * @return string
105 109
      */
106 110
     public function getFilesDir()
107 111
     {
Please login to merge, or discard this patch.
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -8,16 +8,16 @@  discard block
 block discarded – undo
8 8
 
9 9
 class FilesStorage extends AbstractStorage
10 10
 {
11
-    protected $filesDir;
11
+	protected $filesDir;
12 12
 
13
-    public function __construct($repository, $filesDir)
14
-    {
15
-        parent::__construct($repository);
16
-        $this->filesDir = $filesDir;
17
-    }
13
+	public function __construct($repository, $filesDir)
14
+	{
15
+		parent::__construct($repository);
16
+		$this->filesDir = $filesDir;
17
+	}
18 18
 
19 19
 
20
-    /**
20
+	/**
21 21
 	 * @return array
22 22
 	 */
23 23
 	public function getFiles() {
@@ -100,15 +100,15 @@  discard block
 block discarded – undo
100 100
 		}
101 101
 	}
102 102
 
103
-    /**
104
-     * @return mixed
105
-     */
106
-    public function getFilesDir()
107
-    {
108
-        return $this->filesDir;
109
-    }
103
+	/**
104
+	 * @return mixed
105
+	 */
106
+	public function getFilesDir()
107
+	{
108
+		return $this->filesDir;
109
+	}
110 110
 
111
-    /**
111
+	/**
112 112
 	 * @param $a
113 113
 	 * @param $b
114 114
 	 *
@@ -119,9 +119,9 @@  discard block
 block discarded – undo
119 119
 		return strcmp($a->file, $b->file);
120 120
 	}
121 121
 
122
-    protected function getDestinationPath()
123
-    {
124
-        $destinationPath = realpath($this->filesDir . DIRECTORY_SEPARATOR);
125
-        return $destinationPath;
126
-    }
122
+	protected function getDestinationPath()
123
+	{
124
+		$destinationPath = realpath($this->filesDir . DIRECTORY_SEPARATOR);
125
+		return $destinationPath;
126
+	}
127 127
 }
128 128
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/BaseComponent.php 2 patches
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -2,11 +2,11 @@  discard block
 block discarded – undo
2 2
 namespace CloudControl\Cms\components
3 3
 {
4 4
 
5
-    use CloudControl\Cms\cc\Application;
6
-    use CloudControl\Cms\cc\Request;
7
-    use CloudControl\Cms\storage\Storage;
5
+	use CloudControl\Cms\cc\Application;
6
+	use CloudControl\Cms\cc\Request;
7
+	use CloudControl\Cms\storage\Storage;
8 8
 
9
-    class BaseComponent implements Component
9
+	class BaseComponent implements Component
10 10
 	{
11 11
 		/**
12 12
 		 * @var string
@@ -94,17 +94,17 @@  discard block
 block discarded – undo
94 94
 		 */
95 95
 		public function renderTemplate($template='', $obClean = true, $application=null)
96 96
 		{
97
-		    $templateDir = $this->getTemplateDir($template, $application);
98
-		    if ($application !== null) {
99
-                $rootDir = $application->getRootDir();
100
-                if (strpos($templateDir, $rootDir) === false) {
101
-                    $templatePath = $rootDir . DIRECTORY_SEPARATOR . $templateDir;
102
-                } else {
103
-                    $templatePath = $templateDir;
104
-                }
105
-            } else {
106
-		        $templatePath = $templateDir;
107
-            }
97
+			$templateDir = $this->getTemplateDir($template, $application);
98
+			if ($application !== null) {
99
+				$rootDir = $application->getRootDir();
100
+				if (strpos($templateDir, $rootDir) === false) {
101
+					$templatePath = $rootDir . DIRECTORY_SEPARATOR . $templateDir;
102
+				} else {
103
+					$templatePath = $templateDir;
104
+				}
105
+			} else {
106
+				$templatePath = $templateDir;
107
+			}
108 108
 			if (realpath($templatePath) !== false) {
109 109
 				if ($obClean) {
110 110
 					ob_clean();
@@ -151,19 +151,19 @@  discard block
 block discarded – undo
151 151
 			return $this->parameters;
152 152
 		}
153 153
 
154
-        /**
155
-         * @param $template
156
-         * @param null | Application $application
157
-         * @return string
158
-         */
159
-        protected function getTemplateDir($template, $application=null)
160
-        {
161
-            $templatePath = '';
162
-            if ($application !== null) {
163
-                $templatePath = $application->getTemplateDir();
164
-            }
165
-            $templatePath = $templatePath . $template . '.php';
166
-            return $templatePath;
167
-        }
168
-    }
154
+		/**
155
+		 * @param $template
156
+		 * @param null | Application $application
157
+		 * @return string
158
+		 */
159
+		protected function getTemplateDir($template, $application=null)
160
+		{
161
+			$templatePath = '';
162
+			if ($application !== null) {
163
+				$templatePath = $application->getTemplateDir();
164
+			}
165
+			$templatePath = $templatePath . $template . '.php';
166
+			return $templatePath;
167
+		}
168
+	}
169 169
 }
170 170
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 		 * @param array   $parameters
42 42
 		 * @param         $matchedSitemapItem
43 43
 		 */
44
-		public function __construct($template='', Request $request, $parameters=array(), $matchedSitemapItem)
44
+		public function __construct($template = '', Request $request, $parameters = array(), $matchedSitemapItem)
45 45
 		{
46 46
 			$this->template = $template;
47 47
 			$this->request = $request;
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 		 *
67 67
 		 * @throws \Exception
68 68
 		 */
69
-		public function render($application=null)
69
+		public function render($application = null)
70 70
 		{
71 71
 			$this->renderedContent = $this->renderTemplate($this->template, true, $application);
72 72
 		}
@@ -92,13 +92,13 @@  discard block
 block discarded – undo
92 92
 		 * @return string
93 93
 		 * @throws \Exception
94 94
 		 */
95
-		public function renderTemplate($template='', $obClean = true, $application=null)
95
+		public function renderTemplate($template = '', $obClean = true, $application = null)
96 96
 		{
97 97
 		    $templateDir = $this->getTemplateDir($template, $application);
98 98
 		    if ($application !== null) {
99 99
                 $rootDir = $application->getRootDir();
100 100
                 if (strpos($templateDir, $rootDir) === false) {
101
-                    $templatePath = $rootDir . DIRECTORY_SEPARATOR . $templateDir;
101
+                    $templatePath = $rootDir.DIRECTORY_SEPARATOR.$templateDir;
102 102
                 } else {
103 103
                     $templatePath = $templateDir;
104 104
                 }
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 				return ob_get_contents();
122 122
 			} else {
123 123
 				if ($template !== null) { // If template is null, its a application component, which doesnt have a template
124
-					throw new \Exception('Couldnt find template ' . $templatePath);
124
+					throw new \Exception('Couldnt find template '.$templatePath);
125 125
 				}
126 126
 			}
127 127
 		}
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 		 * @return string
137 137
 		 * @throws \Exception
138 138
 		 */
139
-		public function includeTemplate($template='', $parameters = array())
139
+		public function includeTemplate($template = '', $parameters = array())
140 140
 		{
141 141
 			if (is_array($parameters)) {
142 142
 				foreach ($parameters as $name => $value) {
@@ -156,13 +156,13 @@  discard block
 block discarded – undo
156 156
          * @param null | Application $application
157 157
          * @return string
158 158
          */
159
-        protected function getTemplateDir($template, $application=null)
159
+        protected function getTemplateDir($template, $application = null)
160 160
         {
161 161
             $templatePath = '';
162 162
             if ($application !== null) {
163 163
                 $templatePath = $application->getTemplateDir();
164 164
             }
165
-            $templatePath = $templatePath . $template . '.php';
165
+            $templatePath = $templatePath.$template.'.php';
166 166
             return $templatePath;
167 167
         }
168 168
     }
Please login to merge, or discard this patch.
src/components/CmsComponent.php 2 patches
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -1,18 +1,18 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace CloudControl\Cms\components {
3 3
 
4
-    use CloudControl\Cms\components\cms\ConfigurationRouting;
5
-    use CloudControl\Cms\components\cms\DocumentRouting;
6
-    use CloudControl\Cms\components\cms\FilesRouting;
7
-    use CloudControl\Cms\components\cms\ImagesRouting;
8
-    use CloudControl\Cms\components\cms\SearchRouting;
9
-    use CloudControl\Cms\components\cms\SitemapRouting;
10
-    use CloudControl\Cms\crypt\Crypt;
11
-    use CloudControl\Cms\storage\Storage;
12
-
13
-    class CmsComponent extends BaseComponent
4
+	use CloudControl\Cms\components\cms\ConfigurationRouting;
5
+	use CloudControl\Cms\components\cms\DocumentRouting;
6
+	use CloudControl\Cms\components\cms\FilesRouting;
7
+	use CloudControl\Cms\components\cms\ImagesRouting;
8
+	use CloudControl\Cms\components\cms\SearchRouting;
9
+	use CloudControl\Cms\components\cms\SitemapRouting;
10
+	use CloudControl\Cms\crypt\Crypt;
11
+	use CloudControl\Cms\storage\Storage;
12
+
13
+	class CmsComponent extends BaseComponent
14 14
 	{
15
-        /**
15
+		/**
16 16
 		 * @var \CloudControl\Cms\storage\Storage
17 17
 		 */
18 18
 		public $storage;
@@ -41,8 +41,8 @@  discard block
 block discarded – undo
41 41
 		const PARAMETER_IMAGE_SET = 'imageSet';
42 42
 		const PARAMETER_MAIN_NAV_CLASS = 'mainNavClass';
43 43
 		const PARAMETER_MY_BRICK_SLUG = 'myBrickSlug';
44
-        const PARAMETER_REDIRECT = 'redirect';
45
-        const PARAMETER_REDIRECTS = 'redirects';
44
+		const PARAMETER_REDIRECT = 'redirect';
45
+		const PARAMETER_REDIRECTS = 'redirects';
46 46
 		const PARAMETER_SEARCH = 'search';
47 47
 		const PARAMETER_SEARCH_LOG = "searchLog";
48 48
 		const PARAMETER_SEARCH_NEEDS_UPDATE = "searchNeedsUpdate";
@@ -57,14 +57,14 @@  discard block
 block discarded – undo
57 57
 		const PARAMETER_VALUELISTS = "valuelists";
58 58
 		const PARAMETER_WHITELIST_IPS = 'whitelistIps';
59 59
 
60
-        const POST_PARAMETER_COMPONENT = 'component';
61
-        const POST_PARAMETER_FROM_URL = "fromUrl";
62
-        const POST_PARAMETER_PASSWORD = 'password';
63
-        const POST_PARAMETER_SAVE = 'save';
64
-        const POST_PARAMETER_TEMPLATE = 'template';
65
-        const POST_PARAMETER_TITLE = 'title';
66
-        const POST_PARAMETER_TO_URL = "toUrl";
67
-        const POST_PARAMETER_USERNAME = 'username';
60
+		const POST_PARAMETER_COMPONENT = 'component';
61
+		const POST_PARAMETER_FROM_URL = "fromUrl";
62
+		const POST_PARAMETER_PASSWORD = 'password';
63
+		const POST_PARAMETER_SAVE = 'save';
64
+		const POST_PARAMETER_TEMPLATE = 'template';
65
+		const POST_PARAMETER_TITLE = 'title';
66
+		const POST_PARAMETER_TO_URL = "toUrl";
67
+		const POST_PARAMETER_USERNAME = 'username';
68 68
 
69 69
 		const GET_PARAMETER_PATH = 'path';
70 70
 		const GET_PARAMETER_SLUG = 'slug';
@@ -369,9 +369,9 @@  discard block
 block discarded – undo
369 369
 			}
370 370
 		}
371 371
 
372
-        protected function getTemplateDir($template, $application = null)
373
-        {
374
-            return __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $template . '.php';
375
-        }
376
-    }
372
+		protected function getTemplateDir($template, $application = null)
373
+		{
374
+			return __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $template . '.php';
375
+		}
376
+	}
377 377
 }
378 378
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 				$whitelistIps = explode(',', $this->parameters[self::PARAMETER_WHITELIST_IPS]);
171 171
 				$whitelistIps = array_map("trim", $whitelistIps);
172 172
 				if (!in_array($remoteAddress, $whitelistIps)) {
173
-					throw new \Exception('Ip address ' . $remoteAddress . ' is not on whitelist');
173
+					throw new \Exception('Ip address '.$remoteAddress.' is not on whitelist');
174 174
 				}
175 175
 			}
176 176
 		}
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 				$blacklistIps = explode(',', $this->parameters[self::PARAMETER_BLACKLIST_IPS]);
187 187
 				$blacklistIps = array_map("trim", $blacklistIps);
188 188
 				if (in_array($remoteAddress, $blacklistIps)) {
189
-					throw new \Exception('Ip address ' . $remoteAddress . ' is on blacklist');
189
+					throw new \Exception('Ip address '.$remoteAddress.' is on blacklist');
190 190
 				}
191 191
 			}
192 192
 		}
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 			if ($relativeCmsUri == '/log-off') {
231 231
 				$_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL] = null;
232 232
 				unset($_SESSION[self::SESSION_PARAMETER_CLOUD_CONTROL]);
233
-				header('Location: ' . $request::$subfolders . $this->parameters[self::PARAMETER_CMS_PREFIX]);
233
+				header('Location: '.$request::$subfolders.$this->parameters[self::PARAMETER_CMS_PREFIX]);
234 234
 				exit;
235 235
 			}
236 236
 		}
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
 
372 372
         protected function getTemplateDir($template, $application = null)
373 373
         {
374
-            return __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $template . '.php';
374
+            return __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR.$template.'.php';
375 375
         }
376 376
     }
377 377
 }
378 378
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/cms/FilesRouting.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -40,20 +40,20 @@  discard block
 block discarded – undo
40 40
 	{
41 41
 		$file = $cmsComponent->storage->getFiles()->getFileByName($slug);
42 42
 		$path = realpath($cmsComponent->storage->getFiles()->getFilesDir());
43
-		$quoted = sprintf('"%s"', addcslashes(basename($path . '/' . $file->file), '"\\'));
44
-		$size = filesize($path . '/' . $file->file);
43
+		$quoted = sprintf('"%s"', addcslashes(basename($path.'/'.$file->file), '"\\'));
44
+		$size = filesize($path.'/'.$file->file);
45 45
 
46 46
 		header('Content-Description: File Transfer');
47
-		header('Content-Type: ' . $file->type);
48
-		header('Content-Disposition: attachment; filename=' . $quoted);
47
+		header('Content-Type: '.$file->type);
48
+		header('Content-Disposition: attachment; filename='.$quoted);
49 49
 		header('Content-Transfer-Encoding: binary');
50 50
 		header('Connection: Keep-Alive');
51 51
 		header('Expires: 0');
52 52
 		header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
53 53
 		header('Pragma: public');
54
-		header('Content-Length: ' . $size);
54
+		header('Content-Length: '.$size);
55 55
 
56
-		readfile($path . '/' . $file->file);
56
+		readfile($path.'/'.$file->file);
57 57
 		exit;
58 58
 	}
59 59
 
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 		$cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_FILES);
78 78
 		if (isset($_FILES[CmsComponent::FILES_PARAMETER_FILE])) {
79 79
 			$cmsComponent->storage->getFiles()->addFile($_FILES[CmsComponent::FILES_PARAMETER_FILE]);
80
-			header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/files');
80
+			header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/files');
81 81
 			exit;
82 82
 		}
83 83
 	}
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 	private function deleteRoute($request, $cmsComponent)
90 90
 	{
91 91
 		$cmsComponent->storage->getFiles()->deleteFileByName($request::$get[CmsComponent::FILES_PARAMETER_FILE]);
92
-		header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/files');
92
+		header('Location: '.$request::$subfolders.$cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX).'/files');
93 93
 		exit;
94 94
 	}
95 95
 
Please login to merge, or discard this patch.
src/util/functions.php 2 patches
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -9,15 +9,15 @@  discard block
 block discarded – undo
9 9
  */
10 10
 function dump()
11 11
 {
12
-    $debug_backtrace = current(debug_backtrace());
13
-    if (PHP_SAPI == 'cli') {
14
-        echo 'Dump: ' . $debug_backtrace['file'] . ':' . $debug_backtrace['line'] . "\n";
15
-        foreach (func_get_args() as $data) {
16
-            var_dump($data);
17
-        }
18
-    } else {
19
-        ob_clean();
20
-        echo <<<END
12
+	$debug_backtrace = current(debug_backtrace());
13
+	if (PHP_SAPI == 'cli') {
14
+		echo 'Dump: ' . $debug_backtrace['file'] . ':' . $debug_backtrace['line'] . "\n";
15
+		foreach (func_get_args() as $data) {
16
+			var_dump($data);
17
+		}
18
+	} else {
19
+		ob_clean();
20
+		echo <<<END
21 21
 <!DOCTYPE html>
22 22
 <html>
23 23
 <head>
@@ -29,20 +29,20 @@  discard block
 block discarded – undo
29 29
 <body>
30 30
 END;
31 31
 
32
-        echo '<div>Dump: ' . $debug_backtrace['file'] . ':<b>' . $debug_backtrace['line'] . "</b></div>";
33
-        echo '<pre>';
34
-        foreach (func_get_args() as $data) {
35
-            echo "<code>";
36
-            var_dump($data);
37
-            echo "</code>";
38
-        }
39
-        echo '</pre>';
40
-        echo <<<END
32
+		echo '<div>Dump: ' . $debug_backtrace['file'] . ':<b>' . $debug_backtrace['line'] . "</b></div>";
33
+		echo '<pre>';
34
+		foreach (func_get_args() as $data) {
35
+			echo "<code>";
36
+			var_dump($data);
37
+			echo "</code>";
38
+		}
39
+		echo '</pre>';
40
+		echo <<<END
41 41
 </body>
42 42
 </html>
43 43
 END;
44
-    }
45
-    die;
44
+	}
45
+	die;
46 46
 }
47 47
 
48 48
 /**
@@ -53,27 +53,27 @@  discard block
 block discarded – undo
53 53
  */
54 54
 function sanitize_output($buffer)
55 55
 {
56
-    if (!isset($_GET['unsanitized'])) {
57
-        $search = array(
58
-            '/\>[^\S ]+/s',     // strip whitespaces after tags, except space
59
-            '/[^\S ]+\</s',     // strip whitespaces before tags, except space
60
-            '/(\s)+/s',         // shorten multiple whitespace sequences
61
-            '/<!--(.|\s)*?-->/' // Remove HTML comments
62
-        );
56
+	if (!isset($_GET['unsanitized'])) {
57
+		$search = array(
58
+			'/\>[^\S ]+/s',     // strip whitespaces after tags, except space
59
+			'/[^\S ]+\</s',     // strip whitespaces before tags, except space
60
+			'/(\s)+/s',         // shorten multiple whitespace sequences
61
+			'/<!--(.|\s)*?-->/' // Remove HTML comments
62
+		);
63 63
 
64
-        $replace = array(
65
-            '>',
66
-            '<',
67
-            '\\1',
68
-            ''
69
-        );
64
+		$replace = array(
65
+			'>',
66
+			'<',
67
+			'\\1',
68
+			''
69
+		);
70 70
 
71
-        $buffer = preg_replace($search, $replace, $buffer);
71
+		$buffer = preg_replace($search, $replace, $buffer);
72 72
 
73
-        return $buffer;
74
-    } else {
75
-        return $buffer;
76
-    }
73
+		return $buffer;
74
+	} else {
75
+		return $buffer;
76
+	}
77 77
 }
78 78
 
79 79
 
@@ -85,13 +85,13 @@  discard block
 block discarded – undo
85 85
  */
86 86
 function utf8Convert($array)
87 87
 {
88
-    array_walk_recursive($array, function (&$item) {
89
-        if (!mb_detect_encoding($item, 'utf-8', true)) {
90
-            $item = utf8_encode($item);
91
-        }
92
-    });
88
+	array_walk_recursive($array, function (&$item) {
89
+		if (!mb_detect_encoding($item, 'utf-8', true)) {
90
+			$item = utf8_encode($item);
91
+		}
92
+	});
93 93
 
94
-    return $array;
94
+	return $array;
95 95
 }
96 96
 
97 97
 /**
@@ -104,37 +104,37 @@  discard block
 block discarded – undo
104 104
  */
105 105
 function getRelativePath($from, $to)
106 106
 {
107
-    // some compatibility fixes for Windows paths
108
-    $from = is_dir($from) ? rtrim($from, '\/') . DIRECTORY_SEPARATOR : $from;
109
-    $to = is_dir($to) ? rtrim($to, '\/') . DIRECTORY_SEPARATOR : $to;
110
-    $from = str_replace('\\', DIRECTORY_SEPARATOR, $from);
111
-    $to = str_replace('\\', DIRECTORY_SEPARATOR, $to);
107
+	// some compatibility fixes for Windows paths
108
+	$from = is_dir($from) ? rtrim($from, '\/') . DIRECTORY_SEPARATOR : $from;
109
+	$to = is_dir($to) ? rtrim($to, '\/') . DIRECTORY_SEPARATOR : $to;
110
+	$from = str_replace('\\', DIRECTORY_SEPARATOR, $from);
111
+	$to = str_replace('\\', DIRECTORY_SEPARATOR, $to);
112 112
 
113
-    $from = explode(DIRECTORY_SEPARATOR, $from);
114
-    $to = explode(DIRECTORY_SEPARATOR, $to);
115
-    $relPath = $to;
113
+	$from = explode(DIRECTORY_SEPARATOR, $from);
114
+	$to = explode(DIRECTORY_SEPARATOR, $to);
115
+	$relPath = $to;
116 116
 
117
-    foreach ($from as $depth => $dir) {
118
-        // find first non-matching dir
119
-        if ($dir === $to[$depth]) {
120
-            // ignore this directory
121
-            array_shift($relPath);
122
-        } else {
123
-            // get number of remaining dirs to $from
124
-            $remaining = count($from) - $depth;
125
-            if ($remaining > 1) {
126
-                // add traversals up to first matching dir
127
-                $padLength = (count($relPath) + $remaining - 1) * -1;
128
-                $relPath = array_pad($relPath, $padLength, '..');
129
-                break;
130
-            } else {
131
-                $relPath[0] = '.' . DIRECTORY_SEPARATOR . $relPath[0];
132
-            }
133
-        }
134
-    }
135
-    $relPath = implode(DIRECTORY_SEPARATOR, $relPath);
136
-    while (strpos($relPath, '.' . DIRECTORY_SEPARATOR . '.' . DIRECTORY_SEPARATOR) !== false) {
137
-        $relPath = str_replace('.' . DIRECTORY_SEPARATOR . '.' . DIRECTORY_SEPARATOR, '.' . DIRECTORY_SEPARATOR, $relPath);
138
-    }
139
-    return $relPath;
117
+	foreach ($from as $depth => $dir) {
118
+		// find first non-matching dir
119
+		if ($dir === $to[$depth]) {
120
+			// ignore this directory
121
+			array_shift($relPath);
122
+		} else {
123
+			// get number of remaining dirs to $from
124
+			$remaining = count($from) - $depth;
125
+			if ($remaining > 1) {
126
+				// add traversals up to first matching dir
127
+				$padLength = (count($relPath) + $remaining - 1) * -1;
128
+				$relPath = array_pad($relPath, $padLength, '..');
129
+				break;
130
+			} else {
131
+				$relPath[0] = '.' . DIRECTORY_SEPARATOR . $relPath[0];
132
+			}
133
+		}
134
+	}
135
+	$relPath = implode(DIRECTORY_SEPARATOR, $relPath);
136
+	while (strpos($relPath, '.' . DIRECTORY_SEPARATOR . '.' . DIRECTORY_SEPARATOR) !== false) {
137
+		$relPath = str_replace('.' . DIRECTORY_SEPARATOR . '.' . DIRECTORY_SEPARATOR, '.' . DIRECTORY_SEPARATOR, $relPath);
138
+	}
139
+	return $relPath;
140 140
 }
141 141
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 {
12 12
     $debug_backtrace = current(debug_backtrace());
13 13
     if (PHP_SAPI == 'cli') {
14
-        echo 'Dump: ' . $debug_backtrace['file'] . ':' . $debug_backtrace['line'] . "\n";
14
+        echo 'Dump: '.$debug_backtrace['file'].':'.$debug_backtrace['line']."\n";
15 15
         foreach (func_get_args() as $data) {
16 16
             var_dump($data);
17 17
         }
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 <body>
30 30
 END;
31 31
 
32
-        echo '<div>Dump: ' . $debug_backtrace['file'] . ':<b>' . $debug_backtrace['line'] . "</b></div>";
32
+        echo '<div>Dump: '.$debug_backtrace['file'].':<b>'.$debug_backtrace['line']."</b></div>";
33 33
         echo '<pre>';
34 34
         foreach (func_get_args() as $data) {
35 35
             echo "<code>";
@@ -55,9 +55,9 @@  discard block
 block discarded – undo
55 55
 {
56 56
     if (!isset($_GET['unsanitized'])) {
57 57
         $search = array(
58
-            '/\>[^\S ]+/s',     // strip whitespaces after tags, except space
59
-            '/[^\S ]+\</s',     // strip whitespaces before tags, except space
60
-            '/(\s)+/s',         // shorten multiple whitespace sequences
58
+            '/\>[^\S ]+/s', // strip whitespaces after tags, except space
59
+            '/[^\S ]+\</s', // strip whitespaces before tags, except space
60
+            '/(\s)+/s', // shorten multiple whitespace sequences
61 61
             '/<!--(.|\s)*?-->/' // Remove HTML comments
62 62
         );
63 63
 
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
  */
86 86
 function utf8Convert($array)
87 87
 {
88
-    array_walk_recursive($array, function (&$item) {
88
+    array_walk_recursive($array, function(&$item) {
89 89
         if (!mb_detect_encoding($item, 'utf-8', true)) {
90 90
             $item = utf8_encode($item);
91 91
         }
@@ -105,8 +105,8 @@  discard block
 block discarded – undo
105 105
 function getRelativePath($from, $to)
106 106
 {
107 107
     // some compatibility fixes for Windows paths
108
-    $from = is_dir($from) ? rtrim($from, '\/') . DIRECTORY_SEPARATOR : $from;
109
-    $to = is_dir($to) ? rtrim($to, '\/') . DIRECTORY_SEPARATOR : $to;
108
+    $from = is_dir($from) ? rtrim($from, '\/').DIRECTORY_SEPARATOR : $from;
109
+    $to = is_dir($to) ? rtrim($to, '\/').DIRECTORY_SEPARATOR : $to;
110 110
     $from = str_replace('\\', DIRECTORY_SEPARATOR, $from);
111 111
     $to = str_replace('\\', DIRECTORY_SEPARATOR, $to);
112 112
 
@@ -128,13 +128,13 @@  discard block
 block discarded – undo
128 128
                 $relPath = array_pad($relPath, $padLength, '..');
129 129
                 break;
130 130
             } else {
131
-                $relPath[0] = '.' . DIRECTORY_SEPARATOR . $relPath[0];
131
+                $relPath[0] = '.'.DIRECTORY_SEPARATOR.$relPath[0];
132 132
             }
133 133
         }
134 134
     }
135 135
     $relPath = implode(DIRECTORY_SEPARATOR, $relPath);
136
-    while (strpos($relPath, '.' . DIRECTORY_SEPARATOR . '.' . DIRECTORY_SEPARATOR) !== false) {
137
-        $relPath = str_replace('.' . DIRECTORY_SEPARATOR . '.' . DIRECTORY_SEPARATOR, '.' . DIRECTORY_SEPARATOR, $relPath);
136
+    while (strpos($relPath, '.'.DIRECTORY_SEPARATOR.'.'.DIRECTORY_SEPARATOR) !== false) {
137
+        $relPath = str_replace('.'.DIRECTORY_SEPARATOR.'.'.DIRECTORY_SEPARATOR, '.'.DIRECTORY_SEPARATOR, $relPath);
138 138
     }
139 139
     return $relPath;
140 140
 }
141 141
\ No newline at end of file
Please login to merge, or discard this patch.
src/storage/Repository.php 2 patches
Indentation   +329 added lines, -329 removed lines patch added patch discarded remove patch
@@ -24,210 +24,210 @@  discard block
 block discarded – undo
24 24
  */
25 25
 class Repository
26 26
 {
27
-    protected $storagePath;
28
-
29
-    protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users', 'valuelists', 'redirects');
30
-
31
-    protected $sitemap;
32
-    protected $sitemapChanges = false;
33
-
34
-    protected $applicationComponents;
35
-    protected $applicationComponentsChanges = false;
36
-
37
-    protected $documentTypes;
38
-    protected $documentTypesChanges = false;
39
-
40
-    protected $bricks;
41
-    protected $bricksChanges = false;
42
-
43
-    protected $imageSet;
44
-    protected $imageSetChanges = false;
45
-
46
-    protected $images;
47
-    protected $imagesChanges = false;
48
-
49
-    protected $files;
50
-    protected $filesChanges = false;
51
-
52
-    protected $users;
53
-    protected $usersChanges = false;
54
-
55
-    protected $valuelists;
56
-    protected $valuelistsChanges = false;
57
-
58
-    protected $redirects;
59
-    protected $redirectsChanges = false;
60
-
61
-    protected $contentDbHandle;
62
-
63
-
64
-    /**
65
-     * Repository constructor.
66
-     * @param $storagePath
67
-     * @throws \Exception
68
-     */
69
-    public function __construct($storagePath)
70
-    {
71
-        $storagePath = realpath($storagePath);
72
-        if (is_dir($storagePath) && $storagePath !== false) {
73
-            $this->storagePath = $storagePath;
74
-        } else {
75
-            throw new \Exception('Repository not yet initialized.');
76
-        }
77
-    }
78
-
79
-    /**
80
-     * Creates the folder in which to create all storage related files
81
-     *
82
-     * @param $storagePath
83
-     * @return bool
84
-     */
85
-    public static function create($storagePath)
86
-    {
87
-        return mkdir($storagePath);
88
-    }
89
-
90
-    /**
91
-     * Initiates default storage
92
-     * @param $baseStorageDefaultPath
93
-     * @param $baseStorageSqlPath
94
-     */
95
-    public function init($baseStorageDefaultPath, $baseStorageSqlPath)
96
-    {
97
-        $storageDefaultPath = realpath($baseStorageDefaultPath);
98
-        $contentSqlPath = realpath($baseStorageSqlPath);
99
-
100
-        $this->initConfigStorage($storageDefaultPath);
101
-        $this->initContentDb($contentSqlPath);
102
-
103
-        $this->save();
104
-    }
105
-
106
-    /**
107
-     * Load filebased subset and return it's contents
108
-     *
109
-     * @param $name
110
-     * @return mixed|string
111
-     * @throws \Exception
112
-     */
113
-    public function __get($name)
114
-    {
115
-        if (isset($this->$name)) {
116
-            if (in_array($name, $this->fileBasedSubsets)) {
117
-                return $this->$name;
118
-            } else {
119
-                throw new \Exception('Trying to get undefined property from Repository: ' . $name);
120
-            }
121
-        } else {
122
-            if (in_array($name, $this->fileBasedSubsets)) {
123
-                return $this->loadSubset($name);
124
-            } else {
125
-                throw new \Exception('Trying to get undefined property from Repository: ' . $name);
126
-            }
127
-        }
128
-    }
129
-
130
-    /**
131
-     * Set filebased subset contents
132
-     * @param $name
133
-     * @param $value
134
-     * @throws \Exception
135
-     */
136
-    public function __set($name, $value)
137
-    {
138
-        if (in_array($name, $this->fileBasedSubsets)) {
139
-            $this->$name = $value;
140
-            $changes = $name . 'Changes';
141
-            $this->$changes = true;
142
-        } else {
143
-            throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>');
144
-        }
145
-    }
146
-
147
-    /**
148
-     * Persist all subsets
149
-     */
150
-    public function save()
151
-    {
152
-        $host = $this;
153
-        array_map(function ($value) use ($host) {
154
-            $host->saveSubset($value);
27
+	protected $storagePath;
28
+
29
+	protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users', 'valuelists', 'redirects');
30
+
31
+	protected $sitemap;
32
+	protected $sitemapChanges = false;
33
+
34
+	protected $applicationComponents;
35
+	protected $applicationComponentsChanges = false;
36
+
37
+	protected $documentTypes;
38
+	protected $documentTypesChanges = false;
39
+
40
+	protected $bricks;
41
+	protected $bricksChanges = false;
42
+
43
+	protected $imageSet;
44
+	protected $imageSetChanges = false;
45
+
46
+	protected $images;
47
+	protected $imagesChanges = false;
48
+
49
+	protected $files;
50
+	protected $filesChanges = false;
51
+
52
+	protected $users;
53
+	protected $usersChanges = false;
54
+
55
+	protected $valuelists;
56
+	protected $valuelistsChanges = false;
57
+
58
+	protected $redirects;
59
+	protected $redirectsChanges = false;
60
+
61
+	protected $contentDbHandle;
62
+
63
+
64
+	/**
65
+	 * Repository constructor.
66
+	 * @param $storagePath
67
+	 * @throws \Exception
68
+	 */
69
+	public function __construct($storagePath)
70
+	{
71
+		$storagePath = realpath($storagePath);
72
+		if (is_dir($storagePath) && $storagePath !== false) {
73
+			$this->storagePath = $storagePath;
74
+		} else {
75
+			throw new \Exception('Repository not yet initialized.');
76
+		}
77
+	}
78
+
79
+	/**
80
+	 * Creates the folder in which to create all storage related files
81
+	 *
82
+	 * @param $storagePath
83
+	 * @return bool
84
+	 */
85
+	public static function create($storagePath)
86
+	{
87
+		return mkdir($storagePath);
88
+	}
89
+
90
+	/**
91
+	 * Initiates default storage
92
+	 * @param $baseStorageDefaultPath
93
+	 * @param $baseStorageSqlPath
94
+	 */
95
+	public function init($baseStorageDefaultPath, $baseStorageSqlPath)
96
+	{
97
+		$storageDefaultPath = realpath($baseStorageDefaultPath);
98
+		$contentSqlPath = realpath($baseStorageSqlPath);
99
+
100
+		$this->initConfigStorage($storageDefaultPath);
101
+		$this->initContentDb($contentSqlPath);
102
+
103
+		$this->save();
104
+	}
105
+
106
+	/**
107
+	 * Load filebased subset and return it's contents
108
+	 *
109
+	 * @param $name
110
+	 * @return mixed|string
111
+	 * @throws \Exception
112
+	 */
113
+	public function __get($name)
114
+	{
115
+		if (isset($this->$name)) {
116
+			if (in_array($name, $this->fileBasedSubsets)) {
117
+				return $this->$name;
118
+			} else {
119
+				throw new \Exception('Trying to get undefined property from Repository: ' . $name);
120
+			}
121
+		} else {
122
+			if (in_array($name, $this->fileBasedSubsets)) {
123
+				return $this->loadSubset($name);
124
+			} else {
125
+				throw new \Exception('Trying to get undefined property from Repository: ' . $name);
126
+			}
127
+		}
128
+	}
129
+
130
+	/**
131
+	 * Set filebased subset contents
132
+	 * @param $name
133
+	 * @param $value
134
+	 * @throws \Exception
135
+	 */
136
+	public function __set($name, $value)
137
+	{
138
+		if (in_array($name, $this->fileBasedSubsets)) {
139
+			$this->$name = $value;
140
+			$changes = $name . 'Changes';
141
+			$this->$changes = true;
142
+		} else {
143
+			throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>');
144
+		}
145
+	}
146
+
147
+	/**
148
+	 * Persist all subsets
149
+	 */
150
+	public function save()
151
+	{
152
+		$host = $this;
153
+		array_map(function ($value) use ($host) {
154
+			$host->saveSubset($value);
155 155
 		}, $this->fileBasedSubsets);
156
-    }
157
-
158
-    /**
159
-     * Persist subset to disk
160
-     * @param $subset
161
-     */
162
-    public function saveSubset($subset)
163
-    {
156
+	}
157
+
158
+	/**
159
+	 * Persist subset to disk
160
+	 * @param $subset
161
+	 */
162
+	public function saveSubset($subset)
163
+	{
164 164
 		$changes = $subset . 'Changes';
165 165
 		if ($this->$changes === true) {
166
-            if (!defined('JSON_PRETTY_PRINT')) {
167
-                $json = json_encode($this->$subset);
168
-            } else {
169
-                $json = json_encode($this->$subset, JSON_PRETTY_PRINT);
170
-            }
166
+			if (!defined('JSON_PRETTY_PRINT')) {
167
+				$json = json_encode($this->$subset);
168
+			} else {
169
+				$json = json_encode($this->$subset, JSON_PRETTY_PRINT);
170
+			}
171 171
 			$subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json';
172 172
 			file_put_contents($subsetStoragePath, $json);
173 173
 
174 174
 			$this->$changes = false;
175 175
 		}
176
-    }
177
-
178
-    /**
179
-     * Load subset from disk
180
-     * @param $subset
181
-     * @return mixed|string
182
-     */
183
-    protected function loadSubset($subset)
184
-    {
185
-        $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json';
186
-        $json = file_get_contents($subsetStoragePath);
187
-        $json = json_decode($json);
188
-        $this->$subset = $json;
189
-        return $json;
190
-    }
191
-
192
-    /**
193
-     * @param $contentSqlPath
194
-     */
195
-    protected function initContentDb($contentSqlPath)
196
-    {
197
-        $db = $this->getContentDbHandle();
198
-        $sql = file_get_contents($contentSqlPath);
199
-        $db->exec($sql);
200
-    }
201
-
202
-    /**
203
-     * @param $storageDefaultPath
204
-     */
205
-    protected function initConfigStorage($storageDefaultPath)
206
-    {
207
-        $json = file_get_contents($storageDefaultPath);
208
-        $json = json_decode($json);
209
-        $this->initConfigIfNotExists($json, 'sitemap');
210
-        $this->initConfigIfNotExists($json, 'applicationComponents');
211
-        $this->initConfigIfNotExists($json, 'documentTypes');
212
-        $this->initConfigIfNotExists($json, 'bricks');
213
-        $this->initConfigIfNotExists($json, 'imageSet');
214
-        $this->initConfigIfNotExists($json, 'images');
215
-        $this->initConfigIfNotExists($json, 'files');
216
-        $this->initConfigIfNotExists($json, 'users');
217
-        $this->initConfigIfNotExists($json, 'valuelists');
218
-        $this->initConfigIfNotExists($json, 'redirects');
219
-    }
220
-
221
-    /**
222
-     * @return \PDO
223
-     */
224
-    public function getContentDbHandle()
225
-    {
226
-        if ($this->contentDbHandle === null) {
227
-            $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db');
228
-        }
229
-        return $this->contentDbHandle;
230
-    }
176
+	}
177
+
178
+	/**
179
+	 * Load subset from disk
180
+	 * @param $subset
181
+	 * @return mixed|string
182
+	 */
183
+	protected function loadSubset($subset)
184
+	{
185
+		$subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json';
186
+		$json = file_get_contents($subsetStoragePath);
187
+		$json = json_decode($json);
188
+		$this->$subset = $json;
189
+		return $json;
190
+	}
191
+
192
+	/**
193
+	 * @param $contentSqlPath
194
+	 */
195
+	protected function initContentDb($contentSqlPath)
196
+	{
197
+		$db = $this->getContentDbHandle();
198
+		$sql = file_get_contents($contentSqlPath);
199
+		$db->exec($sql);
200
+	}
201
+
202
+	/**
203
+	 * @param $storageDefaultPath
204
+	 */
205
+	protected function initConfigStorage($storageDefaultPath)
206
+	{
207
+		$json = file_get_contents($storageDefaultPath);
208
+		$json = json_decode($json);
209
+		$this->initConfigIfNotExists($json, 'sitemap');
210
+		$this->initConfigIfNotExists($json, 'applicationComponents');
211
+		$this->initConfigIfNotExists($json, 'documentTypes');
212
+		$this->initConfigIfNotExists($json, 'bricks');
213
+		$this->initConfigIfNotExists($json, 'imageSet');
214
+		$this->initConfigIfNotExists($json, 'images');
215
+		$this->initConfigIfNotExists($json, 'files');
216
+		$this->initConfigIfNotExists($json, 'users');
217
+		$this->initConfigIfNotExists($json, 'valuelists');
218
+		$this->initConfigIfNotExists($json, 'redirects');
219
+	}
220
+
221
+	/**
222
+	 * @return \PDO
223
+	 */
224
+	public function getContentDbHandle()
225
+	{
226
+		if ($this->contentDbHandle === null) {
227
+			$this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db');
228
+		}
229
+		return $this->contentDbHandle;
230
+	}
231 231
 
232 232
 	/**
233 233
 	 * Get all documents
@@ -237,13 +237,13 @@  discard block
 block discarded – undo
237 237
 	 * @return array
238 238
 	 * @throws \Exception
239 239
 	 */
240
-    public function getDocuments($state = 'published')
241
-    {
240
+	public function getDocuments($state = 'published')
241
+	{
242 242
 		if (!in_array($state, Document::$DOCUMENT_STATES)) {
243 243
 			throw new \Exception('Unsupported document state: ' . $state);
244 244
 		}
245
-        return $this->getDocumentsByPath('/', $state);
246
-    }
245
+		return $this->getDocumentsByPath('/', $state);
246
+	}
247 247
 
248 248
 	public function getDocumentsWithState($folderPath = '/')
249 249
 	{
@@ -290,51 +290,51 @@  discard block
 block discarded – undo
290 290
 	 * @return array
291 291
 	 * @throws \Exception
292 292
 	 */
293
-    public function getDocumentsByPath($folderPath, $state = 'published')
294
-    {
295
-    	if (!in_array($state, Document::$DOCUMENT_STATES)) {
296
-    		throw new \Exception('Unsupported document state: ' . $state);
293
+	public function getDocumentsByPath($folderPath, $state = 'published')
294
+	{
295
+		if (!in_array($state, Document::$DOCUMENT_STATES)) {
296
+			throw new \Exception('Unsupported document state: ' . $state);
297 297
 		}
298
-        $db = $this->getContentDbHandle();
299
-        $folderPathWithWildcard = $folderPath . '%';
298
+		$db = $this->getContentDbHandle();
299
+		$folderPathWithWildcard = $folderPath . '%';
300 300
 
301
-        $sql = 'SELECT *
301
+		$sql = 'SELECT *
302 302
               FROM documents_' . $state . '
303 303
              WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard) . '
304 304
                AND substr(`path`, ' . (strlen($folderPath) + 1) . ') NOT LIKE "%/%"
305 305
                AND path != ' . $db->quote($folderPath) . '
306 306
           ORDER BY `type` DESC, `path` ASC';
307
-        $stmt = $this->getDbStatement($sql);
307
+		$stmt = $this->getDbStatement($sql);
308 308
 
309
-        $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\CloudControl\Cms\storage\Document');
310
-        foreach ($documents as $key => $document) {
309
+		$documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\CloudControl\Cms\storage\Document');
310
+		foreach ($documents as $key => $document) {
311 311
 			$documents = $this->setAssetsToDocumentFolders($document, $db, $documents, $key);
312
-        }
313
-        return $documents;
314
-    }
315
-
316
-
317
-    /**
318
-     * @param $path
319
-     * @return bool|Document
320
-     */
321
-    public function getDocumentContainerByPath($path)
322
-    {
323
-        $document = $this->getDocumentByPath($path, 'unpublished');
324
-        if ($document === false) {
325
-            return false;
326
-        }
327
-        $slugLength = strlen($document->slug);
328
-        $containerPath = substr($path, 0, -$slugLength);
329
-        if ($containerPath === '/') {
330
-            return $this->getRootFolder();
331
-        }
332
-        if (substr($containerPath, -1) === '/'){
312
+		}
313
+		return $documents;
314
+	}
315
+
316
+
317
+	/**
318
+	 * @param $path
319
+	 * @return bool|Document
320
+	 */
321
+	public function getDocumentContainerByPath($path)
322
+	{
323
+		$document = $this->getDocumentByPath($path, 'unpublished');
324
+		if ($document === false) {
325
+			return false;
326
+		}
327
+		$slugLength = strlen($document->slug);
328
+		$containerPath = substr($path, 0, -$slugLength);
329
+		if ($containerPath === '/') {
330
+			return $this->getRootFolder();
331
+		}
332
+		if (substr($containerPath, -1) === '/'){
333 333
 			$containerPath = substr($containerPath, 0, -1);
334 334
 		}
335
-        $containerFolder = $this->getDocumentByPath($containerPath, 'unpublished');
336
-        return $containerFolder;
337
-    }
335
+		$containerFolder = $this->getDocumentByPath($containerPath, 'unpublished');
336
+		return $containerFolder;
337
+	}
338 338
 
339 339
 	/**
340 340
 	 * @param        $path
@@ -343,23 +343,23 @@  discard block
 block discarded – undo
343 343
 	 * @return bool|\CloudControl\Cms\storage\Document
344 344
 	 * @throws \Exception
345 345
 	 */
346
-    public function getDocumentByPath($path, $state = 'published')
347
-    {
346
+	public function getDocumentByPath($path, $state = 'published')
347
+	{
348 348
 		if (!in_array($state, Document::$DOCUMENT_STATES)) {
349 349
 			throw new \Exception('Unsupported document state: ' . $state);
350 350
 		}
351
-        $db = $this->getContentDbHandle();
352
-        $document = $this->fetchDocument('
351
+		$db = $this->getContentDbHandle();
352
+		$document = $this->fetchDocument('
353 353
             SELECT *
354 354
               FROM documents_' .  $state . '
355 355
              WHERE path = ' . $db->quote($path) . '
356 356
         ');
357
-        if ($document instanceof Document && $document->type === 'folder') {
358
-            $document->dbHandle = $db;
359
-            $document->documentStorage = new DocumentStorage($this);
360
-        }
361
-        return $document;
362
-    }
357
+		if ($document instanceof Document && $document->type === 'folder') {
358
+			$document->dbHandle = $db;
359
+			$document->documentStorage = new DocumentStorage($this);
360
+		}
361
+		return $document;
362
+	}
363 363
 
364 364
 	/**
365 365
 	 * Returns the count of all documents stored in the db
@@ -454,58 +454,58 @@  discard block
 block discarded – undo
454 454
 	}
455 455
 
456 456
 	/**
457
-     * Return the results of the query as array of Documents
458
-     * @param $sql
459
-     * @return array
460
-     * @throws \Exception
461
-     */
462
-    protected function fetchAllDocuments($sql)
463
-    {
464
-        $stmt = $this->getDbStatement($sql);
465
-        return $stmt->fetchAll(\PDO::FETCH_CLASS, '\CloudControl\Cms\storage\Document');
466
-    }
467
-
468
-    /**
469
-     * Return the result of the query as Document
470
-     * @param $sql
471
-     * @return mixed
472
-     * @throws \Exception
473
-     */
474
-    protected function fetchDocument($sql)
475
-    {
476
-        $stmt = $this->getDbStatement($sql);
477
-        return $stmt->fetchObject('\CloudControl\Cms\storage\Document');
478
-    }
479
-
480
-    /**
481
-     * Prepare the sql statement
482
-     * @param $sql
483
-     * @return \PDOStatement
484
-     * @throws \Exception
485
-     */
486
-    protected function getDbStatement($sql)
487
-    {
488
-        $db = $this->getContentDbHandle();
489
-        $stmt = $db->query($sql);
490
-        if ($stmt === false) {
491
-            $errorInfo = $db->errorInfo();
492
-            $errorMsg = $errorInfo[2];
493
-            throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>');
494
-        }
495
-        return $stmt;
496
-    }
497
-
498
-    /**
499
-     * Create a (non-existent) root folder Document and return it
500
-     * @return Document
501
-     */
502
-    protected function getRootFolder()
503
-    {
504
-        $rootFolder = new Document();
505
-        $rootFolder->path = '/';
506
-        $rootFolder->type = 'folder';
507
-        return $rootFolder;
508
-    }
457
+	 * Return the results of the query as array of Documents
458
+	 * @param $sql
459
+	 * @return array
460
+	 * @throws \Exception
461
+	 */
462
+	protected function fetchAllDocuments($sql)
463
+	{
464
+		$stmt = $this->getDbStatement($sql);
465
+		return $stmt->fetchAll(\PDO::FETCH_CLASS, '\CloudControl\Cms\storage\Document');
466
+	}
467
+
468
+	/**
469
+	 * Return the result of the query as Document
470
+	 * @param $sql
471
+	 * @return mixed
472
+	 * @throws \Exception
473
+	 */
474
+	protected function fetchDocument($sql)
475
+	{
476
+		$stmt = $this->getDbStatement($sql);
477
+		return $stmt->fetchObject('\CloudControl\Cms\storage\Document');
478
+	}
479
+
480
+	/**
481
+	 * Prepare the sql statement
482
+	 * @param $sql
483
+	 * @return \PDOStatement
484
+	 * @throws \Exception
485
+	 */
486
+	protected function getDbStatement($sql)
487
+	{
488
+		$db = $this->getContentDbHandle();
489
+		$stmt = $db->query($sql);
490
+		if ($stmt === false) {
491
+			$errorInfo = $db->errorInfo();
492
+			$errorMsg = $errorInfo[2];
493
+			throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>');
494
+		}
495
+		return $stmt;
496
+	}
497
+
498
+	/**
499
+	 * Create a (non-existent) root folder Document and return it
500
+	 * @return Document
501
+	 */
502
+	protected function getRootFolder()
503
+	{
504
+		$rootFolder = new Document();
505
+		$rootFolder->path = '/';
506
+		$rootFolder->type = 'folder';
507
+		return $rootFolder;
508
+	}
509 509
 
510 510
 	/**
511 511
 	 * Save the document to the database
@@ -517,13 +517,13 @@  discard block
 block discarded – undo
517 517
 	 * @throws \Exception
518 518
 	 * @internal param $path
519 519
 	 */
520
-    public function saveDocument($documentObject, $state = 'published')
521
-    {
520
+	public function saveDocument($documentObject, $state = 'published')
521
+	{
522 522
 		if (!in_array($state, Document::$DOCUMENT_STATES)) {
523 523
 			throw new \Exception('Unsupported document state: ' . $state);
524 524
 		}
525
-        $db = $this->getContentDbHandle();
526
-        $stmt = $this->getDbStatement('
525
+		$db = $this->getContentDbHandle();
526
+		$stmt = $this->getDbStatement('
527 527
             INSERT OR REPLACE INTO documents_' . $state . ' (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`)
528 528
             VALUES(
529 529
               ' . $db->quote($documentObject->path) . ',
@@ -541,9 +541,9 @@  discard block
 block discarded – undo
541 541
               ' . $db->quote(json_encode($documentObject->dynamicBricks)) . '
542 542
             )
543 543
         ');
544
-        $result = $stmt->execute();
545
-        return $result;
546
-    }
544
+		$result = $stmt->execute();
545
+		return $result;
546
+	}
547 547
 
548 548
 	/**
549 549
 	 * Delete the document from the database
@@ -554,29 +554,29 @@  discard block
 block discarded – undo
554 554
 	 * @internal param string $state
555 555
 	 *
556 556
 	 */
557
-    public function deleteDocumentByPath($path)
558
-    {
559
-        $db = $this->getContentDbHandle();
560
-        $documentToDelete = $this->getDocumentByPath($path, 'unpublished');
561
-        if ($documentToDelete instanceof Document) {
562
-            if ($documentToDelete->type == 'document') {
563
-                $stmt = $this->getDbStatement('
557
+	public function deleteDocumentByPath($path)
558
+	{
559
+		$db = $this->getContentDbHandle();
560
+		$documentToDelete = $this->getDocumentByPath($path, 'unpublished');
561
+		if ($documentToDelete instanceof Document) {
562
+			if ($documentToDelete->type == 'document') {
563
+				$stmt = $this->getDbStatement('
564 564
                     DELETE FROM documents_unpublished
565 565
                           WHERE path = ' . $db->quote($path) . '
566 566
                 ');
567
-                $stmt->execute();
568
-            } elseif ($documentToDelete->type == 'folder') {
569
-                $folderPathWithWildcard = $path . '%';
570
-                $stmt = $this->getDbStatement('
567
+				$stmt->execute();
568
+			} elseif ($documentToDelete->type == 'folder') {
569
+				$folderPathWithWildcard = $path . '%';
570
+				$stmt = $this->getDbStatement('
571 571
                     DELETE FROM documents_unpublished
572 572
                           WHERE (path LIKE ' . $db->quote($folderPathWithWildcard) . '
573 573
                             AND substr(`path`, ' . (strlen($path) + 1) . ', 1) = "/")
574 574
                             OR path = ' . $db->quote($path) . '
575 575
                 ');
576
-                $stmt->execute();
577
-            }
578
-        }
579
-    }
576
+				$stmt->execute();
577
+			}
578
+		}
579
+	}
580 580
 
581 581
 	/**
582 582
 	 * @param $document
@@ -597,15 +597,15 @@  discard block
 block discarded – undo
597 597
 		return $documents;
598 598
 	}
599 599
 
600
-    private function initConfigIfNotExists($json, $subsetName)
601
-    {
602
-        $subsetFileName = $this->storagePath . DIRECTORY_SEPARATOR . $subsetName . '.json';
603
-        if (file_exists($subsetFileName)) {
604
-            $this->loadSubset($subsetName);
605
-        } else {
606
-            $changes = $subsetName . 'Changes';
607
-            $this->$subsetName = $json->$subsetName;
608
-            $this->$changes = true;
609
-        }
610
-    }
600
+	private function initConfigIfNotExists($json, $subsetName)
601
+	{
602
+		$subsetFileName = $this->storagePath . DIRECTORY_SEPARATOR . $subsetName . '.json';
603
+		if (file_exists($subsetFileName)) {
604
+			$this->loadSubset($subsetName);
605
+		} else {
606
+			$changes = $subsetName . 'Changes';
607
+			$this->$subsetName = $json->$subsetName;
608
+			$this->$changes = true;
609
+		}
610
+	}
611 611
 }
612 612
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -116,13 +116,13 @@  discard block
 block discarded – undo
116 116
             if (in_array($name, $this->fileBasedSubsets)) {
117 117
                 return $this->$name;
118 118
             } else {
119
-                throw new \Exception('Trying to get undefined property from Repository: ' . $name);
119
+                throw new \Exception('Trying to get undefined property from Repository: '.$name);
120 120
             }
121 121
         } else {
122 122
             if (in_array($name, $this->fileBasedSubsets)) {
123 123
                 return $this->loadSubset($name);
124 124
             } else {
125
-                throw new \Exception('Trying to get undefined property from Repository: ' . $name);
125
+                throw new \Exception('Trying to get undefined property from Repository: '.$name);
126 126
             }
127 127
         }
128 128
     }
@@ -137,10 +137,10 @@  discard block
 block discarded – undo
137 137
     {
138 138
         if (in_array($name, $this->fileBasedSubsets)) {
139 139
             $this->$name = $value;
140
-            $changes = $name . 'Changes';
140
+            $changes = $name.'Changes';
141 141
             $this->$changes = true;
142 142
         } else {
143
-            throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>');
143
+            throw new \Exception('Trying to persist unknown subset in repository: '.$name.' <br /><pre>'.print_r($value, true).'</pre>');
144 144
         }
145 145
     }
146 146
 
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
     public function save()
151 151
     {
152 152
         $host = $this;
153
-        array_map(function ($value) use ($host) {
153
+        array_map(function($value) use ($host) {
154 154
             $host->saveSubset($value);
155 155
 		}, $this->fileBasedSubsets);
156 156
     }
@@ -161,14 +161,14 @@  discard block
 block discarded – undo
161 161
      */
162 162
     public function saveSubset($subset)
163 163
     {
164
-		$changes = $subset . 'Changes';
164
+		$changes = $subset.'Changes';
165 165
 		if ($this->$changes === true) {
166 166
             if (!defined('JSON_PRETTY_PRINT')) {
167 167
                 $json = json_encode($this->$subset);
168 168
             } else {
169 169
                 $json = json_encode($this->$subset, JSON_PRETTY_PRINT);
170 170
             }
171
-			$subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json';
171
+			$subsetStoragePath = $this->storagePath.DIRECTORY_SEPARATOR.$subset.'.json';
172 172
 			file_put_contents($subsetStoragePath, $json);
173 173
 
174 174
 			$this->$changes = false;
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
      */
183 183
     protected function loadSubset($subset)
184 184
     {
185
-        $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json';
185
+        $subsetStoragePath = $this->storagePath.DIRECTORY_SEPARATOR.$subset.'.json';
186 186
         $json = file_get_contents($subsetStoragePath);
187 187
         $json = json_decode($json);
188 188
         $this->$subset = $json;
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
     public function getContentDbHandle()
225 225
     {
226 226
         if ($this->contentDbHandle === null) {
227
-            $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db');
227
+            $this->contentDbHandle = new \PDO('sqlite:'.$this->storagePath.DIRECTORY_SEPARATOR.'content.db');
228 228
         }
229 229
         return $this->contentDbHandle;
230 230
     }
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
     public function getDocuments($state = 'published')
241 241
     {
242 242
 		if (!in_array($state, Document::$DOCUMENT_STATES)) {
243
-			throw new \Exception('Unsupported document state: ' . $state);
243
+			throw new \Exception('Unsupported document state: '.$state);
244 244
 		}
245 245
         return $this->getDocumentsByPath('/', $state);
246 246
     }
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 	public function getDocumentsWithState($folderPath = '/')
249 249
 	{
250 250
 		$db = $this->getContentDbHandle();
251
-		$folderPathWithWildcard = $folderPath . '%';
251
+		$folderPathWithWildcard = $folderPath.'%';
252 252
 
253 253
 		$ifRootIndex = 1;
254 254
 		if ($folderPath == '/') {
@@ -263,10 +263,10 @@  discard block
 block discarded – undo
263 263
               FROM documents_unpublished
264 264
 		 LEFT JOIN documents_published
265 265
          		ON documents_published.path = documents_unpublished.path
266
-             WHERE documents_unpublished.`path` LIKE ' . $db->quote($folderPathWithWildcard) . '
267
-               AND substr(documents_unpublished.`path`, ' . (strlen($folderPath) + $ifRootIndex + 1) . ') NOT LIKE "%/%"
268
-               AND length(documents_unpublished.`path`) > ' . (strlen($folderPath) + $ifRootIndex) . '
269
-               AND documents_unpublished.path != ' . $db->quote($folderPath) . '
266
+             WHERE documents_unpublished.`path` LIKE ' . $db->quote($folderPathWithWildcard).'
267
+               AND substr(documents_unpublished.`path`, ' . (strlen($folderPath) + $ifRootIndex + 1).') NOT LIKE "%/%"
268
+               AND length(documents_unpublished.`path`) > ' . (strlen($folderPath) + $ifRootIndex).'
269
+               AND documents_unpublished.path != ' . $db->quote($folderPath).'
270 270
           ORDER BY documents_unpublished.`type` DESC, documents_unpublished.`path` ASC
271 271
         ';
272 272
 		$stmt = $this->getDbStatement($sql);
@@ -293,16 +293,16 @@  discard block
 block discarded – undo
293 293
     public function getDocumentsByPath($folderPath, $state = 'published')
294 294
     {
295 295
     	if (!in_array($state, Document::$DOCUMENT_STATES)) {
296
-    		throw new \Exception('Unsupported document state: ' . $state);
296
+    		throw new \Exception('Unsupported document state: '.$state);
297 297
 		}
298 298
         $db = $this->getContentDbHandle();
299
-        $folderPathWithWildcard = $folderPath . '%';
299
+        $folderPathWithWildcard = $folderPath.'%';
300 300
 
301 301
         $sql = 'SELECT *
302
-              FROM documents_' . $state . '
303
-             WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard) . '
304
-               AND substr(`path`, ' . (strlen($folderPath) + 1) . ') NOT LIKE "%/%"
305
-               AND path != ' . $db->quote($folderPath) . '
302
+              FROM documents_' . $state.'
303
+             WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard).'
304
+               AND substr(`path`, ' . (strlen($folderPath) + 1).') NOT LIKE "%/%"
305
+               AND path != ' . $db->quote($folderPath).'
306 306
           ORDER BY `type` DESC, `path` ASC';
307 307
         $stmt = $this->getDbStatement($sql);
308 308
 
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
         if ($containerPath === '/') {
330 330
             return $this->getRootFolder();
331 331
         }
332
-        if (substr($containerPath, -1) === '/'){
332
+        if (substr($containerPath, -1) === '/') {
333 333
 			$containerPath = substr($containerPath, 0, -1);
334 334
 		}
335 335
         $containerFolder = $this->getDocumentByPath($containerPath, 'unpublished');
@@ -346,13 +346,13 @@  discard block
 block discarded – undo
346 346
     public function getDocumentByPath($path, $state = 'published')
347 347
     {
348 348
 		if (!in_array($state, Document::$DOCUMENT_STATES)) {
349
-			throw new \Exception('Unsupported document state: ' . $state);
349
+			throw new \Exception('Unsupported document state: '.$state);
350 350
 		}
351 351
         $db = $this->getContentDbHandle();
352 352
         $document = $this->fetchDocument('
353 353
             SELECT *
354
-              FROM documents_' .  $state . '
355
-             WHERE path = ' . $db->quote($path) . '
354
+              FROM documents_' .  $state.'
355
+             WHERE path = ' . $db->quote($path).'
356 356
         ');
357 357
         if ($document instanceof Document && $document->type === 'folder') {
358 358
             $document->dbHandle = $db;
@@ -372,16 +372,16 @@  discard block
 block discarded – undo
372 372
 	public function getTotalDocumentCount($state = 'published')
373 373
 	{
374 374
 		if (!in_array($state, Document::$DOCUMENT_STATES)) {
375
-			throw new \Exception('Unsupported document state: ' . $state);
375
+			throw new \Exception('Unsupported document state: '.$state);
376 376
 		}
377 377
 		$db = $this->getContentDbHandle();
378 378
 		$stmt = $db->query('
379 379
 			SELECT count(*)
380
-			  FROM documents_' . $state . '
380
+			  FROM documents_' . $state.'
381 381
 			 WHERE `type` != "folder"
382 382
 		');
383 383
 		$result = $stmt->fetch(\PDO::FETCH_ASSOC);
384
-		if (!is_array($result )) {
384
+		if (!is_array($result)) {
385 385
 			return 0;
386 386
 		}
387 387
 		return intval(current($result));
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 		if ($stmt === false || !$stmt->execute()) {
401 401
 			$errorInfo = $db->errorInfo();
402 402
 			$errorMsg = $errorInfo[2];
403
-			throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>');
403
+			throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>');
404 404
 		}
405 405
 		return $result;
406 406
 	}
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
 			$sql = '
411 411
 				INSERT OR REPLACE INTO documents_published 
412 412
 					  (`id`,`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`publicationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`)
413
-				SELECT `id`,`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,"published" as state,`lastModificationDate`,`creationDate`,' . time() . ' as publicationDate, `lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`
413
+				SELECT `id`,`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,"published" as state,`lastModificationDate`,`creationDate`,' . time().' as publicationDate, `lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`
414 414
 				  FROM documents_unpublished
415 415
 				 WHERE `path` = :path
416 416
 			';
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
 		if ($stmt === false) {
424 424
 			$errorInfo = $db->errorInfo();
425 425
 			$errorMsg = $errorInfo[2];
426
-			throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>');
426
+			throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>');
427 427
 		}
428 428
 		$stmt->bindValue(':path', $path);
429 429
 		$stmt->execute();
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
         if ($stmt === false) {
491 491
             $errorInfo = $db->errorInfo();
492 492
             $errorMsg = $errorInfo[2];
493
-            throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>');
493
+            throw new \Exception('SQLite Exception: '.$errorMsg.' in SQL: <br /><pre>'.$sql.'</pre>');
494 494
         }
495 495
         return $stmt;
496 496
     }
@@ -520,25 +520,25 @@  discard block
 block discarded – undo
520 520
     public function saveDocument($documentObject, $state = 'published')
521 521
     {
522 522
 		if (!in_array($state, Document::$DOCUMENT_STATES)) {
523
-			throw new \Exception('Unsupported document state: ' . $state);
523
+			throw new \Exception('Unsupported document state: '.$state);
524 524
 		}
525 525
         $db = $this->getContentDbHandle();
526 526
         $stmt = $this->getDbStatement('
527
-            INSERT OR REPLACE INTO documents_' . $state . ' (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`)
527
+            INSERT OR REPLACE INTO documents_' . $state.' (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`)
528 528
             VALUES(
529
-              ' . $db->quote($documentObject->path) . ',
530
-              ' . $db->quote($documentObject->title) . ',
531
-              ' . $db->quote($documentObject->slug) . ',
532
-              ' . $db->quote($documentObject->type) . ',
533
-              ' . $db->quote($documentObject->documentType) . ',
534
-              ' . $db->quote($documentObject->documentTypeSlug) . ',
535
-              ' . $db->quote($documentObject->state) . ',
536
-              ' . $db->quote($documentObject->lastModificationDate) . ',
537
-              ' . $db->quote($documentObject->creationDate) . ',
538
-              ' . $db->quote($documentObject->lastModifiedBy) . ',
539
-              ' . $db->quote(json_encode($documentObject->fields)) . ',
540
-              ' . $db->quote(json_encode($documentObject->bricks)) . ',
541
-              ' . $db->quote(json_encode($documentObject->dynamicBricks)) . '
529
+              ' . $db->quote($documentObject->path).',
530
+              ' . $db->quote($documentObject->title).',
531
+              ' . $db->quote($documentObject->slug).',
532
+              ' . $db->quote($documentObject->type).',
533
+              ' . $db->quote($documentObject->documentType).',
534
+              ' . $db->quote($documentObject->documentTypeSlug).',
535
+              ' . $db->quote($documentObject->state).',
536
+              ' . $db->quote($documentObject->lastModificationDate).',
537
+              ' . $db->quote($documentObject->creationDate).',
538
+              ' . $db->quote($documentObject->lastModifiedBy).',
539
+              ' . $db->quote(json_encode($documentObject->fields)).',
540
+              ' . $db->quote(json_encode($documentObject->bricks)).',
541
+              ' . $db->quote(json_encode($documentObject->dynamicBricks)).'
542 542
             )
543 543
         ');
544 544
         $result = $stmt->execute();
@@ -562,16 +562,16 @@  discard block
 block discarded – undo
562 562
             if ($documentToDelete->type == 'document') {
563 563
                 $stmt = $this->getDbStatement('
564 564
                     DELETE FROM documents_unpublished
565
-                          WHERE path = ' . $db->quote($path) . '
565
+                          WHERE path = ' . $db->quote($path).'
566 566
                 ');
567 567
                 $stmt->execute();
568 568
             } elseif ($documentToDelete->type == 'folder') {
569
-                $folderPathWithWildcard = $path . '%';
569
+                $folderPathWithWildcard = $path.'%';
570 570
                 $stmt = $this->getDbStatement('
571 571
                     DELETE FROM documents_unpublished
572
-                          WHERE (path LIKE ' . $db->quote($folderPathWithWildcard) . '
573
-                            AND substr(`path`, ' . (strlen($path) + 1) . ', 1) = "/")
574
-                            OR path = ' . $db->quote($path) . '
572
+                          WHERE (path LIKE ' . $db->quote($folderPathWithWildcard).'
573
+                            AND substr(`path`, ' . (strlen($path) + 1).', 1) = "/")
574
+                            OR path = ' . $db->quote($path).'
575 575
                 ');
576 576
                 $stmt->execute();
577 577
             }
@@ -599,11 +599,11 @@  discard block
 block discarded – undo
599 599
 
600 600
     private function initConfigIfNotExists($json, $subsetName)
601 601
     {
602
-        $subsetFileName = $this->storagePath . DIRECTORY_SEPARATOR . $subsetName . '.json';
602
+        $subsetFileName = $this->storagePath.DIRECTORY_SEPARATOR.$subsetName.'.json';
603 603
         if (file_exists($subsetFileName)) {
604 604
             $this->loadSubset($subsetName);
605 605
         } else {
606
-            $changes = $subsetName . 'Changes';
606
+            $changes = $subsetName.'Changes';
607 607
             $this->$subsetName = $json->$subsetName;
608 608
             $this->$changes = true;
609 609
         }
Please login to merge, or discard this patch.
src/storage/storage/RedirectsStorage.php 1 patch
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -10,94 +10,94 @@
 block discarded – undo
10 10
 
11 11
 class RedirectsStorage extends AbstractStorage
12 12
 {
13
-    /**
14
-     * Get all redirects
15
-     *
16
-     * @return mixed
17
-     */
18
-    public function getRedirects()
19
-    {
20
-        $redirects = $this->repository->redirects;
21
-        if ($redirects === null) {
22
-            $redirects = array();
23
-        }
24
-        usort($redirects, array($this, 'cmp'));
25
-        return $redirects;
26
-    }
13
+	/**
14
+	 * Get all redirects
15
+	 *
16
+	 * @return mixed
17
+	 */
18
+	public function getRedirects()
19
+	{
20
+		$redirects = $this->repository->redirects;
21
+		if ($redirects === null) {
22
+			$redirects = array();
23
+		}
24
+		usort($redirects, array($this, 'cmp'));
25
+		return $redirects;
26
+	}
27 27
 
28
-    /**
29
-     * Add a new redirect
30
-     * @param $postValues
31
-     */
32
-    public function addRedirect($postValues) {
33
-        $redirectObject = RedirectsFactory::createRedirectFromPostValues($postValues);
34
-        $redirects = $this->repository->redirects;
35
-        $redirects[] = $redirectObject;
36
-        $this->repository->redirects = $redirects;
37
-        $this->save();
38
-    }
28
+	/**
29
+	 * Add a new redirect
30
+	 * @param $postValues
31
+	 */
32
+	public function addRedirect($postValues) {
33
+		$redirectObject = RedirectsFactory::createRedirectFromPostValues($postValues);
34
+		$redirects = $this->repository->redirects;
35
+		$redirects[] = $redirectObject;
36
+		$this->repository->redirects = $redirects;
37
+		$this->save();
38
+	}
39 39
 
40
-    /**
41
-     * Get a redirect by it's slug
42
-     *
43
-     * @param $slug
44
-     * @return \stdClass|null
45
-     */
46
-    public function getRedirectBySlug($slug)
47
-    {
48
-        $redirects = $this->repository->redirects;
49
-        foreach ($redirects as $redirect) {
50
-            if ($redirect->slug == $slug) {
51
-                return $redirect;
52
-            }
53
-        }
40
+	/**
41
+	 * Get a redirect by it's slug
42
+	 *
43
+	 * @param $slug
44
+	 * @return \stdClass|null
45
+	 */
46
+	public function getRedirectBySlug($slug)
47
+	{
48
+		$redirects = $this->repository->redirects;
49
+		foreach ($redirects as $redirect) {
50
+			if ($redirect->slug == $slug) {
51
+				return $redirect;
52
+			}
53
+		}
54 54
 
55
-        return null;
56
-    }
55
+		return null;
56
+	}
57 57
 
58
-    /**
59
-     * Save a redirect by it's slug
60
-     * @param $slug
61
-     * @param $postValues
62
-     */
63
-    public function saveRedirect($slug, $postValues)
64
-    {
65
-        $redirectObject = RedirectsFactory::createRedirectFromPostValues($postValues);
58
+	/**
59
+	 * Save a redirect by it's slug
60
+	 * @param $slug
61
+	 * @param $postValues
62
+	 */
63
+	public function saveRedirect($slug, $postValues)
64
+	{
65
+		$redirectObject = RedirectsFactory::createRedirectFromPostValues($postValues);
66 66
 
67
-        $redirects = $this->repository->redirects;
68
-        foreach ($redirects as $key => $redirect) {
69
-            if ($redirect->slug == $slug) {
70
-                $redirects[$key] = $redirectObject;
71
-            }
72
-        }
73
-        $this->repository->redirects = $redirects;
74
-        $this->save();
75
-    }
67
+		$redirects = $this->repository->redirects;
68
+		foreach ($redirects as $key => $redirect) {
69
+			if ($redirect->slug == $slug) {
70
+				$redirects[$key] = $redirectObject;
71
+			}
72
+		}
73
+		$this->repository->redirects = $redirects;
74
+		$this->save();
75
+	}
76 76
 
77
-    /**
78
-     * Delete a redirect by it's slug
79
-     * @param $slug
80
-     */
81
-    public function deleteRedirectBySlug($slug)
82
-    {
83
-        $redirects = $this->repository->redirects;
84
-        foreach ($redirects as $key => $redirect) {
85
-            if ($redirect->slug == $slug) {
86
-                unset($redirects[$key]);
87
-            }
88
-        }
89
-        $redirects = array_values($redirects);
90
-        $this->repository->redirects = $redirects;
91
-        $this->save();
92
-    }
77
+	/**
78
+	 * Delete a redirect by it's slug
79
+	 * @param $slug
80
+	 */
81
+	public function deleteRedirectBySlug($slug)
82
+	{
83
+		$redirects = $this->repository->redirects;
84
+		foreach ($redirects as $key => $redirect) {
85
+			if ($redirect->slug == $slug) {
86
+				unset($redirects[$key]);
87
+			}
88
+		}
89
+		$redirects = array_values($redirects);
90
+		$this->repository->redirects = $redirects;
91
+		$this->save();
92
+	}
93 93
 
94
-    /**
95
-     * Compare a redirect by it's title
96
-     * @param $a
97
-     * @param $b
98
-     * @return int
99
-     */
100
-    public static function cmp($a, $b) {
101
-        return strcmp($a->title, $b->title);
102
-    }
94
+	/**
95
+	 * Compare a redirect by it's title
96
+	 * @param $a
97
+	 * @param $b
98
+	 * @return int
99
+	 */
100
+	public static function cmp($a, $b) {
101
+		return strcmp($a->title, $b->title);
102
+	}
103 103
 }
104 104
\ No newline at end of file
Please login to merge, or discard this patch.