Completed
Push — master ( 81a3ac...528ffa )
by Joas
27:15 queued 10:28
created
lib/private/AppFramework/App.php 2 patches
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -45,143 +45,143 @@
 block discarded – undo
45 45
  */
46 46
 class App {
47 47
 
48
-	/** @var string[] */
49
-	private static $nameSpaceCache = [];
50
-
51
-	/**
52
-	 * Turns an app id into a namespace by either reading the appinfo.xml's
53
-	 * namespace tag or uppercasing the appid's first letter
54
-	 * @param string $appId the app id
55
-	 * @param string $topNamespace the namespace which should be prepended to
56
-	 * the transformed app id, defaults to OCA\
57
-	 * @return string the starting namespace for the app
58
-	 */
59
-	public static function buildAppNamespace(string $appId, string $topNamespace='OCA\\'): string {
60
-		// Hit the cache!
61
-		if (isset(self::$nameSpaceCache[$appId])) {
62
-			return $topNamespace . self::$nameSpaceCache[$appId];
63
-		}
64
-
65
-		$appInfo = \OC_App::getAppInfo($appId);
66
-		if (isset($appInfo['namespace'])) {
67
-			self::$nameSpaceCache[$appId] = trim($appInfo['namespace']);
68
-		} else {
69
-			// if the tag is not found, fall back to uppercasing the first letter
70
-			self::$nameSpaceCache[$appId] = ucfirst($appId);
71
-		}
72
-
73
-		return $topNamespace . self::$nameSpaceCache[$appId];
74
-	}
75
-
76
-
77
-	/**
78
-	 * Shortcut for calling a controller method and printing the result
79
-	 * @param string $controllerName the name of the controller under which it is
80
-	 *                               stored in the DI container
81
-	 * @param string $methodName the method that you want to call
82
-	 * @param DIContainer $container an instance of a pimple container.
83
-	 * @param array $urlParams list of URL parameters (optional)
84
-	 */
85
-	public static function main(string $controllerName, string $methodName, DIContainer $container, array $urlParams = null) {
86
-		if (!is_null($urlParams)) {
87
-			$container[IRequest::class]->setUrlParameters($urlParams);
88
-		} else if (isset($container['urlParams']) && !is_null($container['urlParams'])) {
89
-			$container[IRequest::class]->setUrlParameters($container['urlParams']);
90
-		}
91
-		$appName = $container['AppName'];
92
-
93
-		// first try $controllerName then go for \OCA\AppName\Controller\$controllerName
94
-		try {
95
-			$controller = $container->query($controllerName);
96
-		} catch(QueryException $e) {
97
-			if ($appName === 'core') {
98
-				$appNameSpace = 'OC\\Core';
99
-			} else if ($appName === 'settings') {
100
-				$appNameSpace = 'OC\\Settings';
101
-			} else {
102
-				$appNameSpace = self::buildAppNamespace($appName);
103
-			}
104
-			$controllerName = $appNameSpace . '\\Controller\\' . $controllerName;
105
-			$controller = $container->query($controllerName);
106
-		}
107
-
108
-		// initialize the dispatcher and run all the middleware before the controller
109
-		/** @var Dispatcher $dispatcher */
110
-		$dispatcher = $container['Dispatcher'];
111
-
112
-		list(
113
-			$httpHeaders,
114
-			$responseHeaders,
115
-			$responseCookies,
116
-			$output,
117
-			$response
118
-		) = $dispatcher->dispatch($controller, $methodName);
119
-
120
-		$io = $container[IOutput::class];
121
-
122
-		if(!is_null($httpHeaders)) {
123
-			$io->setHeader($httpHeaders);
124
-		}
125
-
126
-		foreach($responseHeaders as $name => $value) {
127
-			$io->setHeader($name . ': ' . $value);
128
-		}
129
-
130
-		foreach($responseCookies as $name => $value) {
131
-			$expireDate = null;
132
-			if($value['expireDate'] instanceof \DateTime) {
133
-				$expireDate = $value['expireDate']->getTimestamp();
134
-			}
135
-			$io->setCookie(
136
-				$name,
137
-				$value['value'],
138
-				$expireDate,
139
-				$container->getServer()->getWebRoot(),
140
-				null,
141
-				$container->getServer()->getRequest()->getServerProtocol() === 'https',
142
-				true
143
-			);
144
-		}
145
-
146
-		/*
48
+    /** @var string[] */
49
+    private static $nameSpaceCache = [];
50
+
51
+    /**
52
+     * Turns an app id into a namespace by either reading the appinfo.xml's
53
+     * namespace tag or uppercasing the appid's first letter
54
+     * @param string $appId the app id
55
+     * @param string $topNamespace the namespace which should be prepended to
56
+     * the transformed app id, defaults to OCA\
57
+     * @return string the starting namespace for the app
58
+     */
59
+    public static function buildAppNamespace(string $appId, string $topNamespace='OCA\\'): string {
60
+        // Hit the cache!
61
+        if (isset(self::$nameSpaceCache[$appId])) {
62
+            return $topNamespace . self::$nameSpaceCache[$appId];
63
+        }
64
+
65
+        $appInfo = \OC_App::getAppInfo($appId);
66
+        if (isset($appInfo['namespace'])) {
67
+            self::$nameSpaceCache[$appId] = trim($appInfo['namespace']);
68
+        } else {
69
+            // if the tag is not found, fall back to uppercasing the first letter
70
+            self::$nameSpaceCache[$appId] = ucfirst($appId);
71
+        }
72
+
73
+        return $topNamespace . self::$nameSpaceCache[$appId];
74
+    }
75
+
76
+
77
+    /**
78
+     * Shortcut for calling a controller method and printing the result
79
+     * @param string $controllerName the name of the controller under which it is
80
+     *                               stored in the DI container
81
+     * @param string $methodName the method that you want to call
82
+     * @param DIContainer $container an instance of a pimple container.
83
+     * @param array $urlParams list of URL parameters (optional)
84
+     */
85
+    public static function main(string $controllerName, string $methodName, DIContainer $container, array $urlParams = null) {
86
+        if (!is_null($urlParams)) {
87
+            $container[IRequest::class]->setUrlParameters($urlParams);
88
+        } else if (isset($container['urlParams']) && !is_null($container['urlParams'])) {
89
+            $container[IRequest::class]->setUrlParameters($container['urlParams']);
90
+        }
91
+        $appName = $container['AppName'];
92
+
93
+        // first try $controllerName then go for \OCA\AppName\Controller\$controllerName
94
+        try {
95
+            $controller = $container->query($controllerName);
96
+        } catch(QueryException $e) {
97
+            if ($appName === 'core') {
98
+                $appNameSpace = 'OC\\Core';
99
+            } else if ($appName === 'settings') {
100
+                $appNameSpace = 'OC\\Settings';
101
+            } else {
102
+                $appNameSpace = self::buildAppNamespace($appName);
103
+            }
104
+            $controllerName = $appNameSpace . '\\Controller\\' . $controllerName;
105
+            $controller = $container->query($controllerName);
106
+        }
107
+
108
+        // initialize the dispatcher and run all the middleware before the controller
109
+        /** @var Dispatcher $dispatcher */
110
+        $dispatcher = $container['Dispatcher'];
111
+
112
+        list(
113
+            $httpHeaders,
114
+            $responseHeaders,
115
+            $responseCookies,
116
+            $output,
117
+            $response
118
+        ) = $dispatcher->dispatch($controller, $methodName);
119
+
120
+        $io = $container[IOutput::class];
121
+
122
+        if(!is_null($httpHeaders)) {
123
+            $io->setHeader($httpHeaders);
124
+        }
125
+
126
+        foreach($responseHeaders as $name => $value) {
127
+            $io->setHeader($name . ': ' . $value);
128
+        }
129
+
130
+        foreach($responseCookies as $name => $value) {
131
+            $expireDate = null;
132
+            if($value['expireDate'] instanceof \DateTime) {
133
+                $expireDate = $value['expireDate']->getTimestamp();
134
+            }
135
+            $io->setCookie(
136
+                $name,
137
+                $value['value'],
138
+                $expireDate,
139
+                $container->getServer()->getWebRoot(),
140
+                null,
141
+                $container->getServer()->getRequest()->getServerProtocol() === 'https',
142
+                true
143
+            );
144
+        }
145
+
146
+        /*
147 147
 		 * Status 204 does not have a body and no Content Length
148 148
 		 * Status 304 does not have a body and does not need a Content Length
149 149
 		 * https://tools.ietf.org/html/rfc7230#section-3.3
150 150
 		 * https://tools.ietf.org/html/rfc7230#section-3.3.2
151 151
 		 */
152
-		if ($httpHeaders !== Http::STATUS_NO_CONTENT && $httpHeaders !== Http::STATUS_NOT_MODIFIED) {
153
-			if ($response instanceof ICallbackResponse) {
154
-				$response->callback($io);
155
-			} else if (!is_null($output)) {
156
-				$io->setHeader('Content-Length: ' . strlen($output));
157
-				$io->setOutput($output);
158
-			}
159
-		}
160
-
161
-	}
162
-
163
-	/**
164
-	 * Shortcut for calling a controller method and printing the result.
165
-	 * Similar to App:main except that no headers will be sent.
166
-	 * This should be used for example when registering sections via
167
-	 * \OC\AppFramework\Core\API::registerAdmin()
168
-	 *
169
-	 * @param string $controllerName the name of the controller under which it is
170
-	 *                               stored in the DI container
171
-	 * @param string $methodName the method that you want to call
172
-	 * @param array $urlParams an array with variables extracted from the routes
173
-	 * @param DIContainer $container an instance of a pimple container.
174
-	 */
175
-	public static function part(string $controllerName, string $methodName, array $urlParams,
176
-								DIContainer $container){
177
-
178
-		$container['urlParams'] = $urlParams;
179
-		$controller = $container[$controllerName];
180
-
181
-		$dispatcher = $container['Dispatcher'];
182
-
183
-		list(, , $output) =  $dispatcher->dispatch($controller, $methodName);
184
-		return $output;
185
-	}
152
+        if ($httpHeaders !== Http::STATUS_NO_CONTENT && $httpHeaders !== Http::STATUS_NOT_MODIFIED) {
153
+            if ($response instanceof ICallbackResponse) {
154
+                $response->callback($io);
155
+            } else if (!is_null($output)) {
156
+                $io->setHeader('Content-Length: ' . strlen($output));
157
+                $io->setOutput($output);
158
+            }
159
+        }
160
+
161
+    }
162
+
163
+    /**
164
+     * Shortcut for calling a controller method and printing the result.
165
+     * Similar to App:main except that no headers will be sent.
166
+     * This should be used for example when registering sections via
167
+     * \OC\AppFramework\Core\API::registerAdmin()
168
+     *
169
+     * @param string $controllerName the name of the controller under which it is
170
+     *                               stored in the DI container
171
+     * @param string $methodName the method that you want to call
172
+     * @param array $urlParams an array with variables extracted from the routes
173
+     * @param DIContainer $container an instance of a pimple container.
174
+     */
175
+    public static function part(string $controllerName, string $methodName, array $urlParams,
176
+                                DIContainer $container){
177
+
178
+        $container['urlParams'] = $urlParams;
179
+        $controller = $container[$controllerName];
180
+
181
+        $dispatcher = $container['Dispatcher'];
182
+
183
+        list(, , $output) =  $dispatcher->dispatch($controller, $methodName);
184
+        return $output;
185
+    }
186 186
 
187 187
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 /**
4 4
  * @copyright Copyright (c) 2016, ownCloud, Inc.
5 5
  *
@@ -56,10 +56,10 @@  discard block
 block discarded – undo
56 56
 	 * the transformed app id, defaults to OCA\
57 57
 	 * @return string the starting namespace for the app
58 58
 	 */
59
-	public static function buildAppNamespace(string $appId, string $topNamespace='OCA\\'): string {
59
+	public static function buildAppNamespace(string $appId, string $topNamespace = 'OCA\\'): string {
60 60
 		// Hit the cache!
61 61
 		if (isset(self::$nameSpaceCache[$appId])) {
62
-			return $topNamespace . self::$nameSpaceCache[$appId];
62
+			return $topNamespace.self::$nameSpaceCache[$appId];
63 63
 		}
64 64
 
65 65
 		$appInfo = \OC_App::getAppInfo($appId);
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 			self::$nameSpaceCache[$appId] = ucfirst($appId);
71 71
 		}
72 72
 
73
-		return $topNamespace . self::$nameSpaceCache[$appId];
73
+		return $topNamespace.self::$nameSpaceCache[$appId];
74 74
 	}
75 75
 
76 76
 
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 		// first try $controllerName then go for \OCA\AppName\Controller\$controllerName
94 94
 		try {
95 95
 			$controller = $container->query($controllerName);
96
-		} catch(QueryException $e) {
96
+		} catch (QueryException $e) {
97 97
 			if ($appName === 'core') {
98 98
 				$appNameSpace = 'OC\\Core';
99 99
 			} else if ($appName === 'settings') {
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 			} else {
102 102
 				$appNameSpace = self::buildAppNamespace($appName);
103 103
 			}
104
-			$controllerName = $appNameSpace . '\\Controller\\' . $controllerName;
104
+			$controllerName = $appNameSpace.'\\Controller\\'.$controllerName;
105 105
 			$controller = $container->query($controllerName);
106 106
 		}
107 107
 
@@ -119,17 +119,17 @@  discard block
 block discarded – undo
119 119
 
120 120
 		$io = $container[IOutput::class];
121 121
 
122
-		if(!is_null($httpHeaders)) {
122
+		if (!is_null($httpHeaders)) {
123 123
 			$io->setHeader($httpHeaders);
124 124
 		}
125 125
 
126
-		foreach($responseHeaders as $name => $value) {
127
-			$io->setHeader($name . ': ' . $value);
126
+		foreach ($responseHeaders as $name => $value) {
127
+			$io->setHeader($name.': '.$value);
128 128
 		}
129 129
 
130
-		foreach($responseCookies as $name => $value) {
130
+		foreach ($responseCookies as $name => $value) {
131 131
 			$expireDate = null;
132
-			if($value['expireDate'] instanceof \DateTime) {
132
+			if ($value['expireDate'] instanceof \DateTime) {
133 133
 				$expireDate = $value['expireDate']->getTimestamp();
134 134
 			}
135 135
 			$io->setCookie(
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 			if ($response instanceof ICallbackResponse) {
154 154
 				$response->callback($io);
155 155
 			} else if (!is_null($output)) {
156
-				$io->setHeader('Content-Length: ' . strlen($output));
156
+				$io->setHeader('Content-Length: '.strlen($output));
157 157
 				$io->setOutput($output);
158 158
 			}
159 159
 		}
@@ -173,14 +173,14 @@  discard block
 block discarded – undo
173 173
 	 * @param DIContainer $container an instance of a pimple container.
174 174
 	 */
175 175
 	public static function part(string $controllerName, string $methodName, array $urlParams,
176
-								DIContainer $container){
176
+								DIContainer $container) {
177 177
 
178 178
 		$container['urlParams'] = $urlParams;
179 179
 		$controller = $container[$controllerName];
180 180
 
181 181
 		$dispatcher = $container['Dispatcher'];
182 182
 
183
-		list(, , $output) =  $dispatcher->dispatch($controller, $methodName);
183
+		list(,, $output) = $dispatcher->dispatch($controller, $methodName);
184 184
 		return $output;
185 185
 	}
186 186
 
Please login to merge, or discard this patch.
lib/public/AppFramework/App.php 2 patches
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -47,96 +47,96 @@
 block discarded – undo
47 47
  */
48 48
 class App {
49 49
 
50
-	/** @var IAppContainer */
51
-	private $container;
50
+    /** @var IAppContainer */
51
+    private $container;
52 52
 
53
-	/**
54
-	 * Turns an app id into a namespace by convetion. The id is split at the
55
-	 * underscores, all parts are camelcased and reassembled. e.g.:
56
-	 * some_app_id -> OCA\SomeAppId
57
-	 * @param string $appId the app id
58
-	 * @param string $topNamespace the namespace which should be prepended to
59
-	 * the transformed app id, defaults to OCA\
60
-	 * @return string the starting namespace for the app
61
-	 * @since 8.0.0
62
-	 */
63
-	public static function buildAppNamespace(string $appId, string $topNamespace='OCA\\'): string {
64
-		return \OC\AppFramework\App::buildAppNamespace($appId, $topNamespace);
65
-	}
53
+    /**
54
+     * Turns an app id into a namespace by convetion. The id is split at the
55
+     * underscores, all parts are camelcased and reassembled. e.g.:
56
+     * some_app_id -> OCA\SomeAppId
57
+     * @param string $appId the app id
58
+     * @param string $topNamespace the namespace which should be prepended to
59
+     * the transformed app id, defaults to OCA\
60
+     * @return string the starting namespace for the app
61
+     * @since 8.0.0
62
+     */
63
+    public static function buildAppNamespace(string $appId, string $topNamespace='OCA\\'): string {
64
+        return \OC\AppFramework\App::buildAppNamespace($appId, $topNamespace);
65
+    }
66 66
 
67 67
 
68
-	/**
69
-	 * @param array $urlParams an array with variables extracted from the routes
70
-	 * @since 6.0.0
71
-	 */
72
-	public function __construct(string $appName, array $urlParams = []) {
73
-		$this->container = new \OC\AppFramework\DependencyInjection\DIContainer($appName, $urlParams);
74
-	}
68
+    /**
69
+     * @param array $urlParams an array with variables extracted from the routes
70
+     * @since 6.0.0
71
+     */
72
+    public function __construct(string $appName, array $urlParams = []) {
73
+        $this->container = new \OC\AppFramework\DependencyInjection\DIContainer($appName, $urlParams);
74
+    }
75 75
 
76
-	/**
77
-	 * @return IAppContainer
78
-	 * @since 6.0.0
79
-	 */
80
-	public function getContainer(): IAppContainer {
81
-		return $this->container;
82
-	}
76
+    /**
77
+     * @return IAppContainer
78
+     * @since 6.0.0
79
+     */
80
+    public function getContainer(): IAppContainer {
81
+        return $this->container;
82
+    }
83 83
 
84
-	/**
85
-	 * This function is to be called to create single routes and restful routes based on the given $routes array.
86
-	 *
87
-	 * Example code in routes.php of tasks app (it will register two restful resources):
88
-	 * $routes = array(
89
-	 *		'resources' => array(
90
-	 *		'lists' => array('url' => '/tasklists'),
91
-	 *		'tasks' => array('url' => '/tasklists/{listId}/tasks')
92
-	 *	)
93
-	 *	);
94
-	 *
95
-	 * $a = new TasksApp();
96
-	 * $a->registerRoutes($this, $routes);
97
-	 *
98
-	 * @param \OCP\Route\IRouter $router
99
-	 * @param array $routes
100
-	 * @since 6.0.0
101
-	 * @suppress PhanAccessMethodInternal
102
-	 */
103
-	public function registerRoutes(IRouter $router, array $routes) {
104
-		$routeConfig = new RouteConfig($this->container, $router, $routes);
105
-		$routeConfig->register();
106
-	}
84
+    /**
85
+     * This function is to be called to create single routes and restful routes based on the given $routes array.
86
+     *
87
+     * Example code in routes.php of tasks app (it will register two restful resources):
88
+     * $routes = array(
89
+     *		'resources' => array(
90
+     *		'lists' => array('url' => '/tasklists'),
91
+     *		'tasks' => array('url' => '/tasklists/{listId}/tasks')
92
+     *	)
93
+     *	);
94
+     *
95
+     * $a = new TasksApp();
96
+     * $a->registerRoutes($this, $routes);
97
+     *
98
+     * @param \OCP\Route\IRouter $router
99
+     * @param array $routes
100
+     * @since 6.0.0
101
+     * @suppress PhanAccessMethodInternal
102
+     */
103
+    public function registerRoutes(IRouter $router, array $routes) {
104
+        $routeConfig = new RouteConfig($this->container, $router, $routes);
105
+        $routeConfig->register();
106
+    }
107 107
 
108
-	/**
109
-	 * This function is called by the routing component to fire up the frameworks dispatch mechanism.
110
-	 *
111
-	 * Example code in routes.php of the task app:
112
-	 * $this->create('tasks_index', '/')->get()->action(
113
-	 *		function($params){
114
-	 *			$app = new TaskApp($params);
115
-	 *			$app->dispatch('PageController', 'index');
116
-	 *		}
117
-	 *	);
118
-	 *
119
-	 *
120
-	 * Example for for TaskApp implementation:
121
-	 * class TaskApp extends \OCP\AppFramework\App {
122
-	 *
123
-	 *		public function __construct($params){
124
-	 *			parent::__construct('tasks', $params);
125
-	 *
126
-	 *			$this->getContainer()->registerService('PageController', function(IAppContainer $c){
127
-	 *				$a = $c->query('API');
128
-	 *				$r = $c->query('Request');
129
-	 *				return new PageController($a, $r);
130
-	 *			});
131
-	 *		}
132
-	 *	}
133
-	 *
134
-	 * @param string $controllerName the name of the controller under which it is
135
-	 *                               stored in the DI container
136
-	 * @param string $methodName the method that you want to call
137
-	 * @since 6.0.0
138
-	 */
139
-	public function dispatch(string $controllerName, string $methodName) {
140
-		\OC\AppFramework\App::main($controllerName, $methodName, $this->container);
141
-	}
108
+    /**
109
+     * This function is called by the routing component to fire up the frameworks dispatch mechanism.
110
+     *
111
+     * Example code in routes.php of the task app:
112
+     * $this->create('tasks_index', '/')->get()->action(
113
+     *		function($params){
114
+     *			$app = new TaskApp($params);
115
+     *			$app->dispatch('PageController', 'index');
116
+     *		}
117
+     *	);
118
+     *
119
+     *
120
+     * Example for for TaskApp implementation:
121
+     * class TaskApp extends \OCP\AppFramework\App {
122
+     *
123
+     *		public function __construct($params){
124
+     *			parent::__construct('tasks', $params);
125
+     *
126
+     *			$this->getContainer()->registerService('PageController', function(IAppContainer $c){
127
+     *				$a = $c->query('API');
128
+     *				$r = $c->query('Request');
129
+     *				return new PageController($a, $r);
130
+     *			});
131
+     *		}
132
+     *	}
133
+     *
134
+     * @param string $controllerName the name of the controller under which it is
135
+     *                               stored in the DI container
136
+     * @param string $methodName the method that you want to call
137
+     * @since 6.0.0
138
+     */
139
+    public function dispatch(string $controllerName, string $methodName) {
140
+        \OC\AppFramework\App::main($controllerName, $methodName, $this->container);
141
+    }
142 142
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 /**
4 4
  * @copyright Copyright (c) 2016, ownCloud, Inc.
5 5
  *
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	 * @return string the starting namespace for the app
61 61
 	 * @since 8.0.0
62 62
 	 */
63
-	public static function buildAppNamespace(string $appId, string $topNamespace='OCA\\'): string {
63
+	public static function buildAppNamespace(string $appId, string $topNamespace = 'OCA\\'): string {
64 64
 		return \OC\AppFramework\App::buildAppNamespace($appId, $topNamespace);
65 65
 	}
66 66
 
Please login to merge, or discard this patch.