Passed
Push — master ( 67432a...b0c204 )
by Roeland
10:32 queued 10s
created
lib/private/AppFramework/App.php 2 patches
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -46,158 +46,158 @@
 block discarded – undo
46 46
  */
47 47
 class App {
48 48
 
49
-	/** @var string[] */
50
-	private static $nameSpaceCache = [];
51
-
52
-	/**
53
-	 * Turns an app id into a namespace by either reading the appinfo.xml's
54
-	 * namespace tag or uppercasing the appid's first letter
55
-	 * @param string $appId the app id
56
-	 * @param string $topNamespace the namespace which should be prepended to
57
-	 * the transformed app id, defaults to OCA\
58
-	 * @return string the starting namespace for the app
59
-	 */
60
-	public static function buildAppNamespace(string $appId, string $topNamespace='OCA\\'): string {
61
-		// Hit the cache!
62
-		if (isset(self::$nameSpaceCache[$appId])) {
63
-			return $topNamespace . self::$nameSpaceCache[$appId];
64
-		}
65
-
66
-		$appInfo = \OC_App::getAppInfo($appId);
67
-		if (isset($appInfo['namespace'])) {
68
-			self::$nameSpaceCache[$appId] = trim($appInfo['namespace']);
69
-		} else {
70
-			// if the tag is not found, fall back to uppercasing the first letter
71
-			self::$nameSpaceCache[$appId] = ucfirst($appId);
72
-		}
73
-
74
-		return $topNamespace . self::$nameSpaceCache[$appId];
75
-	}
76
-
77
-
78
-	/**
79
-	 * Shortcut for calling a controller method and printing the result
80
-	 * @param string $controllerName the name of the controller under which it is
81
-	 *                               stored in the DI container
82
-	 * @param string $methodName the method that you want to call
83
-	 * @param DIContainer $container an instance of a pimple container.
84
-	 * @param array $urlParams list of URL parameters (optional)
85
-	 * @throws HintException
86
-	 */
87
-	public static function main(string $controllerName, string $methodName, DIContainer $container, array $urlParams = null) {
88
-		if (!is_null($urlParams)) {
89
-			$container->query(IRequest::class)->setUrlParameters($urlParams);
90
-		} else if (isset($container['urlParams']) && !is_null($container['urlParams'])) {
91
-			$container->query(IRequest::class)->setUrlParameters($container['urlParams']);
92
-		}
93
-		$appName = $container['AppName'];
94
-
95
-		// first try $controllerName then go for \OCA\AppName\Controller\$controllerName
96
-		try {
97
-			$controller = $container->query($controllerName);
98
-		} catch(QueryException $e) {
99
-			if (strpos($controllerName, '\\Controller\\') !== false) {
100
-				// This is from a global registered app route that is not enabled.
101
-				[/*OC(A)*/, $app, /* Controller/Name*/] = explode('\\', $controllerName, 3);
102
-				throw new HintException('App ' . strtolower($app) . ' is not enabled');
103
-			}
104
-
105
-			if ($appName === 'core') {
106
-				$appNameSpace = 'OC\\Core';
107
-			} else if ($appName === 'settings') {
108
-				$appNameSpace = 'OC\\Settings';
109
-			} else {
110
-				$appNameSpace = self::buildAppNamespace($appName);
111
-			}
112
-			$controllerName = $appNameSpace . '\\Controller\\' . $controllerName;
113
-			$controller = $container->query($controllerName);
114
-		}
115
-
116
-		// initialize the dispatcher and run all the middleware before the controller
117
-		/** @var Dispatcher $dispatcher */
118
-		$dispatcher = $container['Dispatcher'];
119
-
120
-		list(
121
-			$httpHeaders,
122
-			$responseHeaders,
123
-			$responseCookies,
124
-			$output,
125
-			$response
126
-		) = $dispatcher->dispatch($controller, $methodName);
127
-
128
-		$io = $container[IOutput::class];
129
-
130
-		if(!is_null($httpHeaders)) {
131
-			$io->setHeader($httpHeaders);
132
-		}
133
-
134
-		foreach($responseHeaders as $name => $value) {
135
-			$io->setHeader($name . ': ' . $value);
136
-		}
137
-
138
-		foreach($responseCookies as $name => $value) {
139
-			$expireDate = null;
140
-			if($value['expireDate'] instanceof \DateTime) {
141
-				$expireDate = $value['expireDate']->getTimestamp();
142
-			}
143
-			$io->setCookie(
144
-				$name,
145
-				$value['value'],
146
-				$expireDate,
147
-				$container->getServer()->getWebRoot(),
148
-				null,
149
-				$container->getServer()->getRequest()->getServerProtocol() === 'https',
150
-				true
151
-			);
152
-		}
153
-
154
-		/*
49
+    /** @var string[] */
50
+    private static $nameSpaceCache = [];
51
+
52
+    /**
53
+     * Turns an app id into a namespace by either reading the appinfo.xml's
54
+     * namespace tag or uppercasing the appid's first letter
55
+     * @param string $appId the app id
56
+     * @param string $topNamespace the namespace which should be prepended to
57
+     * the transformed app id, defaults to OCA\
58
+     * @return string the starting namespace for the app
59
+     */
60
+    public static function buildAppNamespace(string $appId, string $topNamespace='OCA\\'): string {
61
+        // Hit the cache!
62
+        if (isset(self::$nameSpaceCache[$appId])) {
63
+            return $topNamespace . self::$nameSpaceCache[$appId];
64
+        }
65
+
66
+        $appInfo = \OC_App::getAppInfo($appId);
67
+        if (isset($appInfo['namespace'])) {
68
+            self::$nameSpaceCache[$appId] = trim($appInfo['namespace']);
69
+        } else {
70
+            // if the tag is not found, fall back to uppercasing the first letter
71
+            self::$nameSpaceCache[$appId] = ucfirst($appId);
72
+        }
73
+
74
+        return $topNamespace . self::$nameSpaceCache[$appId];
75
+    }
76
+
77
+
78
+    /**
79
+     * Shortcut for calling a controller method and printing the result
80
+     * @param string $controllerName the name of the controller under which it is
81
+     *                               stored in the DI container
82
+     * @param string $methodName the method that you want to call
83
+     * @param DIContainer $container an instance of a pimple container.
84
+     * @param array $urlParams list of URL parameters (optional)
85
+     * @throws HintException
86
+     */
87
+    public static function main(string $controllerName, string $methodName, DIContainer $container, array $urlParams = null) {
88
+        if (!is_null($urlParams)) {
89
+            $container->query(IRequest::class)->setUrlParameters($urlParams);
90
+        } else if (isset($container['urlParams']) && !is_null($container['urlParams'])) {
91
+            $container->query(IRequest::class)->setUrlParameters($container['urlParams']);
92
+        }
93
+        $appName = $container['AppName'];
94
+
95
+        // first try $controllerName then go for \OCA\AppName\Controller\$controllerName
96
+        try {
97
+            $controller = $container->query($controllerName);
98
+        } catch(QueryException $e) {
99
+            if (strpos($controllerName, '\\Controller\\') !== false) {
100
+                // This is from a global registered app route that is not enabled.
101
+                [/*OC(A)*/, $app, /* Controller/Name*/] = explode('\\', $controllerName, 3);
102
+                throw new HintException('App ' . strtolower($app) . ' is not enabled');
103
+            }
104
+
105
+            if ($appName === 'core') {
106
+                $appNameSpace = 'OC\\Core';
107
+            } else if ($appName === 'settings') {
108
+                $appNameSpace = 'OC\\Settings';
109
+            } else {
110
+                $appNameSpace = self::buildAppNamespace($appName);
111
+            }
112
+            $controllerName = $appNameSpace . '\\Controller\\' . $controllerName;
113
+            $controller = $container->query($controllerName);
114
+        }
115
+
116
+        // initialize the dispatcher and run all the middleware before the controller
117
+        /** @var Dispatcher $dispatcher */
118
+        $dispatcher = $container['Dispatcher'];
119
+
120
+        list(
121
+            $httpHeaders,
122
+            $responseHeaders,
123
+            $responseCookies,
124
+            $output,
125
+            $response
126
+        ) = $dispatcher->dispatch($controller, $methodName);
127
+
128
+        $io = $container[IOutput::class];
129
+
130
+        if(!is_null($httpHeaders)) {
131
+            $io->setHeader($httpHeaders);
132
+        }
133
+
134
+        foreach($responseHeaders as $name => $value) {
135
+            $io->setHeader($name . ': ' . $value);
136
+        }
137
+
138
+        foreach($responseCookies as $name => $value) {
139
+            $expireDate = null;
140
+            if($value['expireDate'] instanceof \DateTime) {
141
+                $expireDate = $value['expireDate']->getTimestamp();
142
+            }
143
+            $io->setCookie(
144
+                $name,
145
+                $value['value'],
146
+                $expireDate,
147
+                $container->getServer()->getWebRoot(),
148
+                null,
149
+                $container->getServer()->getRequest()->getServerProtocol() === 'https',
150
+                true
151
+            );
152
+        }
153
+
154
+        /*
155 155
 		 * Status 204 does not have a body and no Content Length
156 156
 		 * Status 304 does not have a body and does not need a Content Length
157 157
 		 * https://tools.ietf.org/html/rfc7230#section-3.3
158 158
 		 * https://tools.ietf.org/html/rfc7230#section-3.3.2
159 159
 		 */
160
-		$emptyResponse = false;
161
-		if (preg_match('/^HTTP\/\d\.\d (\d{3}) .*$/', $httpHeaders, $matches)) {
162
-			$status = (int)$matches[1];
163
-			if ($status === Http::STATUS_NO_CONTENT || $status === Http::STATUS_NOT_MODIFIED) {
164
-				$emptyResponse = true;
165
-			}
166
-		}
167
-
168
-		if (!$emptyResponse) {
169
-			if ($response instanceof ICallbackResponse) {
170
-				$response->callback($io);
171
-			} else if (!is_null($output)) {
172
-				$io->setHeader('Content-Length: ' . strlen($output));
173
-				$io->setOutput($output);
174
-			}
175
-		}
176
-
177
-	}
178
-
179
-	/**
180
-	 * Shortcut for calling a controller method and printing the result.
181
-	 * Similar to App:main except that no headers will be sent.
182
-	 * This should be used for example when registering sections via
183
-	 * \OC\AppFramework\Core\API::registerAdmin()
184
-	 *
185
-	 * @param string $controllerName the name of the controller under which it is
186
-	 *                               stored in the DI container
187
-	 * @param string $methodName the method that you want to call
188
-	 * @param array $urlParams an array with variables extracted from the routes
189
-	 * @param DIContainer $container an instance of a pimple container.
190
-	 */
191
-	public static function part(string $controllerName, string $methodName, array $urlParams,
192
-								DIContainer $container){
193
-
194
-		$container['urlParams'] = $urlParams;
195
-		$controller = $container[$controllerName];
196
-
197
-		$dispatcher = $container['Dispatcher'];
198
-
199
-		list(, , $output) =  $dispatcher->dispatch($controller, $methodName);
200
-		return $output;
201
-	}
160
+        $emptyResponse = false;
161
+        if (preg_match('/^HTTP\/\d\.\d (\d{3}) .*$/', $httpHeaders, $matches)) {
162
+            $status = (int)$matches[1];
163
+            if ($status === Http::STATUS_NO_CONTENT || $status === Http::STATUS_NOT_MODIFIED) {
164
+                $emptyResponse = true;
165
+            }
166
+        }
167
+
168
+        if (!$emptyResponse) {
169
+            if ($response instanceof ICallbackResponse) {
170
+                $response->callback($io);
171
+            } else if (!is_null($output)) {
172
+                $io->setHeader('Content-Length: ' . strlen($output));
173
+                $io->setOutput($output);
174
+            }
175
+        }
176
+
177
+    }
178
+
179
+    /**
180
+     * Shortcut for calling a controller method and printing the result.
181
+     * Similar to App:main except that no headers will be sent.
182
+     * This should be used for example when registering sections via
183
+     * \OC\AppFramework\Core\API::registerAdmin()
184
+     *
185
+     * @param string $controllerName the name of the controller under which it is
186
+     *                               stored in the DI container
187
+     * @param string $methodName the method that you want to call
188
+     * @param array $urlParams an array with variables extracted from the routes
189
+     * @param DIContainer $container an instance of a pimple container.
190
+     */
191
+    public static function part(string $controllerName, string $methodName, array $urlParams,
192
+                                DIContainer $container){
193
+
194
+        $container['urlParams'] = $urlParams;
195
+        $controller = $container[$controllerName];
196
+
197
+        $dispatcher = $container['Dispatcher'];
198
+
199
+        list(, , $output) =  $dispatcher->dispatch($controller, $methodName);
200
+        return $output;
201
+    }
202 202
 
203 203
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -57,10 +57,10 @@  discard block
 block discarded – undo
57 57
 	 * the transformed app id, defaults to OCA\
58 58
 	 * @return string the starting namespace for the app
59 59
 	 */
60
-	public static function buildAppNamespace(string $appId, string $topNamespace='OCA\\'): string {
60
+	public static function buildAppNamespace(string $appId, string $topNamespace = 'OCA\\'): string {
61 61
 		// Hit the cache!
62 62
 		if (isset(self::$nameSpaceCache[$appId])) {
63
-			return $topNamespace . self::$nameSpaceCache[$appId];
63
+			return $topNamespace.self::$nameSpaceCache[$appId];
64 64
 		}
65 65
 
66 66
 		$appInfo = \OC_App::getAppInfo($appId);
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 			self::$nameSpaceCache[$appId] = ucfirst($appId);
72 72
 		}
73 73
 
74
-		return $topNamespace . self::$nameSpaceCache[$appId];
74
+		return $topNamespace.self::$nameSpaceCache[$appId];
75 75
 	}
76 76
 
77 77
 
@@ -95,11 +95,11 @@  discard block
 block discarded – undo
95 95
 		// first try $controllerName then go for \OCA\AppName\Controller\$controllerName
96 96
 		try {
97 97
 			$controller = $container->query($controllerName);
98
-		} catch(QueryException $e) {
98
+		} catch (QueryException $e) {
99 99
 			if (strpos($controllerName, '\\Controller\\') !== false) {
100 100
 				// This is from a global registered app route that is not enabled.
101 101
 				[/*OC(A)*/, $app, /* Controller/Name*/] = explode('\\', $controllerName, 3);
102
-				throw new HintException('App ' . strtolower($app) . ' is not enabled');
102
+				throw new HintException('App '.strtolower($app).' is not enabled');
103 103
 			}
104 104
 
105 105
 			if ($appName === 'core') {
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 			} else {
110 110
 				$appNameSpace = self::buildAppNamespace($appName);
111 111
 			}
112
-			$controllerName = $appNameSpace . '\\Controller\\' . $controllerName;
112
+			$controllerName = $appNameSpace.'\\Controller\\'.$controllerName;
113 113
 			$controller = $container->query($controllerName);
114 114
 		}
115 115
 
@@ -127,17 +127,17 @@  discard block
 block discarded – undo
127 127
 
128 128
 		$io = $container[IOutput::class];
129 129
 
130
-		if(!is_null($httpHeaders)) {
130
+		if (!is_null($httpHeaders)) {
131 131
 			$io->setHeader($httpHeaders);
132 132
 		}
133 133
 
134
-		foreach($responseHeaders as $name => $value) {
135
-			$io->setHeader($name . ': ' . $value);
134
+		foreach ($responseHeaders as $name => $value) {
135
+			$io->setHeader($name.': '.$value);
136 136
 		}
137 137
 
138
-		foreach($responseCookies as $name => $value) {
138
+		foreach ($responseCookies as $name => $value) {
139 139
 			$expireDate = null;
140
-			if($value['expireDate'] instanceof \DateTime) {
140
+			if ($value['expireDate'] instanceof \DateTime) {
141 141
 				$expireDate = $value['expireDate']->getTimestamp();
142 142
 			}
143 143
 			$io->setCookie(
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 		 */
160 160
 		$emptyResponse = false;
161 161
 		if (preg_match('/^HTTP\/\d\.\d (\d{3}) .*$/', $httpHeaders, $matches)) {
162
-			$status = (int)$matches[1];
162
+			$status = (int) $matches[1];
163 163
 			if ($status === Http::STATUS_NO_CONTENT || $status === Http::STATUS_NOT_MODIFIED) {
164 164
 				$emptyResponse = true;
165 165
 			}
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 			if ($response instanceof ICallbackResponse) {
170 170
 				$response->callback($io);
171 171
 			} else if (!is_null($output)) {
172
-				$io->setHeader('Content-Length: ' . strlen($output));
172
+				$io->setHeader('Content-Length: '.strlen($output));
173 173
 				$io->setOutput($output);
174 174
 			}
175 175
 		}
@@ -189,14 +189,14 @@  discard block
 block discarded – undo
189 189
 	 * @param DIContainer $container an instance of a pimple container.
190 190
 	 */
191 191
 	public static function part(string $controllerName, string $methodName, array $urlParams,
192
-								DIContainer $container){
192
+								DIContainer $container) {
193 193
 
194 194
 		$container['urlParams'] = $urlParams;
195 195
 		$controller = $container[$controllerName];
196 196
 
197 197
 		$dispatcher = $container['Dispatcher'];
198 198
 
199
-		list(, , $output) =  $dispatcher->dispatch($controller, $methodName);
199
+		list(,, $output) = $dispatcher->dispatch($controller, $methodName);
200 200
 		return $output;
201 201
 	}
202 202
 
Please login to merge, or discard this patch.