Passed
Push — master ( 43fefe...afc596 )
by Joas
11:04 queued 11s
created
lib/public/AppFramework/App.php 2 patches
Indentation   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -53,134 +53,134 @@
 block discarded – undo
53 53
  */
54 54
 class App {
55 55
 
56
-	/** @var IAppContainer */
57
-	private $container;
58
-
59
-	/**
60
-	 * Turns an app id into a namespace by convention. The id is split at the
61
-	 * underscores, all parts are CamelCased and reassembled. e.g.:
62
-	 * some_app_id -> OCA\SomeAppId
63
-	 * @param string $appId the app id
64
-	 * @param string $topNamespace the namespace which should be prepended to
65
-	 * the transformed app id, defaults to OCA\
66
-	 * @return string the starting namespace for the app
67
-	 * @since 8.0.0
68
-	 */
69
-	public static function buildAppNamespace(string $appId, string $topNamespace='OCA\\'): string {
70
-		return \OC\AppFramework\App::buildAppNamespace($appId, $topNamespace);
71
-	}
72
-
73
-
74
-	/**
75
-	 * @param string $appName
76
-	 * @param array $urlParams an array with variables extracted from the routes
77
-	 * @since 6.0.0
78
-	 */
79
-	public function __construct(string $appName, array $urlParams = []) {
80
-		$runIsSetupDirectly = \OC::$server->getConfig()->getSystemValueBool('debug')
81
-			&& (PHP_VERSION_ID < 70400 || (PHP_VERSION_ID >= 70400 && !ini_get('zend.exception_ignore_args')));
82
-
83
-		if ($runIsSetupDirectly) {
84
-			$applicationClassName = get_class($this);
85
-			$e = new \RuntimeException('App class ' . $applicationClassName . ' is not setup via query() but directly');
86
-			$setUpViaQuery = false;
87
-
88
-			$classNameParts = explode('\\', trim($applicationClassName, '\\'));
89
-
90
-			foreach ($e->getTrace() as $step) {
91
-				if (isset($step['class'], $step['function'], $step['args'][0]) &&
92
-					$step['class'] === ServerContainer::class &&
93
-					$step['function'] === 'query' &&
94
-					$step['args'][0] === $applicationClassName) {
95
-					$setUpViaQuery = true;
96
-					break;
97
-				} elseif (isset($step['class'], $step['function'], $step['args'][0]) &&
98
-					$step['class'] === ServerContainer::class &&
99
-					$step['function'] === 'getAppContainer' &&
100
-					$step['args'][1] === $classNameParts[1]) {
101
-					$setUpViaQuery = true;
102
-					break;
103
-				}
104
-			}
105
-
106
-			if (!$setUpViaQuery && $applicationClassName !== \OCP\AppFramework\App::class) {
107
-				\OC::$server->getLogger()->logException($e, [
108
-					'app' => $appName,
109
-				]);
110
-			}
111
-		}
112
-
113
-		try {
114
-			$this->container = \OC::$server->getRegisteredAppContainer($appName);
115
-		} catch (QueryException $e) {
116
-			$this->container = new \OC\AppFramework\DependencyInjection\DIContainer($appName, $urlParams);
117
-		}
118
-	}
119
-
120
-	/**
121
-	 * @return IAppContainer
122
-	 * @since 6.0.0
123
-	 */
124
-	public function getContainer(): IAppContainer {
125
-		return $this->container;
126
-	}
127
-
128
-	/**
129
-	 * This function is to be called to create single routes and restful routes based on the given $routes array.
130
-	 *
131
-	 * Example code in routes.php of tasks app (it will register two restful resources):
132
-	 * $routes = array(
133
-	 *		'resources' => array(
134
-	 *		'lists' => array('url' => '/tasklists'),
135
-	 *		'tasks' => array('url' => '/tasklists/{listId}/tasks')
136
-	 *	)
137
-	 *	);
138
-	 *
139
-	 * $a = new TasksApp();
140
-	 * $a->registerRoutes($this, $routes);
141
-	 *
142
-	 * @param \OCP\Route\IRouter $router
143
-	 * @param array $routes
144
-	 * @since 6.0.0
145
-	 * @suppress PhanAccessMethodInternal
146
-	 */
147
-	public function registerRoutes(IRouter $router, array $routes) {
148
-		$routeConfig = new RouteConfig($this->container, $router, $routes);
149
-		$routeConfig->register();
150
-	}
151
-
152
-	/**
153
-	 * This function is called by the routing component to fire up the frameworks dispatch mechanism.
154
-	 *
155
-	 * Example code in routes.php of the task app:
156
-	 * $this->create('tasks_index', '/')->get()->action(
157
-	 *		function($params){
158
-	 *			$app = new TaskApp($params);
159
-	 *			$app->dispatch('PageController', 'index');
160
-	 *		}
161
-	 *	);
162
-	 *
163
-	 *
164
-	 * Example for for TaskApp implementation:
165
-	 * class TaskApp extends \OCP\AppFramework\App {
166
-	 *
167
-	 *		public function __construct($params){
168
-	 *			parent::__construct('tasks', $params);
169
-	 *
170
-	 *			$this->getContainer()->registerService('PageController', function(IAppContainer $c){
171
-	 *				$a = $c->query('API');
172
-	 *				$r = $c->query('Request');
173
-	 *				return new PageController($a, $r);
174
-	 *			});
175
-	 *		}
176
-	 *	}
177
-	 *
178
-	 * @param string $controllerName the name of the controller under which it is
179
-	 *                               stored in the DI container
180
-	 * @param string $methodName the method that you want to call
181
-	 * @since 6.0.0
182
-	 */
183
-	public function dispatch(string $controllerName, string $methodName) {
184
-		\OC\AppFramework\App::main($controllerName, $methodName, $this->container);
185
-	}
56
+    /** @var IAppContainer */
57
+    private $container;
58
+
59
+    /**
60
+     * Turns an app id into a namespace by convention. The id is split at the
61
+     * underscores, all parts are CamelCased and reassembled. e.g.:
62
+     * some_app_id -> OCA\SomeAppId
63
+     * @param string $appId the app id
64
+     * @param string $topNamespace the namespace which should be prepended to
65
+     * the transformed app id, defaults to OCA\
66
+     * @return string the starting namespace for the app
67
+     * @since 8.0.0
68
+     */
69
+    public static function buildAppNamespace(string $appId, string $topNamespace='OCA\\'): string {
70
+        return \OC\AppFramework\App::buildAppNamespace($appId, $topNamespace);
71
+    }
72
+
73
+
74
+    /**
75
+     * @param string $appName
76
+     * @param array $urlParams an array with variables extracted from the routes
77
+     * @since 6.0.0
78
+     */
79
+    public function __construct(string $appName, array $urlParams = []) {
80
+        $runIsSetupDirectly = \OC::$server->getConfig()->getSystemValueBool('debug')
81
+            && (PHP_VERSION_ID < 70400 || (PHP_VERSION_ID >= 70400 && !ini_get('zend.exception_ignore_args')));
82
+
83
+        if ($runIsSetupDirectly) {
84
+            $applicationClassName = get_class($this);
85
+            $e = new \RuntimeException('App class ' . $applicationClassName . ' is not setup via query() but directly');
86
+            $setUpViaQuery = false;
87
+
88
+            $classNameParts = explode('\\', trim($applicationClassName, '\\'));
89
+
90
+            foreach ($e->getTrace() as $step) {
91
+                if (isset($step['class'], $step['function'], $step['args'][0]) &&
92
+                    $step['class'] === ServerContainer::class &&
93
+                    $step['function'] === 'query' &&
94
+                    $step['args'][0] === $applicationClassName) {
95
+                    $setUpViaQuery = true;
96
+                    break;
97
+                } elseif (isset($step['class'], $step['function'], $step['args'][0]) &&
98
+                    $step['class'] === ServerContainer::class &&
99
+                    $step['function'] === 'getAppContainer' &&
100
+                    $step['args'][1] === $classNameParts[1]) {
101
+                    $setUpViaQuery = true;
102
+                    break;
103
+                }
104
+            }
105
+
106
+            if (!$setUpViaQuery && $applicationClassName !== \OCP\AppFramework\App::class) {
107
+                \OC::$server->getLogger()->logException($e, [
108
+                    'app' => $appName,
109
+                ]);
110
+            }
111
+        }
112
+
113
+        try {
114
+            $this->container = \OC::$server->getRegisteredAppContainer($appName);
115
+        } catch (QueryException $e) {
116
+            $this->container = new \OC\AppFramework\DependencyInjection\DIContainer($appName, $urlParams);
117
+        }
118
+    }
119
+
120
+    /**
121
+     * @return IAppContainer
122
+     * @since 6.0.0
123
+     */
124
+    public function getContainer(): IAppContainer {
125
+        return $this->container;
126
+    }
127
+
128
+    /**
129
+     * This function is to be called to create single routes and restful routes based on the given $routes array.
130
+     *
131
+     * Example code in routes.php of tasks app (it will register two restful resources):
132
+     * $routes = array(
133
+     *		'resources' => array(
134
+     *		'lists' => array('url' => '/tasklists'),
135
+     *		'tasks' => array('url' => '/tasklists/{listId}/tasks')
136
+     *	)
137
+     *	);
138
+     *
139
+     * $a = new TasksApp();
140
+     * $a->registerRoutes($this, $routes);
141
+     *
142
+     * @param \OCP\Route\IRouter $router
143
+     * @param array $routes
144
+     * @since 6.0.0
145
+     * @suppress PhanAccessMethodInternal
146
+     */
147
+    public function registerRoutes(IRouter $router, array $routes) {
148
+        $routeConfig = new RouteConfig($this->container, $router, $routes);
149
+        $routeConfig->register();
150
+    }
151
+
152
+    /**
153
+     * This function is called by the routing component to fire up the frameworks dispatch mechanism.
154
+     *
155
+     * Example code in routes.php of the task app:
156
+     * $this->create('tasks_index', '/')->get()->action(
157
+     *		function($params){
158
+     *			$app = new TaskApp($params);
159
+     *			$app->dispatch('PageController', 'index');
160
+     *		}
161
+     *	);
162
+     *
163
+     *
164
+     * Example for for TaskApp implementation:
165
+     * class TaskApp extends \OCP\AppFramework\App {
166
+     *
167
+     *		public function __construct($params){
168
+     *			parent::__construct('tasks', $params);
169
+     *
170
+     *			$this->getContainer()->registerService('PageController', function(IAppContainer $c){
171
+     *				$a = $c->query('API');
172
+     *				$r = $c->query('Request');
173
+     *				return new PageController($a, $r);
174
+     *			});
175
+     *		}
176
+     *	}
177
+     *
178
+     * @param string $controllerName the name of the controller under which it is
179
+     *                               stored in the DI container
180
+     * @param string $methodName the method that you want to call
181
+     * @since 6.0.0
182
+     */
183
+    public function dispatch(string $controllerName, string $methodName) {
184
+        \OC\AppFramework\App::main($controllerName, $methodName, $this->container);
185
+    }
186 186
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	 * @return string the starting namespace for the app
67 67
 	 * @since 8.0.0
68 68
 	 */
69
-	public static function buildAppNamespace(string $appId, string $topNamespace='OCA\\'): string {
69
+	public static function buildAppNamespace(string $appId, string $topNamespace = 'OCA\\'): string {
70 70
 		return \OC\AppFramework\App::buildAppNamespace($appId, $topNamespace);
71 71
 	}
72 72
 
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 
83 83
 		if ($runIsSetupDirectly) {
84 84
 			$applicationClassName = get_class($this);
85
-			$e = new \RuntimeException('App class ' . $applicationClassName . ' is not setup via query() but directly');
85
+			$e = new \RuntimeException('App class '.$applicationClassName.' is not setup via query() but directly');
86 86
 			$setUpViaQuery = false;
87 87
 
88 88
 			$classNameParts = explode('\\', trim($applicationClassName, '\\'));
Please login to merge, or discard this patch.