| Conditions | 8 |
| Paths | 2 |
| Total Lines | 254 |
| Code Lines | 157 |
| 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 |
||
| 98 | public function __construct(string $appName, array $urlParams = [], ServerContainer $server = null) { |
||
| 99 | parent::__construct(); |
||
| 100 | $this->appName = $appName; |
||
| 101 | $this['appName'] = $appName; |
||
| 102 | $this['urlParams'] = $urlParams; |
||
| 103 | |||
| 104 | $this->registerAlias('Request', IRequest::class); |
||
| 105 | |||
| 106 | /** @var \OC\ServerContainer $server */ |
||
| 107 | if ($server === null) { |
||
| 108 | $server = \OC::$server; |
||
| 109 | } |
||
| 110 | $this->server = $server; |
||
| 111 | $this->server->registerAppContainer($appName, $this); |
||
| 112 | |||
| 113 | // aliases |
||
| 114 | /** @deprecated inject $appName */ |
||
| 115 | $this->registerAlias('AppName', 'appName'); |
||
| 116 | /** @deprecated inject $webRoot*/ |
||
| 117 | $this->registerAlias('WebRoot', 'webRoot'); |
||
| 118 | /** @deprecated inject $userId */ |
||
| 119 | $this->registerAlias('UserId', 'userId'); |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Core services |
||
| 123 | */ |
||
| 124 | $this->registerService(IOutput::class, function () { |
||
| 125 | return new Output($this->getServer()->getWebRoot()); |
||
| 126 | }); |
||
| 127 | |||
| 128 | $this->registerService(Folder::class, function () { |
||
| 129 | return $this->getServer()->getUserFolder(); |
||
| 130 | }); |
||
| 131 | |||
| 132 | $this->registerService(IAppData::class, function (ContainerInterface $c) { |
||
| 133 | return $this->getServer()->getAppDataDir($c->get('AppName')); |
||
| 134 | }); |
||
| 135 | |||
| 136 | $this->registerService(IL10N::class, function (ContainerInterface $c) { |
||
| 137 | return $this->getServer()->getL10N($c->get('AppName')); |
||
| 138 | }); |
||
| 139 | |||
| 140 | // Log wrappers |
||
| 141 | $this->registerService(LoggerInterface::class, function (ContainerInterface $c) { |
||
| 142 | return new ScopedPsrLogger( |
||
| 143 | $c->get(PsrLoggerAdapter::class), |
||
| 144 | $c->get('AppName') |
||
| 145 | ); |
||
| 146 | }); |
||
| 147 | $this->registerService(ILogger::class, function (ContainerInterface $c) { |
||
| 148 | return new OC\AppFramework\Logger($this->server->query(ILogger::class), $c->get('AppName')); |
||
| 149 | }); |
||
| 150 | |||
| 151 | $this->registerService(IServerContainer::class, function () { |
||
| 152 | return $this->getServer(); |
||
| 153 | }); |
||
| 154 | $this->registerAlias('ServerContainer', IServerContainer::class); |
||
| 155 | |||
| 156 | $this->registerService(\OCP\WorkflowEngine\IManager::class, function (ContainerInterface $c) { |
||
| 157 | return $c->get(Manager::class); |
||
| 158 | }); |
||
| 159 | |||
| 160 | $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
||
| 161 | return $c; |
||
| 162 | }); |
||
| 163 | $this->registerAlias(IAppContainer::class, ContainerInterface::class); |
||
| 164 | |||
| 165 | // commonly used attributes |
||
| 166 | $this->registerService('userId', function (ContainerInterface $c) { |
||
| 167 | return $c->get(IUserSession::class)->getSession()->get('user_id'); |
||
| 168 | }); |
||
| 169 | |||
| 170 | $this->registerService('webRoot', function (ContainerInterface $c) { |
||
| 171 | return $c->get(IServerContainer::class)->getWebRoot(); |
||
| 172 | }); |
||
| 173 | |||
| 174 | $this->registerService('OC_Defaults', function (ContainerInterface $c) { |
||
| 175 | return $c->get(IServerContainer::class)->getThemingDefaults(); |
||
| 176 | }); |
||
| 177 | |||
| 178 | $this->registerService('Protocol', function (ContainerInterface $c) { |
||
| 179 | /** @var \OC\Server $server */ |
||
| 180 | $server = $c->get(IServerContainer::class); |
||
| 181 | $protocol = $server->getRequest()->getHttpProtocol(); |
||
| 182 | return new Http($_SERVER, $protocol); |
||
| 183 | }); |
||
| 184 | |||
| 185 | $this->registerService('Dispatcher', function (ContainerInterface $c) { |
||
| 186 | return new Dispatcher( |
||
| 187 | $c->get('Protocol'), |
||
| 188 | $c->get(MiddlewareDispatcher::class), |
||
| 189 | $c->get(IControllerMethodReflector::class), |
||
| 190 | $c->get(IRequest::class), |
||
| 191 | $c->get(IConfig::class), |
||
| 192 | $c->get(IDBConnection::class), |
||
| 193 | $c->get(LoggerInterface::class), |
||
| 194 | $c->get(EventLogger::class), |
||
| 195 | $c, |
||
| 196 | ); |
||
| 197 | }); |
||
| 198 | |||
| 199 | /** |
||
| 200 | * App Framework default arguments |
||
| 201 | */ |
||
| 202 | $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH'); |
||
| 203 | $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept'); |
||
| 204 | $this->registerParameter('corsMaxAge', 1728000); |
||
| 205 | |||
| 206 | /** |
||
| 207 | * Middleware |
||
| 208 | */ |
||
| 209 | $this->registerAlias('MiddlewareDispatcher', MiddlewareDispatcher::class); |
||
| 210 | $this->registerService(MiddlewareDispatcher::class, function (ContainerInterface $c) { |
||
| 211 | $server = $this->getServer(); |
||
| 212 | |||
| 213 | $dispatcher = new MiddlewareDispatcher(); |
||
| 214 | |||
| 215 | $dispatcher->registerMiddleware( |
||
| 216 | $c->get(OC\AppFramework\Middleware\CompressionMiddleware::class) |
||
| 217 | ); |
||
| 218 | |||
| 219 | $dispatcher->registerMiddleware($c->get(OC\AppFramework\Middleware\NotModifiedMiddleware::class)); |
||
| 220 | |||
| 221 | $dispatcher->registerMiddleware( |
||
| 222 | $c->get(OC\AppFramework\Middleware\Security\ReloadExecutionMiddleware::class) |
||
| 223 | ); |
||
| 224 | |||
| 225 | $dispatcher->registerMiddleware( |
||
| 226 | new OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware( |
||
| 227 | $c->get(IRequest::class), |
||
| 228 | $c->get(IControllerMethodReflector::class) |
||
| 229 | ) |
||
| 230 | ); |
||
| 231 | $dispatcher->registerMiddleware( |
||
| 232 | new CORSMiddleware( |
||
| 233 | $c->get(IRequest::class), |
||
| 234 | $c->get(IControllerMethodReflector::class), |
||
| 235 | $c->get(IUserSession::class), |
||
| 236 | $c->get(OC\Security\Bruteforce\Throttler::class) |
||
| 237 | ) |
||
| 238 | ); |
||
| 239 | $dispatcher->registerMiddleware( |
||
| 240 | new OCSMiddleware( |
||
| 241 | $c->get(IRequest::class) |
||
| 242 | ) |
||
| 243 | ); |
||
| 244 | |||
| 245 | |||
| 246 | |||
| 247 | $securityMiddleware = new SecurityMiddleware( |
||
| 248 | $c->get(IRequest::class), |
||
| 249 | $c->get(IControllerMethodReflector::class), |
||
| 250 | $c->get(INavigationManager::class), |
||
| 251 | $c->get(IURLGenerator::class), |
||
| 252 | $server->get(LoggerInterface::class), |
||
| 253 | $c->get('AppName'), |
||
| 254 | $server->getUserSession()->isLoggedIn(), |
||
| 255 | $this->getUserId() !== null && $server->getGroupManager()->isAdmin($this->getUserId()), |
||
| 256 | $server->getUserSession()->getUser() !== null && $server->query(ISubAdmin::class)->isSubAdmin($server->getUserSession()->getUser()), |
||
| 257 | $server->getAppManager(), |
||
| 258 | $server->getL10N('lib'), |
||
| 259 | $c->get(AuthorizedGroupMapper::class), |
||
| 260 | $server->get(IUserSession::class) |
||
| 261 | ); |
||
| 262 | $dispatcher->registerMiddleware($securityMiddleware); |
||
| 263 | $dispatcher->registerMiddleware( |
||
| 264 | new OC\AppFramework\Middleware\Security\CSPMiddleware( |
||
| 265 | $server->query(OC\Security\CSP\ContentSecurityPolicyManager::class), |
||
| 266 | $server->query(OC\Security\CSP\ContentSecurityPolicyNonceManager::class), |
||
| 267 | $server->query(OC\Security\CSRF\CsrfTokenManager::class) |
||
| 268 | ) |
||
| 269 | ); |
||
| 270 | $dispatcher->registerMiddleware( |
||
| 271 | $server->query(OC\AppFramework\Middleware\Security\FeaturePolicyMiddleware::class) |
||
| 272 | ); |
||
| 273 | $dispatcher->registerMiddleware( |
||
| 274 | new OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware( |
||
| 275 | $c->get(IControllerMethodReflector::class), |
||
| 276 | $c->get(ISession::class), |
||
| 277 | $c->get(IUserSession::class), |
||
| 278 | $c->get(ITimeFactory::class) |
||
| 279 | ) |
||
| 280 | ); |
||
| 281 | $dispatcher->registerMiddleware( |
||
| 282 | new TwoFactorMiddleware( |
||
| 283 | $c->get(OC\Authentication\TwoFactorAuth\Manager::class), |
||
| 284 | $c->get(IUserSession::class), |
||
| 285 | $c->get(ISession::class), |
||
| 286 | $c->get(IURLGenerator::class), |
||
| 287 | $c->get(IControllerMethodReflector::class), |
||
| 288 | $c->get(IRequest::class) |
||
| 289 | ) |
||
| 290 | ); |
||
| 291 | $dispatcher->registerMiddleware( |
||
| 292 | new OC\AppFramework\Middleware\Security\BruteForceMiddleware( |
||
| 293 | $c->get(IControllerMethodReflector::class), |
||
| 294 | $c->get(OC\Security\Bruteforce\Throttler::class), |
||
| 295 | $c->get(IRequest::class) |
||
| 296 | ) |
||
| 297 | ); |
||
| 298 | $dispatcher->registerMiddleware( |
||
| 299 | new RateLimitingMiddleware( |
||
| 300 | $c->get(IRequest::class), |
||
| 301 | $c->get(IUserSession::class), |
||
| 302 | $c->get(IControllerMethodReflector::class), |
||
| 303 | $c->get(OC\Security\RateLimiting\Limiter::class) |
||
| 304 | ) |
||
| 305 | ); |
||
| 306 | $dispatcher->registerMiddleware( |
||
| 307 | new OC\AppFramework\Middleware\PublicShare\PublicShareMiddleware( |
||
| 308 | $c->get(IRequest::class), |
||
| 309 | $c->get(ISession::class), |
||
| 310 | $c->get(\OCP\IConfig::class), |
||
| 311 | $c->get(OC\Security\Bruteforce\Throttler::class) |
||
| 312 | ) |
||
| 313 | ); |
||
| 314 | $dispatcher->registerMiddleware( |
||
| 315 | $c->get(\OC\AppFramework\Middleware\AdditionalScriptsMiddleware::class) |
||
| 316 | ); |
||
| 317 | |||
| 318 | /** @var \OC\AppFramework\Bootstrap\Coordinator $coordinator */ |
||
| 319 | $coordinator = $c->get(\OC\AppFramework\Bootstrap\Coordinator::class); |
||
| 320 | $registrationContext = $coordinator->getRegistrationContext(); |
||
| 321 | if ($registrationContext !== null) { |
||
| 322 | $appId = $this->getAppName(); |
||
| 323 | foreach ($registrationContext->getMiddlewareRegistrations() as $middlewareRegistration) { |
||
| 324 | if ($middlewareRegistration->getAppId() === $appId) { |
||
| 325 | $dispatcher->registerMiddleware($c->get($middlewareRegistration->getService())); |
||
| 326 | } |
||
| 327 | } |
||
| 328 | } |
||
| 329 | foreach ($this->middleWares as $middleWare) { |
||
| 330 | $dispatcher->registerMiddleware($c->get($middleWare)); |
||
| 331 | } |
||
| 332 | |||
| 333 | $dispatcher->registerMiddleware( |
||
| 334 | new SessionMiddleware( |
||
| 335 | $c->get(IControllerMethodReflector::class), |
||
| 336 | $c->get(ISession::class) |
||
| 337 | ) |
||
| 338 | ); |
||
| 339 | return $dispatcher; |
||
| 340 | }); |
||
| 341 | |||
| 342 | $this->registerService(IAppConfig::class, function (ContainerInterface $c) { |
||
| 343 | return new OC\AppFramework\Services\AppConfig( |
||
| 344 | $c->get(IConfig::class), |
||
| 345 | $c->get('AppName') |
||
| 346 | ); |
||
| 347 | }); |
||
| 348 | $this->registerService(IInitialState::class, function (ContainerInterface $c) { |
||
| 349 | return new OC\AppFramework\Services\InitialState( |
||
| 350 | $c->get(IInitialStateService::class), |
||
| 351 | $c->get('AppName') |
||
| 352 | ); |
||
| 499 |
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.