@@ -38,294 +38,294 @@ |
||
38 | 38 | * @package OC\AppFramework\routing |
39 | 39 | */ |
40 | 40 | class RouteConfig { |
41 | - /** @var DIContainer */ |
|
42 | - private $container; |
|
43 | - |
|
44 | - /** @var IRouter */ |
|
45 | - private $router; |
|
46 | - |
|
47 | - /** @var array */ |
|
48 | - private $routes; |
|
49 | - |
|
50 | - /** @var string */ |
|
51 | - private $appName; |
|
52 | - |
|
53 | - /** @var string[] */ |
|
54 | - private $controllerNameCache = []; |
|
55 | - |
|
56 | - /** |
|
57 | - * @param \OC\AppFramework\DependencyInjection\DIContainer $container |
|
58 | - * @param \OCP\Route\IRouter $router |
|
59 | - * @param array $routes |
|
60 | - * @internal param $appName |
|
61 | - */ |
|
62 | - public function __construct(DIContainer $container, IRouter $router, $routes) { |
|
63 | - $this->routes = $routes; |
|
64 | - $this->container = $container; |
|
65 | - $this->router = $router; |
|
66 | - $this->appName = $container['AppName']; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * The routes and resource will be registered to the \OCP\Route\IRouter |
|
71 | - */ |
|
72 | - public function register() { |
|
73 | - |
|
74 | - // parse simple |
|
75 | - $this->processSimpleRoutes($this->routes); |
|
76 | - |
|
77 | - // parse resources |
|
78 | - $this->processResources($this->routes); |
|
79 | - |
|
80 | - /* |
|
41 | + /** @var DIContainer */ |
|
42 | + private $container; |
|
43 | + |
|
44 | + /** @var IRouter */ |
|
45 | + private $router; |
|
46 | + |
|
47 | + /** @var array */ |
|
48 | + private $routes; |
|
49 | + |
|
50 | + /** @var string */ |
|
51 | + private $appName; |
|
52 | + |
|
53 | + /** @var string[] */ |
|
54 | + private $controllerNameCache = []; |
|
55 | + |
|
56 | + /** |
|
57 | + * @param \OC\AppFramework\DependencyInjection\DIContainer $container |
|
58 | + * @param \OCP\Route\IRouter $router |
|
59 | + * @param array $routes |
|
60 | + * @internal param $appName |
|
61 | + */ |
|
62 | + public function __construct(DIContainer $container, IRouter $router, $routes) { |
|
63 | + $this->routes = $routes; |
|
64 | + $this->container = $container; |
|
65 | + $this->router = $router; |
|
66 | + $this->appName = $container['AppName']; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * The routes and resource will be registered to the \OCP\Route\IRouter |
|
71 | + */ |
|
72 | + public function register() { |
|
73 | + |
|
74 | + // parse simple |
|
75 | + $this->processSimpleRoutes($this->routes); |
|
76 | + |
|
77 | + // parse resources |
|
78 | + $this->processResources($this->routes); |
|
79 | + |
|
80 | + /* |
|
81 | 81 | * OCS routes go into a different collection |
82 | 82 | */ |
83 | - $oldCollection = $this->router->getCurrentCollection(); |
|
84 | - $this->router->useCollection($oldCollection . '.ocs'); |
|
85 | - |
|
86 | - // parse ocs simple routes |
|
87 | - $this->processOCS($this->routes); |
|
88 | - |
|
89 | - // parse ocs simple routes |
|
90 | - $this->processOCSResources($this->routes); |
|
91 | - |
|
92 | - $this->router->useCollection($oldCollection); |
|
93 | - } |
|
94 | - |
|
95 | - private function processOCS(array $routes): void { |
|
96 | - $ocsRoutes = $routes['ocs'] ?? []; |
|
97 | - foreach ($ocsRoutes as $ocsRoute) { |
|
98 | - $name = $ocsRoute['name']; |
|
99 | - $postfix = $ocsRoute['postfix'] ?? ''; |
|
100 | - $root = $ocsRoute['root'] ?? '/apps/' . $this->appName; |
|
101 | - |
|
102 | - $url = $root . $ocsRoute['url']; |
|
103 | - $verb = strtoupper($ocsRoute['verb'] ?? 'GET'); |
|
104 | - |
|
105 | - $split = explode('#', $name, 2); |
|
106 | - if (count($split) !== 2) { |
|
107 | - throw new \UnexpectedValueException('Invalid route name'); |
|
108 | - } |
|
109 | - list($controller, $action) = $split; |
|
110 | - |
|
111 | - $controllerName = $this->buildControllerName($controller); |
|
112 | - $actionName = $this->buildActionName($action); |
|
113 | - |
|
114 | - $routeName = 'ocs.' . $this->appName . '.' . $controller . '.' . $action . $postfix; |
|
115 | - |
|
116 | - // register the route |
|
117 | - $handler = new RouteActionHandler($this->container, $controllerName, $actionName); |
|
118 | - |
|
119 | - $router = $this->router->create($routeName, $url) |
|
120 | - ->method($verb) |
|
121 | - ->action($handler); |
|
122 | - |
|
123 | - // optionally register requirements for route. This is used to |
|
124 | - // tell the route parser how url parameters should be matched |
|
125 | - if(array_key_exists('requirements', $ocsRoute)) { |
|
126 | - $router->requirements($ocsRoute['requirements']); |
|
127 | - } |
|
128 | - |
|
129 | - // optionally register defaults for route. This is used to |
|
130 | - // tell the route parser how url parameters should be default valued |
|
131 | - if(array_key_exists('defaults', $ocsRoute)) { |
|
132 | - $router->defaults($ocsRoute['defaults']); |
|
133 | - } |
|
134 | - } |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Creates one route base on the give configuration |
|
139 | - * @param array $routes |
|
140 | - * @throws \UnexpectedValueException |
|
141 | - */ |
|
142 | - private function processSimpleRoutes(array $routes): void { |
|
143 | - $simpleRoutes = $routes['routes'] ?? []; |
|
144 | - foreach ($simpleRoutes as $simpleRoute) { |
|
145 | - $name = $simpleRoute['name']; |
|
146 | - $postfix = $simpleRoute['postfix'] ?? ''; |
|
147 | - |
|
148 | - $url = $simpleRoute['url']; |
|
149 | - $verb = strtoupper($simpleRoute['verb'] ?? 'GET'); |
|
150 | - |
|
151 | - $split = explode('#', $name, 2); |
|
152 | - if (count($split) !== 2) { |
|
153 | - throw new \UnexpectedValueException('Invalid route name'); |
|
154 | - } |
|
155 | - list($controller, $action) = $split; |
|
156 | - |
|
157 | - $controllerName = $this->buildControllerName($controller); |
|
158 | - $actionName = $this->buildActionName($action); |
|
159 | - $appName = $simpleRoute['app'] ?? $this->appName; |
|
160 | - |
|
161 | - if (isset($simpleRoute['app'])) { |
|
162 | - // Legacy routes that need to be globally available while they are handled by an app |
|
163 | - // E.g. '/f/{id}', '/s/{token}', '/call/{token}', … |
|
164 | - $controllerName = str_replace('controllerController', 'Controller', $controllerName); |
|
165 | - if ($controllerName === 'PublicpreviewController') { |
|
166 | - $controllerName = 'PublicPreviewController'; |
|
167 | - } else if ($controllerName === 'RequesthandlerController') { |
|
168 | - $controllerName = 'RequestHandlerController'; |
|
169 | - } |
|
170 | - $controllerName = App::buildAppNamespace($appName) . '\\Controller\\' . $controllerName; |
|
171 | - } |
|
172 | - |
|
173 | - $routeName = $appName . '.' . $controller . '.' . $action . $postfix; |
|
174 | - |
|
175 | - // register the route |
|
176 | - $handler = new RouteActionHandler($this->container, $controllerName, $actionName); |
|
177 | - $router = $this->router->create($routeName, $url) |
|
178 | - ->method($verb) |
|
179 | - ->action($handler); |
|
180 | - |
|
181 | - // optionally register requirements for route. This is used to |
|
182 | - // tell the route parser how url parameters should be matched |
|
183 | - if(array_key_exists('requirements', $simpleRoute)) { |
|
184 | - $router->requirements($simpleRoute['requirements']); |
|
185 | - } |
|
186 | - |
|
187 | - // optionally register defaults for route. This is used to |
|
188 | - // tell the route parser how url parameters should be default valued |
|
189 | - if(array_key_exists('defaults', $simpleRoute)) { |
|
190 | - $router->defaults($simpleRoute['defaults']); |
|
191 | - } |
|
192 | - } |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * For a given name and url restful OCS routes are created: |
|
197 | - * - index |
|
198 | - * - show |
|
199 | - * - create |
|
200 | - * - update |
|
201 | - * - destroy |
|
202 | - * |
|
203 | - * @param array $routes |
|
204 | - */ |
|
205 | - private function processOCSResources(array $routes): void { |
|
206 | - // declaration of all restful actions |
|
207 | - $actions = [ |
|
208 | - ['name' => 'index', 'verb' => 'GET', 'on-collection' => true], |
|
209 | - ['name' => 'show', 'verb' => 'GET'], |
|
210 | - ['name' => 'create', 'verb' => 'POST', 'on-collection' => true], |
|
211 | - ['name' => 'update', 'verb' => 'PUT'], |
|
212 | - ['name' => 'destroy', 'verb' => 'DELETE'], |
|
213 | - ]; |
|
214 | - |
|
215 | - $resources = $routes['ocs-resources'] ?? []; |
|
216 | - foreach ($resources as $resource => $config) { |
|
217 | - $root = $config['root'] ?? '/apps/' . $this->appName; |
|
218 | - |
|
219 | - // the url parameter used as id to the resource |
|
220 | - foreach($actions as $action) { |
|
221 | - $url = $root . $config['url']; |
|
222 | - $method = $action['name']; |
|
223 | - $verb = strtoupper($action['verb'] ?? 'GET'); |
|
224 | - $collectionAction = $action['on-collection'] ?? false; |
|
225 | - if (!$collectionAction) { |
|
226 | - $url .= '/{id}'; |
|
227 | - } |
|
228 | - if (isset($action['url-postfix'])) { |
|
229 | - $url .= '/' . $action['url-postfix']; |
|
230 | - } |
|
231 | - |
|
232 | - $controller = $resource; |
|
233 | - |
|
234 | - $controllerName = $this->buildControllerName($controller); |
|
235 | - $actionName = $this->buildActionName($method); |
|
236 | - |
|
237 | - $routeName = 'ocs.' . $this->appName . '.' . strtolower($resource) . '.' . strtolower($method); |
|
238 | - |
|
239 | - $this->router->create($routeName, $url)->method($verb)->action( |
|
240 | - new RouteActionHandler($this->container, $controllerName, $actionName) |
|
241 | - ); |
|
242 | - } |
|
243 | - } |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * For a given name and url restful routes are created: |
|
248 | - * - index |
|
249 | - * - show |
|
250 | - * - create |
|
251 | - * - update |
|
252 | - * - destroy |
|
253 | - * |
|
254 | - * @param array $routes |
|
255 | - */ |
|
256 | - private function processResources(array $routes): void { |
|
257 | - // declaration of all restful actions |
|
258 | - $actions = [ |
|
259 | - ['name' => 'index', 'verb' => 'GET', 'on-collection' => true], |
|
260 | - ['name' => 'show', 'verb' => 'GET'], |
|
261 | - ['name' => 'create', 'verb' => 'POST', 'on-collection' => true], |
|
262 | - ['name' => 'update', 'verb' => 'PUT'], |
|
263 | - ['name' => 'destroy', 'verb' => 'DELETE'], |
|
264 | - ]; |
|
265 | - |
|
266 | - $resources = $routes['resources'] ?? []; |
|
267 | - foreach ($resources as $resource => $config) { |
|
268 | - |
|
269 | - // the url parameter used as id to the resource |
|
270 | - foreach($actions as $action) { |
|
271 | - $url = $config['url']; |
|
272 | - $method = $action['name']; |
|
273 | - $verb = strtoupper($action['verb'] ?? 'GET'); |
|
274 | - $collectionAction = $action['on-collection'] ?? false; |
|
275 | - if (!$collectionAction) { |
|
276 | - $url .= '/{id}'; |
|
277 | - } |
|
278 | - if (isset($action['url-postfix'])) { |
|
279 | - $url .= '/' . $action['url-postfix']; |
|
280 | - } |
|
281 | - |
|
282 | - $controller = $resource; |
|
283 | - |
|
284 | - $controllerName = $this->buildControllerName($controller); |
|
285 | - $actionName = $this->buildActionName($method); |
|
286 | - |
|
287 | - $routeName = $this->appName . '.' . strtolower($resource) . '.' . strtolower($method); |
|
288 | - |
|
289 | - $this->router->create($routeName, $url)->method($verb)->action( |
|
290 | - new RouteActionHandler($this->container, $controllerName, $actionName) |
|
291 | - ); |
|
292 | - } |
|
293 | - } |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * Based on a given route name the controller name is generated |
|
298 | - * @param string $controller |
|
299 | - * @return string |
|
300 | - */ |
|
301 | - private function buildControllerName(string $controller): string { |
|
302 | - if (!isset($this->controllerNameCache[$controller])) { |
|
303 | - $this->controllerNameCache[$controller] = $this->underScoreToCamelCase(ucfirst($controller)) . 'Controller'; |
|
304 | - } |
|
305 | - return $this->controllerNameCache[$controller]; |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Based on the action part of the route name the controller method name is generated |
|
310 | - * @param string $action |
|
311 | - * @return string |
|
312 | - */ |
|
313 | - private function buildActionName(string $action): string { |
|
314 | - return $this->underScoreToCamelCase($action); |
|
315 | - } |
|
316 | - |
|
317 | - /** |
|
318 | - * Underscored strings are converted to camel case strings |
|
319 | - * @param string $str |
|
320 | - * @return string |
|
321 | - */ |
|
322 | - private function underScoreToCamelCase(string $str): string { |
|
323 | - $pattern = '/_[a-z]?/'; |
|
324 | - return preg_replace_callback( |
|
325 | - $pattern, |
|
326 | - function ($matches) { |
|
327 | - return strtoupper(ltrim($matches[0], '_')); |
|
328 | - }, |
|
329 | - $str); |
|
330 | - } |
|
83 | + $oldCollection = $this->router->getCurrentCollection(); |
|
84 | + $this->router->useCollection($oldCollection . '.ocs'); |
|
85 | + |
|
86 | + // parse ocs simple routes |
|
87 | + $this->processOCS($this->routes); |
|
88 | + |
|
89 | + // parse ocs simple routes |
|
90 | + $this->processOCSResources($this->routes); |
|
91 | + |
|
92 | + $this->router->useCollection($oldCollection); |
|
93 | + } |
|
94 | + |
|
95 | + private function processOCS(array $routes): void { |
|
96 | + $ocsRoutes = $routes['ocs'] ?? []; |
|
97 | + foreach ($ocsRoutes as $ocsRoute) { |
|
98 | + $name = $ocsRoute['name']; |
|
99 | + $postfix = $ocsRoute['postfix'] ?? ''; |
|
100 | + $root = $ocsRoute['root'] ?? '/apps/' . $this->appName; |
|
101 | + |
|
102 | + $url = $root . $ocsRoute['url']; |
|
103 | + $verb = strtoupper($ocsRoute['verb'] ?? 'GET'); |
|
104 | + |
|
105 | + $split = explode('#', $name, 2); |
|
106 | + if (count($split) !== 2) { |
|
107 | + throw new \UnexpectedValueException('Invalid route name'); |
|
108 | + } |
|
109 | + list($controller, $action) = $split; |
|
110 | + |
|
111 | + $controllerName = $this->buildControllerName($controller); |
|
112 | + $actionName = $this->buildActionName($action); |
|
113 | + |
|
114 | + $routeName = 'ocs.' . $this->appName . '.' . $controller . '.' . $action . $postfix; |
|
115 | + |
|
116 | + // register the route |
|
117 | + $handler = new RouteActionHandler($this->container, $controllerName, $actionName); |
|
118 | + |
|
119 | + $router = $this->router->create($routeName, $url) |
|
120 | + ->method($verb) |
|
121 | + ->action($handler); |
|
122 | + |
|
123 | + // optionally register requirements for route. This is used to |
|
124 | + // tell the route parser how url parameters should be matched |
|
125 | + if(array_key_exists('requirements', $ocsRoute)) { |
|
126 | + $router->requirements($ocsRoute['requirements']); |
|
127 | + } |
|
128 | + |
|
129 | + // optionally register defaults for route. This is used to |
|
130 | + // tell the route parser how url parameters should be default valued |
|
131 | + if(array_key_exists('defaults', $ocsRoute)) { |
|
132 | + $router->defaults($ocsRoute['defaults']); |
|
133 | + } |
|
134 | + } |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Creates one route base on the give configuration |
|
139 | + * @param array $routes |
|
140 | + * @throws \UnexpectedValueException |
|
141 | + */ |
|
142 | + private function processSimpleRoutes(array $routes): void { |
|
143 | + $simpleRoutes = $routes['routes'] ?? []; |
|
144 | + foreach ($simpleRoutes as $simpleRoute) { |
|
145 | + $name = $simpleRoute['name']; |
|
146 | + $postfix = $simpleRoute['postfix'] ?? ''; |
|
147 | + |
|
148 | + $url = $simpleRoute['url']; |
|
149 | + $verb = strtoupper($simpleRoute['verb'] ?? 'GET'); |
|
150 | + |
|
151 | + $split = explode('#', $name, 2); |
|
152 | + if (count($split) !== 2) { |
|
153 | + throw new \UnexpectedValueException('Invalid route name'); |
|
154 | + } |
|
155 | + list($controller, $action) = $split; |
|
156 | + |
|
157 | + $controllerName = $this->buildControllerName($controller); |
|
158 | + $actionName = $this->buildActionName($action); |
|
159 | + $appName = $simpleRoute['app'] ?? $this->appName; |
|
160 | + |
|
161 | + if (isset($simpleRoute['app'])) { |
|
162 | + // Legacy routes that need to be globally available while they are handled by an app |
|
163 | + // E.g. '/f/{id}', '/s/{token}', '/call/{token}', … |
|
164 | + $controllerName = str_replace('controllerController', 'Controller', $controllerName); |
|
165 | + if ($controllerName === 'PublicpreviewController') { |
|
166 | + $controllerName = 'PublicPreviewController'; |
|
167 | + } else if ($controllerName === 'RequesthandlerController') { |
|
168 | + $controllerName = 'RequestHandlerController'; |
|
169 | + } |
|
170 | + $controllerName = App::buildAppNamespace($appName) . '\\Controller\\' . $controllerName; |
|
171 | + } |
|
172 | + |
|
173 | + $routeName = $appName . '.' . $controller . '.' . $action . $postfix; |
|
174 | + |
|
175 | + // register the route |
|
176 | + $handler = new RouteActionHandler($this->container, $controllerName, $actionName); |
|
177 | + $router = $this->router->create($routeName, $url) |
|
178 | + ->method($verb) |
|
179 | + ->action($handler); |
|
180 | + |
|
181 | + // optionally register requirements for route. This is used to |
|
182 | + // tell the route parser how url parameters should be matched |
|
183 | + if(array_key_exists('requirements', $simpleRoute)) { |
|
184 | + $router->requirements($simpleRoute['requirements']); |
|
185 | + } |
|
186 | + |
|
187 | + // optionally register defaults for route. This is used to |
|
188 | + // tell the route parser how url parameters should be default valued |
|
189 | + if(array_key_exists('defaults', $simpleRoute)) { |
|
190 | + $router->defaults($simpleRoute['defaults']); |
|
191 | + } |
|
192 | + } |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * For a given name and url restful OCS routes are created: |
|
197 | + * - index |
|
198 | + * - show |
|
199 | + * - create |
|
200 | + * - update |
|
201 | + * - destroy |
|
202 | + * |
|
203 | + * @param array $routes |
|
204 | + */ |
|
205 | + private function processOCSResources(array $routes): void { |
|
206 | + // declaration of all restful actions |
|
207 | + $actions = [ |
|
208 | + ['name' => 'index', 'verb' => 'GET', 'on-collection' => true], |
|
209 | + ['name' => 'show', 'verb' => 'GET'], |
|
210 | + ['name' => 'create', 'verb' => 'POST', 'on-collection' => true], |
|
211 | + ['name' => 'update', 'verb' => 'PUT'], |
|
212 | + ['name' => 'destroy', 'verb' => 'DELETE'], |
|
213 | + ]; |
|
214 | + |
|
215 | + $resources = $routes['ocs-resources'] ?? []; |
|
216 | + foreach ($resources as $resource => $config) { |
|
217 | + $root = $config['root'] ?? '/apps/' . $this->appName; |
|
218 | + |
|
219 | + // the url parameter used as id to the resource |
|
220 | + foreach($actions as $action) { |
|
221 | + $url = $root . $config['url']; |
|
222 | + $method = $action['name']; |
|
223 | + $verb = strtoupper($action['verb'] ?? 'GET'); |
|
224 | + $collectionAction = $action['on-collection'] ?? false; |
|
225 | + if (!$collectionAction) { |
|
226 | + $url .= '/{id}'; |
|
227 | + } |
|
228 | + if (isset($action['url-postfix'])) { |
|
229 | + $url .= '/' . $action['url-postfix']; |
|
230 | + } |
|
231 | + |
|
232 | + $controller = $resource; |
|
233 | + |
|
234 | + $controllerName = $this->buildControllerName($controller); |
|
235 | + $actionName = $this->buildActionName($method); |
|
236 | + |
|
237 | + $routeName = 'ocs.' . $this->appName . '.' . strtolower($resource) . '.' . strtolower($method); |
|
238 | + |
|
239 | + $this->router->create($routeName, $url)->method($verb)->action( |
|
240 | + new RouteActionHandler($this->container, $controllerName, $actionName) |
|
241 | + ); |
|
242 | + } |
|
243 | + } |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * For a given name and url restful routes are created: |
|
248 | + * - index |
|
249 | + * - show |
|
250 | + * - create |
|
251 | + * - update |
|
252 | + * - destroy |
|
253 | + * |
|
254 | + * @param array $routes |
|
255 | + */ |
|
256 | + private function processResources(array $routes): void { |
|
257 | + // declaration of all restful actions |
|
258 | + $actions = [ |
|
259 | + ['name' => 'index', 'verb' => 'GET', 'on-collection' => true], |
|
260 | + ['name' => 'show', 'verb' => 'GET'], |
|
261 | + ['name' => 'create', 'verb' => 'POST', 'on-collection' => true], |
|
262 | + ['name' => 'update', 'verb' => 'PUT'], |
|
263 | + ['name' => 'destroy', 'verb' => 'DELETE'], |
|
264 | + ]; |
|
265 | + |
|
266 | + $resources = $routes['resources'] ?? []; |
|
267 | + foreach ($resources as $resource => $config) { |
|
268 | + |
|
269 | + // the url parameter used as id to the resource |
|
270 | + foreach($actions as $action) { |
|
271 | + $url = $config['url']; |
|
272 | + $method = $action['name']; |
|
273 | + $verb = strtoupper($action['verb'] ?? 'GET'); |
|
274 | + $collectionAction = $action['on-collection'] ?? false; |
|
275 | + if (!$collectionAction) { |
|
276 | + $url .= '/{id}'; |
|
277 | + } |
|
278 | + if (isset($action['url-postfix'])) { |
|
279 | + $url .= '/' . $action['url-postfix']; |
|
280 | + } |
|
281 | + |
|
282 | + $controller = $resource; |
|
283 | + |
|
284 | + $controllerName = $this->buildControllerName($controller); |
|
285 | + $actionName = $this->buildActionName($method); |
|
286 | + |
|
287 | + $routeName = $this->appName . '.' . strtolower($resource) . '.' . strtolower($method); |
|
288 | + |
|
289 | + $this->router->create($routeName, $url)->method($verb)->action( |
|
290 | + new RouteActionHandler($this->container, $controllerName, $actionName) |
|
291 | + ); |
|
292 | + } |
|
293 | + } |
|
294 | + } |
|
295 | + |
|
296 | + /** |
|
297 | + * Based on a given route name the controller name is generated |
|
298 | + * @param string $controller |
|
299 | + * @return string |
|
300 | + */ |
|
301 | + private function buildControllerName(string $controller): string { |
|
302 | + if (!isset($this->controllerNameCache[$controller])) { |
|
303 | + $this->controllerNameCache[$controller] = $this->underScoreToCamelCase(ucfirst($controller)) . 'Controller'; |
|
304 | + } |
|
305 | + return $this->controllerNameCache[$controller]; |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Based on the action part of the route name the controller method name is generated |
|
310 | + * @param string $action |
|
311 | + * @return string |
|
312 | + */ |
|
313 | + private function buildActionName(string $action): string { |
|
314 | + return $this->underScoreToCamelCase($action); |
|
315 | + } |
|
316 | + |
|
317 | + /** |
|
318 | + * Underscored strings are converted to camel case strings |
|
319 | + * @param string $str |
|
320 | + * @return string |
|
321 | + */ |
|
322 | + private function underScoreToCamelCase(string $str): string { |
|
323 | + $pattern = '/_[a-z]?/'; |
|
324 | + return preg_replace_callback( |
|
325 | + $pattern, |
|
326 | + function ($matches) { |
|
327 | + return strtoupper(ltrim($matches[0], '_')); |
|
328 | + }, |
|
329 | + $str); |
|
330 | + } |
|
331 | 331 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * OCS routes go into a different collection |
82 | 82 | */ |
83 | 83 | $oldCollection = $this->router->getCurrentCollection(); |
84 | - $this->router->useCollection($oldCollection . '.ocs'); |
|
84 | + $this->router->useCollection($oldCollection.'.ocs'); |
|
85 | 85 | |
86 | 86 | // parse ocs simple routes |
87 | 87 | $this->processOCS($this->routes); |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | foreach ($ocsRoutes as $ocsRoute) { |
98 | 98 | $name = $ocsRoute['name']; |
99 | 99 | $postfix = $ocsRoute['postfix'] ?? ''; |
100 | - $root = $ocsRoute['root'] ?? '/apps/' . $this->appName; |
|
100 | + $root = $ocsRoute['root'] ?? '/apps/'.$this->appName; |
|
101 | 101 | |
102 | - $url = $root . $ocsRoute['url']; |
|
102 | + $url = $root.$ocsRoute['url']; |
|
103 | 103 | $verb = strtoupper($ocsRoute['verb'] ?? 'GET'); |
104 | 104 | |
105 | 105 | $split = explode('#', $name, 2); |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | $controllerName = $this->buildControllerName($controller); |
112 | 112 | $actionName = $this->buildActionName($action); |
113 | 113 | |
114 | - $routeName = 'ocs.' . $this->appName . '.' . $controller . '.' . $action . $postfix; |
|
114 | + $routeName = 'ocs.'.$this->appName.'.'.$controller.'.'.$action.$postfix; |
|
115 | 115 | |
116 | 116 | // register the route |
117 | 117 | $handler = new RouteActionHandler($this->container, $controllerName, $actionName); |
@@ -122,13 +122,13 @@ discard block |
||
122 | 122 | |
123 | 123 | // optionally register requirements for route. This is used to |
124 | 124 | // tell the route parser how url parameters should be matched |
125 | - if(array_key_exists('requirements', $ocsRoute)) { |
|
125 | + if (array_key_exists('requirements', $ocsRoute)) { |
|
126 | 126 | $router->requirements($ocsRoute['requirements']); |
127 | 127 | } |
128 | 128 | |
129 | 129 | // optionally register defaults for route. This is used to |
130 | 130 | // tell the route parser how url parameters should be default valued |
131 | - if(array_key_exists('defaults', $ocsRoute)) { |
|
131 | + if (array_key_exists('defaults', $ocsRoute)) { |
|
132 | 132 | $router->defaults($ocsRoute['defaults']); |
133 | 133 | } |
134 | 134 | } |
@@ -167,10 +167,10 @@ discard block |
||
167 | 167 | } else if ($controllerName === 'RequesthandlerController') { |
168 | 168 | $controllerName = 'RequestHandlerController'; |
169 | 169 | } |
170 | - $controllerName = App::buildAppNamespace($appName) . '\\Controller\\' . $controllerName; |
|
170 | + $controllerName = App::buildAppNamespace($appName).'\\Controller\\'.$controllerName; |
|
171 | 171 | } |
172 | 172 | |
173 | - $routeName = $appName . '.' . $controller . '.' . $action . $postfix; |
|
173 | + $routeName = $appName.'.'.$controller.'.'.$action.$postfix; |
|
174 | 174 | |
175 | 175 | // register the route |
176 | 176 | $handler = new RouteActionHandler($this->container, $controllerName, $actionName); |
@@ -180,13 +180,13 @@ discard block |
||
180 | 180 | |
181 | 181 | // optionally register requirements for route. This is used to |
182 | 182 | // tell the route parser how url parameters should be matched |
183 | - if(array_key_exists('requirements', $simpleRoute)) { |
|
183 | + if (array_key_exists('requirements', $simpleRoute)) { |
|
184 | 184 | $router->requirements($simpleRoute['requirements']); |
185 | 185 | } |
186 | 186 | |
187 | 187 | // optionally register defaults for route. This is used to |
188 | 188 | // tell the route parser how url parameters should be default valued |
189 | - if(array_key_exists('defaults', $simpleRoute)) { |
|
189 | + if (array_key_exists('defaults', $simpleRoute)) { |
|
190 | 190 | $router->defaults($simpleRoute['defaults']); |
191 | 191 | } |
192 | 192 | } |
@@ -214,11 +214,11 @@ discard block |
||
214 | 214 | |
215 | 215 | $resources = $routes['ocs-resources'] ?? []; |
216 | 216 | foreach ($resources as $resource => $config) { |
217 | - $root = $config['root'] ?? '/apps/' . $this->appName; |
|
217 | + $root = $config['root'] ?? '/apps/'.$this->appName; |
|
218 | 218 | |
219 | 219 | // the url parameter used as id to the resource |
220 | - foreach($actions as $action) { |
|
221 | - $url = $root . $config['url']; |
|
220 | + foreach ($actions as $action) { |
|
221 | + $url = $root.$config['url']; |
|
222 | 222 | $method = $action['name']; |
223 | 223 | $verb = strtoupper($action['verb'] ?? 'GET'); |
224 | 224 | $collectionAction = $action['on-collection'] ?? false; |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | $url .= '/{id}'; |
227 | 227 | } |
228 | 228 | if (isset($action['url-postfix'])) { |
229 | - $url .= '/' . $action['url-postfix']; |
|
229 | + $url .= '/'.$action['url-postfix']; |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | $controller = $resource; |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | $controllerName = $this->buildControllerName($controller); |
235 | 235 | $actionName = $this->buildActionName($method); |
236 | 236 | |
237 | - $routeName = 'ocs.' . $this->appName . '.' . strtolower($resource) . '.' . strtolower($method); |
|
237 | + $routeName = 'ocs.'.$this->appName.'.'.strtolower($resource).'.'.strtolower($method); |
|
238 | 238 | |
239 | 239 | $this->router->create($routeName, $url)->method($verb)->action( |
240 | 240 | new RouteActionHandler($this->container, $controllerName, $actionName) |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | foreach ($resources as $resource => $config) { |
268 | 268 | |
269 | 269 | // the url parameter used as id to the resource |
270 | - foreach($actions as $action) { |
|
270 | + foreach ($actions as $action) { |
|
271 | 271 | $url = $config['url']; |
272 | 272 | $method = $action['name']; |
273 | 273 | $verb = strtoupper($action['verb'] ?? 'GET'); |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | $url .= '/{id}'; |
277 | 277 | } |
278 | 278 | if (isset($action['url-postfix'])) { |
279 | - $url .= '/' . $action['url-postfix']; |
|
279 | + $url .= '/'.$action['url-postfix']; |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | $controller = $resource; |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | $controllerName = $this->buildControllerName($controller); |
285 | 285 | $actionName = $this->buildActionName($method); |
286 | 286 | |
287 | - $routeName = $this->appName . '.' . strtolower($resource) . '.' . strtolower($method); |
|
287 | + $routeName = $this->appName.'.'.strtolower($resource).'.'.strtolower($method); |
|
288 | 288 | |
289 | 289 | $this->router->create($routeName, $url)->method($verb)->action( |
290 | 290 | new RouteActionHandler($this->container, $controllerName, $actionName) |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | */ |
301 | 301 | private function buildControllerName(string $controller): string { |
302 | 302 | if (!isset($this->controllerNameCache[$controller])) { |
303 | - $this->controllerNameCache[$controller] = $this->underScoreToCamelCase(ucfirst($controller)) . 'Controller'; |
|
303 | + $this->controllerNameCache[$controller] = $this->underScoreToCamelCase(ucfirst($controller)).'Controller'; |
|
304 | 304 | } |
305 | 305 | return $this->controllerNameCache[$controller]; |
306 | 306 | } |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | $pattern = '/_[a-z]?/'; |
324 | 324 | return preg_replace_callback( |
325 | 325 | $pattern, |
326 | - function ($matches) { |
|
326 | + function($matches) { |
|
327 | 327 | return strtoupper(ltrim($matches[0], '_')); |
328 | 328 | }, |
329 | 329 | $str); |
@@ -46,150 +46,150 @@ |
||
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 | - if ($httpHeaders !== Http::STATUS_NO_CONTENT && $httpHeaders !== Http::STATUS_NOT_MODIFIED) { |
|
161 | - if ($response instanceof ICallbackResponse) { |
|
162 | - $response->callback($io); |
|
163 | - } else if (!is_null($output)) { |
|
164 | - $io->setHeader('Content-Length: ' . strlen($output)); |
|
165 | - $io->setOutput($output); |
|
166 | - } |
|
167 | - } |
|
168 | - |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * Shortcut for calling a controller method and printing the result. |
|
173 | - * Similar to App:main except that no headers will be sent. |
|
174 | - * This should be used for example when registering sections via |
|
175 | - * \OC\AppFramework\Core\API::registerAdmin() |
|
176 | - * |
|
177 | - * @param string $controllerName the name of the controller under which it is |
|
178 | - * stored in the DI container |
|
179 | - * @param string $methodName the method that you want to call |
|
180 | - * @param array $urlParams an array with variables extracted from the routes |
|
181 | - * @param DIContainer $container an instance of a pimple container. |
|
182 | - */ |
|
183 | - public static function part(string $controllerName, string $methodName, array $urlParams, |
|
184 | - DIContainer $container){ |
|
185 | - |
|
186 | - $container['urlParams'] = $urlParams; |
|
187 | - $controller = $container[$controllerName]; |
|
188 | - |
|
189 | - $dispatcher = $container['Dispatcher']; |
|
190 | - |
|
191 | - list(, , $output) = $dispatcher->dispatch($controller, $methodName); |
|
192 | - return $output; |
|
193 | - } |
|
160 | + if ($httpHeaders !== Http::STATUS_NO_CONTENT && $httpHeaders !== Http::STATUS_NOT_MODIFIED) { |
|
161 | + if ($response instanceof ICallbackResponse) { |
|
162 | + $response->callback($io); |
|
163 | + } else if (!is_null($output)) { |
|
164 | + $io->setHeader('Content-Length: ' . strlen($output)); |
|
165 | + $io->setOutput($output); |
|
166 | + } |
|
167 | + } |
|
168 | + |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * Shortcut for calling a controller method and printing the result. |
|
173 | + * Similar to App:main except that no headers will be sent. |
|
174 | + * This should be used for example when registering sections via |
|
175 | + * \OC\AppFramework\Core\API::registerAdmin() |
|
176 | + * |
|
177 | + * @param string $controllerName the name of the controller under which it is |
|
178 | + * stored in the DI container |
|
179 | + * @param string $methodName the method that you want to call |
|
180 | + * @param array $urlParams an array with variables extracted from the routes |
|
181 | + * @param DIContainer $container an instance of a pimple container. |
|
182 | + */ |
|
183 | + public static function part(string $controllerName, string $methodName, array $urlParams, |
|
184 | + DIContainer $container){ |
|
185 | + |
|
186 | + $container['urlParams'] = $urlParams; |
|
187 | + $controller = $container[$controllerName]; |
|
188 | + |
|
189 | + $dispatcher = $container['Dispatcher']; |
|
190 | + |
|
191 | + list(, , $output) = $dispatcher->dispatch($controller, $methodName); |
|
192 | + return $output; |
|
193 | + } |
|
194 | 194 | |
195 | 195 | } |
@@ -57,10 +57,10 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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( |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | if ($response instanceof ICallbackResponse) { |
162 | 162 | $response->callback($io); |
163 | 163 | } else if (!is_null($output)) { |
164 | - $io->setHeader('Content-Length: ' . strlen($output)); |
|
164 | + $io->setHeader('Content-Length: '.strlen($output)); |
|
165 | 165 | $io->setOutput($output); |
166 | 166 | } |
167 | 167 | } |
@@ -181,14 +181,14 @@ discard block |
||
181 | 181 | * @param DIContainer $container an instance of a pimple container. |
182 | 182 | */ |
183 | 183 | public static function part(string $controllerName, string $methodName, array $urlParams, |
184 | - DIContainer $container){ |
|
184 | + DIContainer $container) { |
|
185 | 185 | |
186 | 186 | $container['urlParams'] = $urlParams; |
187 | 187 | $controller = $container[$controllerName]; |
188 | 188 | |
189 | 189 | $dispatcher = $container['Dispatcher']; |
190 | 190 | |
191 | - list(, , $output) = $dispatcher->dispatch($controller, $methodName); |
|
191 | + list(,, $output) = $dispatcher->dispatch($controller, $methodName); |
|
192 | 192 | return $output; |
193 | 193 | } |
194 | 194 |
@@ -36,81 +36,81 @@ discard block |
||
36 | 36 | |
37 | 37 | $application = new Application(); |
38 | 38 | $application->registerRoutes($this, [ |
39 | - 'routes' => [ |
|
40 | - ['name' => 'lost#email', 'url' => '/lostpassword/email', 'verb' => 'POST'], |
|
41 | - ['name' => 'lost#resetform', 'url' => '/lostpassword/reset/form/{token}/{userId}', 'verb' => 'GET'], |
|
42 | - ['name' => 'lost#setPassword', 'url' => '/lostpassword/set/{token}/{userId}', 'verb' => 'POST'], |
|
43 | - ['name' => 'user#getDisplayNames', 'url' => '/displaynames', 'verb' => 'POST'], |
|
44 | - ['name' => 'avatar#getAvatar', 'url' => '/avatar/{userId}/{size}', 'verb' => 'GET'], |
|
45 | - ['name' => 'avatar#deleteAvatar', 'url' => '/avatar/', 'verb' => 'DELETE'], |
|
46 | - ['name' => 'avatar#postCroppedAvatar', 'url' => '/avatar/cropped', 'verb' => 'POST'], |
|
47 | - ['name' => 'avatar#getTmpAvatar', 'url' => '/avatar/tmp', 'verb' => 'GET'], |
|
48 | - ['name' => 'avatar#postAvatar', 'url' => '/avatar/', 'verb' => 'POST'], |
|
49 | - ['name' => 'GuestAvatar#getAvatar', 'url' => '/avatar/guest/{guestName}/{size}', 'verb' => 'GET'], |
|
50 | - ['name' => 'CSRFToken#index', 'url' => '/csrftoken', 'verb' => 'GET'], |
|
51 | - ['name' => 'login#tryLogin', 'url' => '/login', 'verb' => 'POST'], |
|
52 | - ['name' => 'login#confirmPassword', 'url' => '/login/confirm', 'verb' => 'POST'], |
|
53 | - ['name' => 'login#showLoginForm', 'url' => '/login', 'verb' => 'GET'], |
|
54 | - ['name' => 'login#logout', 'url' => '/logout', 'verb' => 'GET'], |
|
55 | - // Original login flow used by all clients |
|
56 | - ['name' => 'ClientFlowLogin#showAuthPickerPage', 'url' => '/login/flow', 'verb' => 'GET'], |
|
57 | - ['name' => 'ClientFlowLogin#generateAppPassword', 'url' => '/login/flow', 'verb' => 'POST'], |
|
58 | - ['name' => 'ClientFlowLogin#grantPage', 'url' => '/login/flow/grant', 'verb' => 'GET'], |
|
59 | - ['name' => 'ClientFlowLogin#apptokenRedirect', 'url' => '/login/flow/apptoken', 'verb' => 'POST'], |
|
60 | - // NG login flow used by desktop client in case of Kerberos/fancy 2fa (smart cards for example) |
|
61 | - ['name' => 'ClientFlowLoginV2#poll', 'url' => '/login/v2/poll', 'verb' => 'POST'], |
|
62 | - ['name' => 'ClientFlowLoginV2#showAuthPickerPage', 'url' => '/login/v2/flow', 'verb' => 'GET'], |
|
63 | - ['name' => 'ClientFlowLoginV2#landing', 'url' => '/login/v2/flow/{token}', 'verb' => 'GET'], |
|
64 | - ['name' => 'ClientFlowLoginV2#grantPage', 'url' => '/login/v2/grant', 'verb' => 'GET'], |
|
65 | - ['name' => 'ClientFlowLoginV2#generateAppPassword', 'url' => '/login/v2/grant', 'verb' => 'POST'], |
|
66 | - ['name' => 'ClientFlowLoginV2#init', 'url' => '/login/v2', 'verb' => 'POST'], |
|
67 | - ['name' => 'TwoFactorChallenge#selectChallenge', 'url' => '/login/selectchallenge', 'verb' => 'GET'], |
|
68 | - ['name' => 'TwoFactorChallenge#showChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'GET'], |
|
69 | - ['name' => 'TwoFactorChallenge#solveChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'POST'], |
|
70 | - ['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'], |
|
71 | - ['name' => 'Preview#getPreviewByFileId', 'url' => '/core/preview', 'verb' => 'GET'], |
|
72 | - ['name' => 'Preview#getPreview', 'url' => '/core/preview.png', 'verb' => 'GET'], |
|
73 | - ['name' => 'Svg#getSvgFromCore', 'url' => '/svg/core/{folder}/{fileName}', 'verb' => 'GET'], |
|
74 | - ['name' => 'Svg#getSvgFromApp', 'url' => '/svg/{app}/{fileName}', 'verb' => 'GET'], |
|
75 | - ['name' => 'Css#getCss', 'url' => '/css/{appName}/{fileName}', 'verb' => 'GET'], |
|
76 | - ['name' => 'Js#getJs', 'url' => '/js/{appName}/{fileName}', 'verb' => 'GET'], |
|
77 | - ['name' => 'contactsMenu#index', 'url' => '/contactsmenu/contacts', 'verb' => 'POST'], |
|
78 | - ['name' => 'contactsMenu#findOne', 'url' => '/contactsmenu/findOne', 'verb' => 'POST'], |
|
79 | - ['name' => 'WalledGarden#get', 'url' => '/204', 'verb' => 'GET'], |
|
80 | - ['name' => 'Search#search', 'url' => '/core/search', 'verb' => 'GET'], |
|
39 | + 'routes' => [ |
|
40 | + ['name' => 'lost#email', 'url' => '/lostpassword/email', 'verb' => 'POST'], |
|
41 | + ['name' => 'lost#resetform', 'url' => '/lostpassword/reset/form/{token}/{userId}', 'verb' => 'GET'], |
|
42 | + ['name' => 'lost#setPassword', 'url' => '/lostpassword/set/{token}/{userId}', 'verb' => 'POST'], |
|
43 | + ['name' => 'user#getDisplayNames', 'url' => '/displaynames', 'verb' => 'POST'], |
|
44 | + ['name' => 'avatar#getAvatar', 'url' => '/avatar/{userId}/{size}', 'verb' => 'GET'], |
|
45 | + ['name' => 'avatar#deleteAvatar', 'url' => '/avatar/', 'verb' => 'DELETE'], |
|
46 | + ['name' => 'avatar#postCroppedAvatar', 'url' => '/avatar/cropped', 'verb' => 'POST'], |
|
47 | + ['name' => 'avatar#getTmpAvatar', 'url' => '/avatar/tmp', 'verb' => 'GET'], |
|
48 | + ['name' => 'avatar#postAvatar', 'url' => '/avatar/', 'verb' => 'POST'], |
|
49 | + ['name' => 'GuestAvatar#getAvatar', 'url' => '/avatar/guest/{guestName}/{size}', 'verb' => 'GET'], |
|
50 | + ['name' => 'CSRFToken#index', 'url' => '/csrftoken', 'verb' => 'GET'], |
|
51 | + ['name' => 'login#tryLogin', 'url' => '/login', 'verb' => 'POST'], |
|
52 | + ['name' => 'login#confirmPassword', 'url' => '/login/confirm', 'verb' => 'POST'], |
|
53 | + ['name' => 'login#showLoginForm', 'url' => '/login', 'verb' => 'GET'], |
|
54 | + ['name' => 'login#logout', 'url' => '/logout', 'verb' => 'GET'], |
|
55 | + // Original login flow used by all clients |
|
56 | + ['name' => 'ClientFlowLogin#showAuthPickerPage', 'url' => '/login/flow', 'verb' => 'GET'], |
|
57 | + ['name' => 'ClientFlowLogin#generateAppPassword', 'url' => '/login/flow', 'verb' => 'POST'], |
|
58 | + ['name' => 'ClientFlowLogin#grantPage', 'url' => '/login/flow/grant', 'verb' => 'GET'], |
|
59 | + ['name' => 'ClientFlowLogin#apptokenRedirect', 'url' => '/login/flow/apptoken', 'verb' => 'POST'], |
|
60 | + // NG login flow used by desktop client in case of Kerberos/fancy 2fa (smart cards for example) |
|
61 | + ['name' => 'ClientFlowLoginV2#poll', 'url' => '/login/v2/poll', 'verb' => 'POST'], |
|
62 | + ['name' => 'ClientFlowLoginV2#showAuthPickerPage', 'url' => '/login/v2/flow', 'verb' => 'GET'], |
|
63 | + ['name' => 'ClientFlowLoginV2#landing', 'url' => '/login/v2/flow/{token}', 'verb' => 'GET'], |
|
64 | + ['name' => 'ClientFlowLoginV2#grantPage', 'url' => '/login/v2/grant', 'verb' => 'GET'], |
|
65 | + ['name' => 'ClientFlowLoginV2#generateAppPassword', 'url' => '/login/v2/grant', 'verb' => 'POST'], |
|
66 | + ['name' => 'ClientFlowLoginV2#init', 'url' => '/login/v2', 'verb' => 'POST'], |
|
67 | + ['name' => 'TwoFactorChallenge#selectChallenge', 'url' => '/login/selectchallenge', 'verb' => 'GET'], |
|
68 | + ['name' => 'TwoFactorChallenge#showChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'GET'], |
|
69 | + ['name' => 'TwoFactorChallenge#solveChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'POST'], |
|
70 | + ['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'], |
|
71 | + ['name' => 'Preview#getPreviewByFileId', 'url' => '/core/preview', 'verb' => 'GET'], |
|
72 | + ['name' => 'Preview#getPreview', 'url' => '/core/preview.png', 'verb' => 'GET'], |
|
73 | + ['name' => 'Svg#getSvgFromCore', 'url' => '/svg/core/{folder}/{fileName}', 'verb' => 'GET'], |
|
74 | + ['name' => 'Svg#getSvgFromApp', 'url' => '/svg/{app}/{fileName}', 'verb' => 'GET'], |
|
75 | + ['name' => 'Css#getCss', 'url' => '/css/{appName}/{fileName}', 'verb' => 'GET'], |
|
76 | + ['name' => 'Js#getJs', 'url' => '/js/{appName}/{fileName}', 'verb' => 'GET'], |
|
77 | + ['name' => 'contactsMenu#index', 'url' => '/contactsmenu/contacts', 'verb' => 'POST'], |
|
78 | + ['name' => 'contactsMenu#findOne', 'url' => '/contactsmenu/findOne', 'verb' => 'POST'], |
|
79 | + ['name' => 'WalledGarden#get', 'url' => '/204', 'verb' => 'GET'], |
|
80 | + ['name' => 'Search#search', 'url' => '/core/search', 'verb' => 'GET'], |
|
81 | 81 | |
82 | - // Legacy routes that need to be globally available while they are handled by an app |
|
83 | - ['name' => 'viewcontroller#showFile', 'url' => '/f/{fileid}', 'verb' => 'GET', 'app' => 'files'], |
|
84 | - ['name' => 'sharecontroller#showShare', 'url' => '/s/{token}', 'verb' => 'GET', 'app' => 'files_sharing'], |
|
85 | - ['name' => 'sharecontroller#showAuthenticate', 'url' => '/s/{token}/authenticate/{redirect}', 'verb' => 'GET', 'app' => 'files_sharing'], |
|
86 | - ['name' => 'sharecontroller#authenticate', 'url' => '/s/{token}/authenticate/{redirect}', 'verb' => 'POST', 'app' => 'files_sharing'], |
|
87 | - ['name' => 'sharecontroller#downloadShare', 'url' => '/s/{token}/download', 'verb' => 'GET', 'app' => 'files_sharing'], |
|
88 | - ['name' => 'publicpreview#directLink', 'url' => '/s/{token}/preview', 'verb' => 'GET', 'app' => 'files_sharing'], |
|
89 | - ['name' => 'requesthandlercontroller#addShare', 'url' => '/ocm/shares', 'verb' => 'POST', 'app' => 'cloud_federation_api'], |
|
90 | - ['name' => 'requesthandlercontroller#receiveNotification', 'url' => '/ocm/notifications', 'verb' => 'POST', 'app' => 'cloud_federation_api'], |
|
91 | - ['name' => 'pagecontroller#showCall', 'url' => '/call/{token}', 'verb' => 'GET', 'app' => 'spreed'], |
|
92 | - ], |
|
93 | - 'ocs' => [ |
|
94 | - ['root' => '/cloud', 'name' => 'OCS#getCapabilities', 'url' => '/capabilities', 'verb' => 'GET'], |
|
95 | - ['root' => '', 'name' => 'OCS#getConfig', 'url' => '/config', 'verb' => 'GET'], |
|
96 | - ['root' => '/person', 'name' => 'OCS#personCheck', 'url' => '/check', 'verb' => 'POST'], |
|
97 | - ['root' => '/identityproof', 'name' => 'OCS#getIdentityProof', 'url' => '/key/{cloudId}', 'verb' => 'GET'], |
|
98 | - ['root' => '/core', 'name' => 'Navigation#getAppsNavigation', 'url' => '/navigation/apps', 'verb' => 'GET'], |
|
99 | - ['root' => '/core', 'name' => 'Navigation#getSettingsNavigation', 'url' => '/navigation/settings', 'verb' => 'GET'], |
|
100 | - ['root' => '/core', 'name' => 'AutoComplete#get', 'url' => '/autocomplete/get', 'verb' => 'GET'], |
|
101 | - ['root' => '/core', 'name' => 'WhatsNew#get', 'url' => '/whatsnew', 'verb' => 'GET'], |
|
102 | - ['root' => '/core', 'name' => 'WhatsNew#dismiss', 'url' => '/whatsnew', 'verb' => 'POST'], |
|
103 | - ['root' => '/core', 'name' => 'AppPassword#getAppPassword', 'url' => '/getapppassword', 'verb' => 'GET'], |
|
82 | + // Legacy routes that need to be globally available while they are handled by an app |
|
83 | + ['name' => 'viewcontroller#showFile', 'url' => '/f/{fileid}', 'verb' => 'GET', 'app' => 'files'], |
|
84 | + ['name' => 'sharecontroller#showShare', 'url' => '/s/{token}', 'verb' => 'GET', 'app' => 'files_sharing'], |
|
85 | + ['name' => 'sharecontroller#showAuthenticate', 'url' => '/s/{token}/authenticate/{redirect}', 'verb' => 'GET', 'app' => 'files_sharing'], |
|
86 | + ['name' => 'sharecontroller#authenticate', 'url' => '/s/{token}/authenticate/{redirect}', 'verb' => 'POST', 'app' => 'files_sharing'], |
|
87 | + ['name' => 'sharecontroller#downloadShare', 'url' => '/s/{token}/download', 'verb' => 'GET', 'app' => 'files_sharing'], |
|
88 | + ['name' => 'publicpreview#directLink', 'url' => '/s/{token}/preview', 'verb' => 'GET', 'app' => 'files_sharing'], |
|
89 | + ['name' => 'requesthandlercontroller#addShare', 'url' => '/ocm/shares', 'verb' => 'POST', 'app' => 'cloud_federation_api'], |
|
90 | + ['name' => 'requesthandlercontroller#receiveNotification', 'url' => '/ocm/notifications', 'verb' => 'POST', 'app' => 'cloud_federation_api'], |
|
91 | + ['name' => 'pagecontroller#showCall', 'url' => '/call/{token}', 'verb' => 'GET', 'app' => 'spreed'], |
|
92 | + ], |
|
93 | + 'ocs' => [ |
|
94 | + ['root' => '/cloud', 'name' => 'OCS#getCapabilities', 'url' => '/capabilities', 'verb' => 'GET'], |
|
95 | + ['root' => '', 'name' => 'OCS#getConfig', 'url' => '/config', 'verb' => 'GET'], |
|
96 | + ['root' => '/person', 'name' => 'OCS#personCheck', 'url' => '/check', 'verb' => 'POST'], |
|
97 | + ['root' => '/identityproof', 'name' => 'OCS#getIdentityProof', 'url' => '/key/{cloudId}', 'verb' => 'GET'], |
|
98 | + ['root' => '/core', 'name' => 'Navigation#getAppsNavigation', 'url' => '/navigation/apps', 'verb' => 'GET'], |
|
99 | + ['root' => '/core', 'name' => 'Navigation#getSettingsNavigation', 'url' => '/navigation/settings', 'verb' => 'GET'], |
|
100 | + ['root' => '/core', 'name' => 'AutoComplete#get', 'url' => '/autocomplete/get', 'verb' => 'GET'], |
|
101 | + ['root' => '/core', 'name' => 'WhatsNew#get', 'url' => '/whatsnew', 'verb' => 'GET'], |
|
102 | + ['root' => '/core', 'name' => 'WhatsNew#dismiss', 'url' => '/whatsnew', 'verb' => 'POST'], |
|
103 | + ['root' => '/core', 'name' => 'AppPassword#getAppPassword', 'url' => '/getapppassword', 'verb' => 'GET'], |
|
104 | 104 | |
105 | - ['root' => '/collaboration', 'name' => 'CollaborationResources#searchCollections', 'url' => '/resources/collections/search/{filter}', 'verb' => 'GET'], |
|
106 | - ['root' => '/collaboration', 'name' => 'CollaborationResources#listCollection', 'url' => '/resources/collections/{collectionId}', 'verb' => 'GET'], |
|
107 | - ['root' => '/collaboration', 'name' => 'CollaborationResources#renameCollection', 'url' => '/resources/collections/{collectionId}', 'verb' => 'PUT'], |
|
108 | - ['root' => '/collaboration', 'name' => 'CollaborationResources#addResource', 'url' => '/resources/collections/{collectionId}', 'verb' => 'POST'], |
|
105 | + ['root' => '/collaboration', 'name' => 'CollaborationResources#searchCollections', 'url' => '/resources/collections/search/{filter}', 'verb' => 'GET'], |
|
106 | + ['root' => '/collaboration', 'name' => 'CollaborationResources#listCollection', 'url' => '/resources/collections/{collectionId}', 'verb' => 'GET'], |
|
107 | + ['root' => '/collaboration', 'name' => 'CollaborationResources#renameCollection', 'url' => '/resources/collections/{collectionId}', 'verb' => 'PUT'], |
|
108 | + ['root' => '/collaboration', 'name' => 'CollaborationResources#addResource', 'url' => '/resources/collections/{collectionId}', 'verb' => 'POST'], |
|
109 | 109 | |
110 | - ['root' => '/collaboration', 'name' => 'CollaborationResources#removeResource', 'url' => '/resources/collections/{collectionId}', 'verb' => 'DELETE'], |
|
111 | - ['root' => '/collaboration', 'name' => 'CollaborationResources#getCollectionsByResource', 'url' => '/resources/{resourceType}/{resourceId}', 'verb' => 'GET'], |
|
112 | - ['root' => '/collaboration', 'name' => 'CollaborationResources#createCollectionOnResource', 'url' => '/resources/{baseResourceType}/{baseResourceId}', 'verb' => 'POST'], |
|
113 | - ], |
|
110 | + ['root' => '/collaboration', 'name' => 'CollaborationResources#removeResource', 'url' => '/resources/collections/{collectionId}', 'verb' => 'DELETE'], |
|
111 | + ['root' => '/collaboration', 'name' => 'CollaborationResources#getCollectionsByResource', 'url' => '/resources/{resourceType}/{resourceId}', 'verb' => 'GET'], |
|
112 | + ['root' => '/collaboration', 'name' => 'CollaborationResources#createCollectionOnResource', 'url' => '/resources/{baseResourceType}/{baseResourceId}', 'verb' => 'POST'], |
|
113 | + ], |
|
114 | 114 | ]); |
115 | 115 | |
116 | 116 | // Post installation check |
@@ -119,4 +119,4 @@ discard block |
||
119 | 119 | // Core ajax actions |
120 | 120 | // Routing |
121 | 121 | $this->create('core_ajax_update', '/core/ajax/update.php') |
122 | - ->actionInclude('core/ajax/update.php'); |
|
122 | + ->actionInclude('core/ajax/update.php'); |