Conditions | 4 |
Paths | 2 |
Total Lines | 223 |
Code Lines | 137 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
93 | public function __construct($appName, $urlParams = [], ServerContainer $server = null) { |
||
94 | parent::__construct(); |
||
95 | $this['AppName'] = $appName; |
||
96 | $this['urlParams'] = $urlParams; |
||
97 | |||
98 | $this->registerAlias('Request', IRequest::class); |
||
99 | |||
100 | /** @var \OC\ServerContainer $server */ |
||
101 | if ($server === null) { |
||
102 | $server = \OC::$server; |
||
103 | } |
||
104 | $this->server = $server; |
||
105 | $this->server->registerAppContainer($appName, $this); |
||
106 | |||
107 | // aliases |
||
108 | $this->registerAlias('appName', 'AppName'); |
||
109 | $this->registerAlias('webRoot', 'WebRoot'); |
||
110 | $this->registerAlias('userId', 'UserId'); |
||
111 | |||
112 | /** |
||
113 | * Core services |
||
114 | */ |
||
115 | $this->registerService(IOutput::class, function () { |
||
116 | return new Output($this->getServer()->getWebRoot()); |
||
117 | }); |
||
118 | |||
119 | $this->registerService(Folder::class, function () { |
||
120 | return $this->getServer()->getUserFolder(); |
||
121 | }); |
||
122 | |||
123 | $this->registerService(IAppData::class, function (ContainerInterface $c) { |
||
124 | return $this->getServer()->getAppDataDir($c->get('AppName')); |
||
125 | }); |
||
126 | |||
127 | $this->registerService(IL10N::class, function (ContainerInterface $c) { |
||
128 | return $this->getServer()->getL10N($c->get('AppName')); |
||
129 | }); |
||
130 | |||
131 | // Log wrapper |
||
132 | $this->registerService(ILogger::class, function (ContainerInterface $c) { |
||
133 | return new OC\AppFramework\Logger($this->server->query(ILogger::class), $c->get('AppName')); |
||
134 | }); |
||
135 | |||
136 | $this->registerService(IServerContainer::class, function () { |
||
137 | return $this->getServer(); |
||
138 | }); |
||
139 | $this->registerAlias('ServerContainer', IServerContainer::class); |
||
140 | |||
141 | $this->registerService(\OCP\WorkflowEngine\IManager::class, function (ContainerInterface $c) { |
||
142 | return $c->get(Manager::class); |
||
143 | }); |
||
144 | |||
145 | $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
||
146 | return $c; |
||
147 | }); |
||
148 | $this->registerAlias(IAppContainer::class, ContainerInterface::class); |
||
149 | |||
150 | // commonly used attributes |
||
151 | $this->registerService('UserId', function (ContainerInterface $c) { |
||
152 | return $c->get(IUserSession::class)->getSession()->get('user_id'); |
||
153 | }); |
||
154 | |||
155 | $this->registerService('WebRoot', function (ContainerInterface $c) { |
||
156 | return $c->get(IServerContainer::class)->getWebRoot(); |
||
157 | }); |
||
158 | |||
159 | $this->registerService('OC_Defaults', function (ContainerInterface $c) { |
||
160 | return $c->get(IServerContainer::class)->getThemingDefaults(); |
||
161 | }); |
||
162 | |||
163 | $this->registerService('Protocol', function (ContainerInterface $c) { |
||
164 | /** @var \OC\Server $server */ |
||
165 | $server = $c->get(IServerContainer::class); |
||
166 | $protocol = $server->getRequest()->getHttpProtocol(); |
||
167 | return new Http($_SERVER, $protocol); |
||
168 | }); |
||
169 | |||
170 | $this->registerService('Dispatcher', function (ContainerInterface $c) { |
||
171 | return new Dispatcher( |
||
172 | $c->get('Protocol'), |
||
173 | $c->get(MiddlewareDispatcher::class), |
||
174 | $c->get(IControllerMethodReflector::class), |
||
175 | $c->get(IRequest::class) |
||
176 | ); |
||
177 | }); |
||
178 | |||
179 | /** |
||
180 | * App Framework default arguments |
||
181 | */ |
||
182 | $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH'); |
||
183 | $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept'); |
||
184 | $this->registerParameter('corsMaxAge', 1728000); |
||
185 | |||
186 | /** |
||
187 | * Middleware |
||
188 | */ |
||
189 | $this->registerAlias('MiddlewareDispatcher', MiddlewareDispatcher::class); |
||
190 | $this->registerService(MiddlewareDispatcher::class, function (ContainerInterface $c) { |
||
191 | $server = $this->getServer(); |
||
192 | |||
193 | $dispatcher = new MiddlewareDispatcher(); |
||
194 | |||
195 | $dispatcher->registerMiddleware( |
||
196 | $c->get(OC\AppFramework\Middleware\CompressionMiddleware::class) |
||
197 | ); |
||
198 | |||
199 | $dispatcher->registerMiddleware($c->get(OC\AppFramework\Middleware\NotModifiedMiddleware::class)); |
||
200 | |||
201 | $dispatcher->registerMiddleware( |
||
202 | $c->get(OC\AppFramework\Middleware\Security\ReloadExecutionMiddleware::class) |
||
203 | ); |
||
204 | |||
205 | $dispatcher->registerMiddleware( |
||
206 | new OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware( |
||
207 | $c->get(IRequest::class), |
||
208 | $c->get(IControllerMethodReflector::class) |
||
209 | ) |
||
210 | ); |
||
211 | $dispatcher->registerMiddleware( |
||
212 | new CORSMiddleware( |
||
213 | $c->get(IRequest::class), |
||
214 | $c->get(IControllerMethodReflector::class), |
||
215 | $c->get(IUserSession::class), |
||
216 | $c->get(OC\Security\Bruteforce\Throttler::class) |
||
217 | ) |
||
218 | ); |
||
219 | $dispatcher->registerMiddleware( |
||
220 | new OCSMiddleware( |
||
221 | $c->get(IRequest::class) |
||
222 | ) |
||
223 | ); |
||
224 | |||
225 | $securityMiddleware = new SecurityMiddleware( |
||
226 | $c->get(IRequest::class), |
||
227 | $c->get(IControllerMethodReflector::class), |
||
228 | $c->get(INavigationManager::class), |
||
229 | $c->get(IURLGenerator::class), |
||
230 | $server->query(ILogger::class), |
||
231 | $c->get('AppName'), |
||
232 | $server->getUserSession()->isLoggedIn(), |
||
233 | $server->getGroupManager()->isAdmin($this->getUserId()), |
||
234 | $server->getUserSession()->getUser() !== null && $server->query(ISubAdmin::class)->isSubAdmin($server->getUserSession()->getUser()), |
||
235 | $server->getAppManager(), |
||
236 | $server->getL10N('lib') |
||
237 | ); |
||
238 | $dispatcher->registerMiddleware($securityMiddleware); |
||
239 | $dispatcher->registerMiddleware( |
||
240 | new OC\AppFramework\Middleware\Security\CSPMiddleware( |
||
241 | $server->query(OC\Security\CSP\ContentSecurityPolicyManager::class), |
||
242 | $server->query(OC\Security\CSP\ContentSecurityPolicyNonceManager::class), |
||
243 | $server->query(OC\Security\CSRF\CsrfTokenManager::class) |
||
244 | ) |
||
245 | ); |
||
246 | $dispatcher->registerMiddleware( |
||
247 | $server->query(OC\AppFramework\Middleware\Security\FeaturePolicyMiddleware::class) |
||
248 | ); |
||
249 | $dispatcher->registerMiddleware( |
||
250 | new OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware( |
||
251 | $c->get(IControllerMethodReflector::class), |
||
252 | $c->get(ISession::class), |
||
253 | $c->get(IUserSession::class), |
||
254 | $c->get(ITimeFactory::class) |
||
255 | ) |
||
256 | ); |
||
257 | $dispatcher->registerMiddleware( |
||
258 | new TwoFactorMiddleware( |
||
259 | $c->get(OC\Authentication\TwoFactorAuth\Manager::class), |
||
260 | $c->get(IUserSession::class), |
||
261 | $c->get(ISession::class), |
||
262 | $c->get(IURLGenerator::class), |
||
263 | $c->get(IControllerMethodReflector::class), |
||
264 | $c->get(IRequest::class) |
||
265 | ) |
||
266 | ); |
||
267 | $dispatcher->registerMiddleware( |
||
268 | new OC\AppFramework\Middleware\Security\BruteForceMiddleware( |
||
269 | $c->get(IControllerMethodReflector::class), |
||
270 | $c->get(OC\Security\Bruteforce\Throttler::class), |
||
271 | $c->get(IRequest::class) |
||
272 | ) |
||
273 | ); |
||
274 | $dispatcher->registerMiddleware( |
||
275 | new RateLimitingMiddleware( |
||
276 | $c->get(IRequest::class), |
||
277 | $c->get(IUserSession::class), |
||
278 | $c->get(IControllerMethodReflector::class), |
||
279 | $c->get(OC\Security\RateLimiting\Limiter::class) |
||
280 | ) |
||
281 | ); |
||
282 | $dispatcher->registerMiddleware( |
||
283 | new OC\AppFramework\Middleware\PublicShare\PublicShareMiddleware( |
||
284 | $c->get(IRequest::class), |
||
285 | $c->get(ISession::class), |
||
286 | $c->get(\OCP\IConfig::class) |
||
287 | ) |
||
288 | ); |
||
289 | $dispatcher->registerMiddleware( |
||
290 | $c->get(\OC\AppFramework\Middleware\AdditionalScriptsMiddleware::class) |
||
291 | ); |
||
292 | |||
293 | foreach ($this->middleWares as $middleWare) { |
||
294 | $dispatcher->registerMiddleware($c->get($middleWare)); |
||
295 | } |
||
296 | |||
297 | $dispatcher->registerMiddleware( |
||
298 | new SessionMiddleware( |
||
299 | $c->get(IControllerMethodReflector::class), |
||
300 | $c->get(ISession::class) |
||
301 | ) |
||
302 | ); |
||
303 | return $dispatcher; |
||
304 | }); |
||
305 | |||
306 | $this->registerService(IAppConfig::class, function (ContainerInterface $c) { |
||
307 | return new OC\AppFramework\Services\AppConfig( |
||
308 | $c->get(IConfig::class), |
||
309 | $c->get('AppName') |
||
310 | ); |
||
311 | }); |
||
312 | $this->registerService(IInitialState::class, function (ContainerInterface $c) { |
||
313 | return new OC\AppFramework\Services\InitialState( |
||
314 | $c->get(IInitialStateService::class), |
||
315 | $c->get('AppName') |
||
316 | ); |
||
454 |
This interface has been deprecated. The supplier of the interface has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.