@@ -70,396 +70,396 @@ |
||
| 70 | 70 | |
| 71 | 71 | class DIContainer extends SimpleContainer implements IAppContainer { |
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @var array |
|
| 75 | - */ |
|
| 76 | - private $middleWares = array(); |
|
| 77 | - |
|
| 78 | - /** @var ServerContainer */ |
|
| 79 | - private $server; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Put your class dependencies in here |
|
| 83 | - * @param string $appName the name of the app |
|
| 84 | - * @param array $urlParams |
|
| 85 | - * @param ServerContainer|null $server |
|
| 86 | - */ |
|
| 87 | - public function __construct($appName, $urlParams = array(), ServerContainer $server = null){ |
|
| 88 | - parent::__construct(); |
|
| 89 | - $this['AppName'] = $appName; |
|
| 90 | - $this['urlParams'] = $urlParams; |
|
| 91 | - |
|
| 92 | - /** @var \OC\ServerContainer $server */ |
|
| 93 | - if ($server === null) { |
|
| 94 | - $server = \OC::$server; |
|
| 95 | - } |
|
| 96 | - $this->server = $server; |
|
| 97 | - $this->server->registerAppContainer($appName, $this); |
|
| 98 | - |
|
| 99 | - // aliases |
|
| 100 | - $this->registerAlias('appName', 'AppName'); |
|
| 101 | - $this->registerAlias('webRoot', 'WebRoot'); |
|
| 102 | - $this->registerAlias('userId', 'UserId'); |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Core services |
|
| 106 | - */ |
|
| 107 | - $this->registerService(IOutput::class, function($c){ |
|
| 108 | - return new Output($this->getServer()->getWebRoot()); |
|
| 109 | - }); |
|
| 110 | - |
|
| 111 | - $this->registerService(Folder::class, function() { |
|
| 112 | - return $this->getServer()->getUserFolder(); |
|
| 113 | - }); |
|
| 114 | - |
|
| 115 | - $this->registerService(IAppData::class, function (SimpleContainer $c) { |
|
| 116 | - return $this->getServer()->getAppDataDir($c->query('AppName')); |
|
| 117 | - }); |
|
| 118 | - |
|
| 119 | - $this->registerService(IL10N::class, function($c) { |
|
| 120 | - return $this->getServer()->getL10N($c->query('AppName')); |
|
| 121 | - }); |
|
| 122 | - |
|
| 123 | - // Log wrapper |
|
| 124 | - $this->registerService(ILogger::class, function ($c) { |
|
| 125 | - return new OC\AppFramework\Logger($this->server->query(ILogger::class), $c->query('AppName')); |
|
| 126 | - }); |
|
| 127 | - |
|
| 128 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 129 | - $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 130 | - |
|
| 131 | - $this->registerService(IRequest::class, function() { |
|
| 132 | - return $this->getServer()->query(IRequest::class); |
|
| 133 | - }); |
|
| 134 | - $this->registerAlias('Request', IRequest::class); |
|
| 135 | - |
|
| 136 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 137 | - $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 138 | - |
|
| 139 | - $this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class); |
|
| 140 | - |
|
| 141 | - $this->registerService(IServerContainer::class, function ($c) { |
|
| 142 | - return $this->getServer(); |
|
| 143 | - }); |
|
| 144 | - $this->registerAlias('ServerContainer', IServerContainer::class); |
|
| 145 | - |
|
| 146 | - $this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) { |
|
| 147 | - return $c->query(Manager::class); |
|
| 148 | - }); |
|
| 149 | - |
|
| 150 | - $this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) { |
|
| 151 | - return $c; |
|
| 152 | - }); |
|
| 153 | - |
|
| 154 | - $this->registerAlias(ISearchResult::class, SearchResult::class); |
|
| 155 | - |
|
| 156 | - // commonly used attributes |
|
| 157 | - $this->registerService('UserId', function ($c) { |
|
| 158 | - return $c->query(IUserSession::class)->getSession()->get('user_id'); |
|
| 159 | - }); |
|
| 160 | - |
|
| 161 | - $this->registerService('WebRoot', function ($c) { |
|
| 162 | - return $c->query('ServerContainer')->getWebRoot(); |
|
| 163 | - }); |
|
| 164 | - |
|
| 165 | - $this->registerService('OC_Defaults', function ($c) { |
|
| 166 | - return $c->getServer()->getThemingDefaults(); |
|
| 167 | - }); |
|
| 168 | - |
|
| 169 | - $this->registerService(IManager::class, function ($c) { |
|
| 170 | - return $this->getServer()->getEncryptionManager(); |
|
| 171 | - }); |
|
| 172 | - |
|
| 173 | - $this->registerService(IConfig::class, function ($c) { |
|
| 174 | - return $c->query(OC\GlobalScale\Config::class); |
|
| 175 | - }); |
|
| 176 | - |
|
| 177 | - $this->registerService(IValidator::class, function($c) { |
|
| 178 | - return $c->query(Validator::class); |
|
| 179 | - }); |
|
| 180 | - |
|
| 181 | - $this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) { |
|
| 182 | - return new \OC\Security\IdentityProof\Manager( |
|
| 183 | - $this->getServer()->query(\OC\Files\AppData\Factory::class), |
|
| 184 | - $this->getServer()->getCrypto(), |
|
| 185 | - $this->getServer()->getConfig() |
|
| 186 | - ); |
|
| 187 | - }); |
|
| 188 | - |
|
| 189 | - $this->registerService('Protocol', function($c){ |
|
| 190 | - /** @var \OC\Server $server */ |
|
| 191 | - $server = $c->query('ServerContainer'); |
|
| 192 | - $protocol = $server->getRequest()->getHttpProtocol(); |
|
| 193 | - return new Http($_SERVER, $protocol); |
|
| 194 | - }); |
|
| 195 | - |
|
| 196 | - $this->registerService('Dispatcher', function($c) { |
|
| 197 | - return new Dispatcher( |
|
| 198 | - $c['Protocol'], |
|
| 199 | - $c['MiddlewareDispatcher'], |
|
| 200 | - $c['ControllerMethodReflector'], |
|
| 201 | - $c['Request'] |
|
| 202 | - ); |
|
| 203 | - }); |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * App Framework default arguments |
|
| 207 | - */ |
|
| 208 | - $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH'); |
|
| 209 | - $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept'); |
|
| 210 | - $this->registerParameter('corsMaxAge', 1728000); |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Middleware |
|
| 214 | - */ |
|
| 215 | - $app = $this; |
|
| 216 | - $this->registerService('SecurityMiddleware', function($c) use ($app){ |
|
| 217 | - /** @var \OC\Server $server */ |
|
| 218 | - $server = $app->getServer(); |
|
| 219 | - |
|
| 220 | - return new SecurityMiddleware( |
|
| 221 | - $c['Request'], |
|
| 222 | - $c['ControllerMethodReflector'], |
|
| 223 | - $server->getNavigationManager(), |
|
| 224 | - $server->getURLGenerator(), |
|
| 225 | - $server->getLogger(), |
|
| 226 | - $c['AppName'], |
|
| 227 | - $server->getUserSession()->isLoggedIn(), |
|
| 228 | - $server->getGroupManager()->isAdmin($this->getUserId()), |
|
| 229 | - $server->getContentSecurityPolicyManager(), |
|
| 230 | - $server->getCsrfTokenManager(), |
|
| 231 | - $server->getContentSecurityPolicyNonceManager(), |
|
| 232 | - $server->getAppManager(), |
|
| 233 | - $server->getL10N('lib') |
|
| 234 | - ); |
|
| 235 | - }); |
|
| 236 | - |
|
| 237 | - $this->registerService(OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware::class, function ($c) use ($app) { |
|
| 238 | - /** @var \OC\Server $server */ |
|
| 239 | - $server = $app->getServer(); |
|
| 240 | - |
|
| 241 | - return new OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware( |
|
| 242 | - $c['ControllerMethodReflector'], |
|
| 243 | - $server->getSession(), |
|
| 244 | - $server->getUserSession(), |
|
| 245 | - $server->query(ITimeFactory::class) |
|
| 246 | - ); |
|
| 247 | - }); |
|
| 248 | - |
|
| 249 | - $this->registerService('BruteForceMiddleware', function($c) use ($app) { |
|
| 250 | - /** @var \OC\Server $server */ |
|
| 251 | - $server = $app->getServer(); |
|
| 252 | - |
|
| 253 | - return new OC\AppFramework\Middleware\Security\BruteForceMiddleware( |
|
| 254 | - $c['ControllerMethodReflector'], |
|
| 255 | - $server->getBruteForceThrottler(), |
|
| 256 | - $server->getRequest() |
|
| 257 | - ); |
|
| 258 | - }); |
|
| 259 | - |
|
| 260 | - $this->registerService('RateLimitingMiddleware', function($c) use ($app) { |
|
| 261 | - /** @var \OC\Server $server */ |
|
| 262 | - $server = $app->getServer(); |
|
| 263 | - |
|
| 264 | - return new RateLimitingMiddleware( |
|
| 265 | - $server->getRequest(), |
|
| 266 | - $server->getUserSession(), |
|
| 267 | - $c['ControllerMethodReflector'], |
|
| 268 | - $c->query(OC\Security\RateLimiting\Limiter::class) |
|
| 269 | - ); |
|
| 270 | - }); |
|
| 271 | - |
|
| 272 | - $this->registerService('CORSMiddleware', function($c) { |
|
| 273 | - return new CORSMiddleware( |
|
| 274 | - $c['Request'], |
|
| 275 | - $c['ControllerMethodReflector'], |
|
| 276 | - $c->query(IUserSession::class), |
|
| 277 | - $c->getServer()->getBruteForceThrottler() |
|
| 278 | - ); |
|
| 279 | - }); |
|
| 280 | - |
|
| 281 | - $this->registerService('SessionMiddleware', function($c) use ($app) { |
|
| 282 | - return new SessionMiddleware( |
|
| 283 | - $c['Request'], |
|
| 284 | - $c['ControllerMethodReflector'], |
|
| 285 | - $app->getServer()->getSession() |
|
| 286 | - ); |
|
| 287 | - }); |
|
| 288 | - |
|
| 289 | - $this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) { |
|
| 290 | - $twoFactorManager = $c->getServer()->getTwoFactorAuthManager(); |
|
| 291 | - $userSession = $app->getServer()->getUserSession(); |
|
| 292 | - $session = $app->getServer()->getSession(); |
|
| 293 | - $urlGenerator = $app->getServer()->getURLGenerator(); |
|
| 294 | - $reflector = $c['ControllerMethodReflector']; |
|
| 295 | - $request = $app->getServer()->getRequest(); |
|
| 296 | - return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request); |
|
| 297 | - }); |
|
| 298 | - |
|
| 299 | - $this->registerService('OCSMiddleware', function (SimpleContainer $c) { |
|
| 300 | - return new OCSMiddleware( |
|
| 301 | - $c['Request'] |
|
| 302 | - ); |
|
| 303 | - }); |
|
| 304 | - |
|
| 305 | - $this->registerService(OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware::class, function (SimpleContainer $c) { |
|
| 306 | - return new OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware( |
|
| 307 | - $c['Request'], |
|
| 308 | - $c['ControllerMethodReflector'] |
|
| 309 | - ); |
|
| 310 | - }); |
|
| 311 | - |
|
| 312 | - $middleWares = &$this->middleWares; |
|
| 313 | - $this->registerService('MiddlewareDispatcher', function(SimpleContainer $c) use (&$middleWares) { |
|
| 314 | - $dispatcher = new MiddlewareDispatcher(); |
|
| 315 | - $dispatcher->registerMiddleware($c[OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware::class]); |
|
| 316 | - $dispatcher->registerMiddleware($c['CORSMiddleware']); |
|
| 317 | - $dispatcher->registerMiddleware($c['OCSMiddleware']); |
|
| 318 | - $dispatcher->registerMiddleware($c['SecurityMiddleware']); |
|
| 319 | - $dispatcher->registerMiddleware($c[OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware::class]); |
|
| 320 | - $dispatcher->registerMiddleware($c['TwoFactorMiddleware']); |
|
| 321 | - $dispatcher->registerMiddleware($c['BruteForceMiddleware']); |
|
| 322 | - $dispatcher->registerMiddleware($c['RateLimitingMiddleware']); |
|
| 323 | - $dispatcher->registerMiddleware(new OC\AppFramework\Middleware\PublicShare\PublicShareMiddleware( |
|
| 324 | - $c['Request'], |
|
| 325 | - $c->query(ISession::class), |
|
| 326 | - $c->query(\OCP\IConfig::class) |
|
| 327 | - )); |
|
| 328 | - |
|
| 329 | - foreach($middleWares as $middleWare) { |
|
| 330 | - $dispatcher->registerMiddleware($c[$middleWare]); |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - $dispatcher->registerMiddleware($c['SessionMiddleware']); |
|
| 334 | - return $dispatcher; |
|
| 335 | - }); |
|
| 336 | - |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * @return \OCP\IServerContainer |
|
| 341 | - */ |
|
| 342 | - public function getServer() |
|
| 343 | - { |
|
| 344 | - return $this->server; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * @param string $middleWare |
|
| 349 | - * @return boolean|null |
|
| 350 | - */ |
|
| 351 | - public function registerMiddleWare($middleWare) { |
|
| 352 | - $this->middleWares[] = $middleWare; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * used to return the appname of the set application |
|
| 357 | - * @return string the name of your application |
|
| 358 | - */ |
|
| 359 | - public function getAppName() { |
|
| 360 | - return $this->query('AppName'); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * @deprecated use IUserSession->isLoggedIn() |
|
| 365 | - * @return boolean |
|
| 366 | - */ |
|
| 367 | - public function isLoggedIn() { |
|
| 368 | - return \OC::$server->getUserSession()->isLoggedIn(); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * @deprecated use IGroupManager->isAdmin($userId) |
|
| 373 | - * @return boolean |
|
| 374 | - */ |
|
| 375 | - public function isAdminUser() { |
|
| 376 | - $uid = $this->getUserId(); |
|
| 377 | - return \OC_User::isAdminUser($uid); |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - private function getUserId() { |
|
| 381 | - return $this->getServer()->getSession()->get('user_id'); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * @deprecated use the ILogger instead |
|
| 386 | - * @param string $message |
|
| 387 | - * @param string $level |
|
| 388 | - * @return mixed |
|
| 389 | - */ |
|
| 390 | - public function log($message, $level) { |
|
| 391 | - switch($level){ |
|
| 392 | - case 'debug': |
|
| 393 | - $level = ILogger::DEBUG; |
|
| 394 | - break; |
|
| 395 | - case 'info': |
|
| 396 | - $level = ILogger::INFO; |
|
| 397 | - break; |
|
| 398 | - case 'warn': |
|
| 399 | - $level = ILogger::WARN; |
|
| 400 | - break; |
|
| 401 | - case 'fatal': |
|
| 402 | - $level = ILogger::FATAL; |
|
| 403 | - break; |
|
| 404 | - default: |
|
| 405 | - $level = ILogger::ERROR; |
|
| 406 | - break; |
|
| 407 | - } |
|
| 408 | - \OCP\Util::writeLog($this->getAppName(), $message, $level); |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - /** |
|
| 412 | - * Register a capability |
|
| 413 | - * |
|
| 414 | - * @param string $serviceName e.g. 'OCA\Files\Capabilities' |
|
| 415 | - */ |
|
| 416 | - public function registerCapability($serviceName) { |
|
| 417 | - $this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) { |
|
| 418 | - return $this->query($serviceName); |
|
| 419 | - }); |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * @param string $name |
|
| 424 | - * @return mixed |
|
| 425 | - * @throws QueryException if the query could not be resolved |
|
| 426 | - */ |
|
| 427 | - public function query($name) { |
|
| 428 | - try { |
|
| 429 | - return $this->queryNoFallback($name); |
|
| 430 | - } catch (QueryException $firstException) { |
|
| 431 | - try { |
|
| 432 | - return $this->getServer()->query($name); |
|
| 433 | - } catch (QueryException $secondException) { |
|
| 434 | - if ($firstException->getCode() === 1) { |
|
| 435 | - throw $secondException; |
|
| 436 | - } |
|
| 437 | - throw $firstException; |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * @param string $name |
|
| 444 | - * @return mixed |
|
| 445 | - * @throws QueryException if the query could not be resolved |
|
| 446 | - */ |
|
| 447 | - public function queryNoFallback($name) { |
|
| 448 | - $name = $this->sanitizeName($name); |
|
| 449 | - |
|
| 450 | - if ($this->offsetExists($name)) { |
|
| 451 | - return parent::query($name); |
|
| 452 | - } else { |
|
| 453 | - if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) { |
|
| 454 | - return parent::query($name); |
|
| 455 | - } else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) { |
|
| 456 | - return parent::query($name); |
|
| 457 | - } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) { |
|
| 458 | - return parent::query($name); |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - throw new QueryException('Could not resolve ' . $name . '!' . |
|
| 463 | - ' Class can not be instantiated', 1); |
|
| 464 | - } |
|
| 73 | + /** |
|
| 74 | + * @var array |
|
| 75 | + */ |
|
| 76 | + private $middleWares = array(); |
|
| 77 | + |
|
| 78 | + /** @var ServerContainer */ |
|
| 79 | + private $server; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Put your class dependencies in here |
|
| 83 | + * @param string $appName the name of the app |
|
| 84 | + * @param array $urlParams |
|
| 85 | + * @param ServerContainer|null $server |
|
| 86 | + */ |
|
| 87 | + public function __construct($appName, $urlParams = array(), ServerContainer $server = null){ |
|
| 88 | + parent::__construct(); |
|
| 89 | + $this['AppName'] = $appName; |
|
| 90 | + $this['urlParams'] = $urlParams; |
|
| 91 | + |
|
| 92 | + /** @var \OC\ServerContainer $server */ |
|
| 93 | + if ($server === null) { |
|
| 94 | + $server = \OC::$server; |
|
| 95 | + } |
|
| 96 | + $this->server = $server; |
|
| 97 | + $this->server->registerAppContainer($appName, $this); |
|
| 98 | + |
|
| 99 | + // aliases |
|
| 100 | + $this->registerAlias('appName', 'AppName'); |
|
| 101 | + $this->registerAlias('webRoot', 'WebRoot'); |
|
| 102 | + $this->registerAlias('userId', 'UserId'); |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Core services |
|
| 106 | + */ |
|
| 107 | + $this->registerService(IOutput::class, function($c){ |
|
| 108 | + return new Output($this->getServer()->getWebRoot()); |
|
| 109 | + }); |
|
| 110 | + |
|
| 111 | + $this->registerService(Folder::class, function() { |
|
| 112 | + return $this->getServer()->getUserFolder(); |
|
| 113 | + }); |
|
| 114 | + |
|
| 115 | + $this->registerService(IAppData::class, function (SimpleContainer $c) { |
|
| 116 | + return $this->getServer()->getAppDataDir($c->query('AppName')); |
|
| 117 | + }); |
|
| 118 | + |
|
| 119 | + $this->registerService(IL10N::class, function($c) { |
|
| 120 | + return $this->getServer()->getL10N($c->query('AppName')); |
|
| 121 | + }); |
|
| 122 | + |
|
| 123 | + // Log wrapper |
|
| 124 | + $this->registerService(ILogger::class, function ($c) { |
|
| 125 | + return new OC\AppFramework\Logger($this->server->query(ILogger::class), $c->query('AppName')); |
|
| 126 | + }); |
|
| 127 | + |
|
| 128 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 129 | + $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 130 | + |
|
| 131 | + $this->registerService(IRequest::class, function() { |
|
| 132 | + return $this->getServer()->query(IRequest::class); |
|
| 133 | + }); |
|
| 134 | + $this->registerAlias('Request', IRequest::class); |
|
| 135 | + |
|
| 136 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 137 | + $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 138 | + |
|
| 139 | + $this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class); |
|
| 140 | + |
|
| 141 | + $this->registerService(IServerContainer::class, function ($c) { |
|
| 142 | + return $this->getServer(); |
|
| 143 | + }); |
|
| 144 | + $this->registerAlias('ServerContainer', IServerContainer::class); |
|
| 145 | + |
|
| 146 | + $this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) { |
|
| 147 | + return $c->query(Manager::class); |
|
| 148 | + }); |
|
| 149 | + |
|
| 150 | + $this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) { |
|
| 151 | + return $c; |
|
| 152 | + }); |
|
| 153 | + |
|
| 154 | + $this->registerAlias(ISearchResult::class, SearchResult::class); |
|
| 155 | + |
|
| 156 | + // commonly used attributes |
|
| 157 | + $this->registerService('UserId', function ($c) { |
|
| 158 | + return $c->query(IUserSession::class)->getSession()->get('user_id'); |
|
| 159 | + }); |
|
| 160 | + |
|
| 161 | + $this->registerService('WebRoot', function ($c) { |
|
| 162 | + return $c->query('ServerContainer')->getWebRoot(); |
|
| 163 | + }); |
|
| 164 | + |
|
| 165 | + $this->registerService('OC_Defaults', function ($c) { |
|
| 166 | + return $c->getServer()->getThemingDefaults(); |
|
| 167 | + }); |
|
| 168 | + |
|
| 169 | + $this->registerService(IManager::class, function ($c) { |
|
| 170 | + return $this->getServer()->getEncryptionManager(); |
|
| 171 | + }); |
|
| 172 | + |
|
| 173 | + $this->registerService(IConfig::class, function ($c) { |
|
| 174 | + return $c->query(OC\GlobalScale\Config::class); |
|
| 175 | + }); |
|
| 176 | + |
|
| 177 | + $this->registerService(IValidator::class, function($c) { |
|
| 178 | + return $c->query(Validator::class); |
|
| 179 | + }); |
|
| 180 | + |
|
| 181 | + $this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) { |
|
| 182 | + return new \OC\Security\IdentityProof\Manager( |
|
| 183 | + $this->getServer()->query(\OC\Files\AppData\Factory::class), |
|
| 184 | + $this->getServer()->getCrypto(), |
|
| 185 | + $this->getServer()->getConfig() |
|
| 186 | + ); |
|
| 187 | + }); |
|
| 188 | + |
|
| 189 | + $this->registerService('Protocol', function($c){ |
|
| 190 | + /** @var \OC\Server $server */ |
|
| 191 | + $server = $c->query('ServerContainer'); |
|
| 192 | + $protocol = $server->getRequest()->getHttpProtocol(); |
|
| 193 | + return new Http($_SERVER, $protocol); |
|
| 194 | + }); |
|
| 195 | + |
|
| 196 | + $this->registerService('Dispatcher', function($c) { |
|
| 197 | + return new Dispatcher( |
|
| 198 | + $c['Protocol'], |
|
| 199 | + $c['MiddlewareDispatcher'], |
|
| 200 | + $c['ControllerMethodReflector'], |
|
| 201 | + $c['Request'] |
|
| 202 | + ); |
|
| 203 | + }); |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * App Framework default arguments |
|
| 207 | + */ |
|
| 208 | + $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH'); |
|
| 209 | + $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept'); |
|
| 210 | + $this->registerParameter('corsMaxAge', 1728000); |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Middleware |
|
| 214 | + */ |
|
| 215 | + $app = $this; |
|
| 216 | + $this->registerService('SecurityMiddleware', function($c) use ($app){ |
|
| 217 | + /** @var \OC\Server $server */ |
|
| 218 | + $server = $app->getServer(); |
|
| 219 | + |
|
| 220 | + return new SecurityMiddleware( |
|
| 221 | + $c['Request'], |
|
| 222 | + $c['ControllerMethodReflector'], |
|
| 223 | + $server->getNavigationManager(), |
|
| 224 | + $server->getURLGenerator(), |
|
| 225 | + $server->getLogger(), |
|
| 226 | + $c['AppName'], |
|
| 227 | + $server->getUserSession()->isLoggedIn(), |
|
| 228 | + $server->getGroupManager()->isAdmin($this->getUserId()), |
|
| 229 | + $server->getContentSecurityPolicyManager(), |
|
| 230 | + $server->getCsrfTokenManager(), |
|
| 231 | + $server->getContentSecurityPolicyNonceManager(), |
|
| 232 | + $server->getAppManager(), |
|
| 233 | + $server->getL10N('lib') |
|
| 234 | + ); |
|
| 235 | + }); |
|
| 236 | + |
|
| 237 | + $this->registerService(OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware::class, function ($c) use ($app) { |
|
| 238 | + /** @var \OC\Server $server */ |
|
| 239 | + $server = $app->getServer(); |
|
| 240 | + |
|
| 241 | + return new OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware( |
|
| 242 | + $c['ControllerMethodReflector'], |
|
| 243 | + $server->getSession(), |
|
| 244 | + $server->getUserSession(), |
|
| 245 | + $server->query(ITimeFactory::class) |
|
| 246 | + ); |
|
| 247 | + }); |
|
| 248 | + |
|
| 249 | + $this->registerService('BruteForceMiddleware', function($c) use ($app) { |
|
| 250 | + /** @var \OC\Server $server */ |
|
| 251 | + $server = $app->getServer(); |
|
| 252 | + |
|
| 253 | + return new OC\AppFramework\Middleware\Security\BruteForceMiddleware( |
|
| 254 | + $c['ControllerMethodReflector'], |
|
| 255 | + $server->getBruteForceThrottler(), |
|
| 256 | + $server->getRequest() |
|
| 257 | + ); |
|
| 258 | + }); |
|
| 259 | + |
|
| 260 | + $this->registerService('RateLimitingMiddleware', function($c) use ($app) { |
|
| 261 | + /** @var \OC\Server $server */ |
|
| 262 | + $server = $app->getServer(); |
|
| 263 | + |
|
| 264 | + return new RateLimitingMiddleware( |
|
| 265 | + $server->getRequest(), |
|
| 266 | + $server->getUserSession(), |
|
| 267 | + $c['ControllerMethodReflector'], |
|
| 268 | + $c->query(OC\Security\RateLimiting\Limiter::class) |
|
| 269 | + ); |
|
| 270 | + }); |
|
| 271 | + |
|
| 272 | + $this->registerService('CORSMiddleware', function($c) { |
|
| 273 | + return new CORSMiddleware( |
|
| 274 | + $c['Request'], |
|
| 275 | + $c['ControllerMethodReflector'], |
|
| 276 | + $c->query(IUserSession::class), |
|
| 277 | + $c->getServer()->getBruteForceThrottler() |
|
| 278 | + ); |
|
| 279 | + }); |
|
| 280 | + |
|
| 281 | + $this->registerService('SessionMiddleware', function($c) use ($app) { |
|
| 282 | + return new SessionMiddleware( |
|
| 283 | + $c['Request'], |
|
| 284 | + $c['ControllerMethodReflector'], |
|
| 285 | + $app->getServer()->getSession() |
|
| 286 | + ); |
|
| 287 | + }); |
|
| 288 | + |
|
| 289 | + $this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) { |
|
| 290 | + $twoFactorManager = $c->getServer()->getTwoFactorAuthManager(); |
|
| 291 | + $userSession = $app->getServer()->getUserSession(); |
|
| 292 | + $session = $app->getServer()->getSession(); |
|
| 293 | + $urlGenerator = $app->getServer()->getURLGenerator(); |
|
| 294 | + $reflector = $c['ControllerMethodReflector']; |
|
| 295 | + $request = $app->getServer()->getRequest(); |
|
| 296 | + return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request); |
|
| 297 | + }); |
|
| 298 | + |
|
| 299 | + $this->registerService('OCSMiddleware', function (SimpleContainer $c) { |
|
| 300 | + return new OCSMiddleware( |
|
| 301 | + $c['Request'] |
|
| 302 | + ); |
|
| 303 | + }); |
|
| 304 | + |
|
| 305 | + $this->registerService(OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware::class, function (SimpleContainer $c) { |
|
| 306 | + return new OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware( |
|
| 307 | + $c['Request'], |
|
| 308 | + $c['ControllerMethodReflector'] |
|
| 309 | + ); |
|
| 310 | + }); |
|
| 311 | + |
|
| 312 | + $middleWares = &$this->middleWares; |
|
| 313 | + $this->registerService('MiddlewareDispatcher', function(SimpleContainer $c) use (&$middleWares) { |
|
| 314 | + $dispatcher = new MiddlewareDispatcher(); |
|
| 315 | + $dispatcher->registerMiddleware($c[OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware::class]); |
|
| 316 | + $dispatcher->registerMiddleware($c['CORSMiddleware']); |
|
| 317 | + $dispatcher->registerMiddleware($c['OCSMiddleware']); |
|
| 318 | + $dispatcher->registerMiddleware($c['SecurityMiddleware']); |
|
| 319 | + $dispatcher->registerMiddleware($c[OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware::class]); |
|
| 320 | + $dispatcher->registerMiddleware($c['TwoFactorMiddleware']); |
|
| 321 | + $dispatcher->registerMiddleware($c['BruteForceMiddleware']); |
|
| 322 | + $dispatcher->registerMiddleware($c['RateLimitingMiddleware']); |
|
| 323 | + $dispatcher->registerMiddleware(new OC\AppFramework\Middleware\PublicShare\PublicShareMiddleware( |
|
| 324 | + $c['Request'], |
|
| 325 | + $c->query(ISession::class), |
|
| 326 | + $c->query(\OCP\IConfig::class) |
|
| 327 | + )); |
|
| 328 | + |
|
| 329 | + foreach($middleWares as $middleWare) { |
|
| 330 | + $dispatcher->registerMiddleware($c[$middleWare]); |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + $dispatcher->registerMiddleware($c['SessionMiddleware']); |
|
| 334 | + return $dispatcher; |
|
| 335 | + }); |
|
| 336 | + |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * @return \OCP\IServerContainer |
|
| 341 | + */ |
|
| 342 | + public function getServer() |
|
| 343 | + { |
|
| 344 | + return $this->server; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * @param string $middleWare |
|
| 349 | + * @return boolean|null |
|
| 350 | + */ |
|
| 351 | + public function registerMiddleWare($middleWare) { |
|
| 352 | + $this->middleWares[] = $middleWare; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * used to return the appname of the set application |
|
| 357 | + * @return string the name of your application |
|
| 358 | + */ |
|
| 359 | + public function getAppName() { |
|
| 360 | + return $this->query('AppName'); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * @deprecated use IUserSession->isLoggedIn() |
|
| 365 | + * @return boolean |
|
| 366 | + */ |
|
| 367 | + public function isLoggedIn() { |
|
| 368 | + return \OC::$server->getUserSession()->isLoggedIn(); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * @deprecated use IGroupManager->isAdmin($userId) |
|
| 373 | + * @return boolean |
|
| 374 | + */ |
|
| 375 | + public function isAdminUser() { |
|
| 376 | + $uid = $this->getUserId(); |
|
| 377 | + return \OC_User::isAdminUser($uid); |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + private function getUserId() { |
|
| 381 | + return $this->getServer()->getSession()->get('user_id'); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * @deprecated use the ILogger instead |
|
| 386 | + * @param string $message |
|
| 387 | + * @param string $level |
|
| 388 | + * @return mixed |
|
| 389 | + */ |
|
| 390 | + public function log($message, $level) { |
|
| 391 | + switch($level){ |
|
| 392 | + case 'debug': |
|
| 393 | + $level = ILogger::DEBUG; |
|
| 394 | + break; |
|
| 395 | + case 'info': |
|
| 396 | + $level = ILogger::INFO; |
|
| 397 | + break; |
|
| 398 | + case 'warn': |
|
| 399 | + $level = ILogger::WARN; |
|
| 400 | + break; |
|
| 401 | + case 'fatal': |
|
| 402 | + $level = ILogger::FATAL; |
|
| 403 | + break; |
|
| 404 | + default: |
|
| 405 | + $level = ILogger::ERROR; |
|
| 406 | + break; |
|
| 407 | + } |
|
| 408 | + \OCP\Util::writeLog($this->getAppName(), $message, $level); |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + /** |
|
| 412 | + * Register a capability |
|
| 413 | + * |
|
| 414 | + * @param string $serviceName e.g. 'OCA\Files\Capabilities' |
|
| 415 | + */ |
|
| 416 | + public function registerCapability($serviceName) { |
|
| 417 | + $this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) { |
|
| 418 | + return $this->query($serviceName); |
|
| 419 | + }); |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * @param string $name |
|
| 424 | + * @return mixed |
|
| 425 | + * @throws QueryException if the query could not be resolved |
|
| 426 | + */ |
|
| 427 | + public function query($name) { |
|
| 428 | + try { |
|
| 429 | + return $this->queryNoFallback($name); |
|
| 430 | + } catch (QueryException $firstException) { |
|
| 431 | + try { |
|
| 432 | + return $this->getServer()->query($name); |
|
| 433 | + } catch (QueryException $secondException) { |
|
| 434 | + if ($firstException->getCode() === 1) { |
|
| 435 | + throw $secondException; |
|
| 436 | + } |
|
| 437 | + throw $firstException; |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * @param string $name |
|
| 444 | + * @return mixed |
|
| 445 | + * @throws QueryException if the query could not be resolved |
|
| 446 | + */ |
|
| 447 | + public function queryNoFallback($name) { |
|
| 448 | + $name = $this->sanitizeName($name); |
|
| 449 | + |
|
| 450 | + if ($this->offsetExists($name)) { |
|
| 451 | + return parent::query($name); |
|
| 452 | + } else { |
|
| 453 | + if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) { |
|
| 454 | + return parent::query($name); |
|
| 455 | + } else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) { |
|
| 456 | + return parent::query($name); |
|
| 457 | + } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) { |
|
| 458 | + return parent::query($name); |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + throw new QueryException('Could not resolve ' . $name . '!' . |
|
| 463 | + ' Class can not be instantiated', 1); |
|
| 464 | + } |
|
| 465 | 465 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | * @param array $urlParams |
| 85 | 85 | * @param ServerContainer|null $server |
| 86 | 86 | */ |
| 87 | - public function __construct($appName, $urlParams = array(), ServerContainer $server = null){ |
|
| 87 | + public function __construct($appName, $urlParams = array(), ServerContainer $server = null) { |
|
| 88 | 88 | parent::__construct(); |
| 89 | 89 | $this['AppName'] = $appName; |
| 90 | 90 | $this['urlParams'] = $urlParams; |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | /** |
| 105 | 105 | * Core services |
| 106 | 106 | */ |
| 107 | - $this->registerService(IOutput::class, function($c){ |
|
| 107 | + $this->registerService(IOutput::class, function($c) { |
|
| 108 | 108 | return new Output($this->getServer()->getWebRoot()); |
| 109 | 109 | }); |
| 110 | 110 | |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | return $this->getServer()->getUserFolder(); |
| 113 | 113 | }); |
| 114 | 114 | |
| 115 | - $this->registerService(IAppData::class, function (SimpleContainer $c) { |
|
| 115 | + $this->registerService(IAppData::class, function(SimpleContainer $c) { |
|
| 116 | 116 | return $this->getServer()->getAppDataDir($c->query('AppName')); |
| 117 | 117 | }); |
| 118 | 118 | |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | }); |
| 122 | 122 | |
| 123 | 123 | // Log wrapper |
| 124 | - $this->registerService(ILogger::class, function ($c) { |
|
| 124 | + $this->registerService(ILogger::class, function($c) { |
|
| 125 | 125 | return new OC\AppFramework\Logger($this->server->query(ILogger::class), $c->query('AppName')); |
| 126 | 126 | }); |
| 127 | 127 | |
@@ -138,39 +138,39 @@ discard block |
||
| 138 | 138 | |
| 139 | 139 | $this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class); |
| 140 | 140 | |
| 141 | - $this->registerService(IServerContainer::class, function ($c) { |
|
| 141 | + $this->registerService(IServerContainer::class, function($c) { |
|
| 142 | 142 | return $this->getServer(); |
| 143 | 143 | }); |
| 144 | 144 | $this->registerAlias('ServerContainer', IServerContainer::class); |
| 145 | 145 | |
| 146 | - $this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) { |
|
| 146 | + $this->registerService(\OCP\WorkflowEngine\IManager::class, function($c) { |
|
| 147 | 147 | return $c->query(Manager::class); |
| 148 | 148 | }); |
| 149 | 149 | |
| 150 | - $this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) { |
|
| 150 | + $this->registerService(\OCP\AppFramework\IAppContainer::class, function($c) { |
|
| 151 | 151 | return $c; |
| 152 | 152 | }); |
| 153 | 153 | |
| 154 | 154 | $this->registerAlias(ISearchResult::class, SearchResult::class); |
| 155 | 155 | |
| 156 | 156 | // commonly used attributes |
| 157 | - $this->registerService('UserId', function ($c) { |
|
| 157 | + $this->registerService('UserId', function($c) { |
|
| 158 | 158 | return $c->query(IUserSession::class)->getSession()->get('user_id'); |
| 159 | 159 | }); |
| 160 | 160 | |
| 161 | - $this->registerService('WebRoot', function ($c) { |
|
| 161 | + $this->registerService('WebRoot', function($c) { |
|
| 162 | 162 | return $c->query('ServerContainer')->getWebRoot(); |
| 163 | 163 | }); |
| 164 | 164 | |
| 165 | - $this->registerService('OC_Defaults', function ($c) { |
|
| 165 | + $this->registerService('OC_Defaults', function($c) { |
|
| 166 | 166 | return $c->getServer()->getThemingDefaults(); |
| 167 | 167 | }); |
| 168 | 168 | |
| 169 | - $this->registerService(IManager::class, function ($c) { |
|
| 169 | + $this->registerService(IManager::class, function($c) { |
|
| 170 | 170 | return $this->getServer()->getEncryptionManager(); |
| 171 | 171 | }); |
| 172 | 172 | |
| 173 | - $this->registerService(IConfig::class, function ($c) { |
|
| 173 | + $this->registerService(IConfig::class, function($c) { |
|
| 174 | 174 | return $c->query(OC\GlobalScale\Config::class); |
| 175 | 175 | }); |
| 176 | 176 | |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | return $c->query(Validator::class); |
| 179 | 179 | }); |
| 180 | 180 | |
| 181 | - $this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) { |
|
| 181 | + $this->registerService(\OC\Security\IdentityProof\Manager::class, function($c) { |
|
| 182 | 182 | return new \OC\Security\IdentityProof\Manager( |
| 183 | 183 | $this->getServer()->query(\OC\Files\AppData\Factory::class), |
| 184 | 184 | $this->getServer()->getCrypto(), |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | ); |
| 187 | 187 | }); |
| 188 | 188 | |
| 189 | - $this->registerService('Protocol', function($c){ |
|
| 189 | + $this->registerService('Protocol', function($c) { |
|
| 190 | 190 | /** @var \OC\Server $server */ |
| 191 | 191 | $server = $c->query('ServerContainer'); |
| 192 | 192 | $protocol = $server->getRequest()->getHttpProtocol(); |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | ); |
| 235 | 235 | }); |
| 236 | 236 | |
| 237 | - $this->registerService(OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware::class, function ($c) use ($app) { |
|
| 237 | + $this->registerService(OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware::class, function($c) use ($app) { |
|
| 238 | 238 | /** @var \OC\Server $server */ |
| 239 | 239 | $server = $app->getServer(); |
| 240 | 240 | |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | ); |
| 287 | 287 | }); |
| 288 | 288 | |
| 289 | - $this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) { |
|
| 289 | + $this->registerService('TwoFactorMiddleware', function(SimpleContainer $c) use ($app) { |
|
| 290 | 290 | $twoFactorManager = $c->getServer()->getTwoFactorAuthManager(); |
| 291 | 291 | $userSession = $app->getServer()->getUserSession(); |
| 292 | 292 | $session = $app->getServer()->getSession(); |
@@ -296,13 +296,13 @@ discard block |
||
| 296 | 296 | return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request); |
| 297 | 297 | }); |
| 298 | 298 | |
| 299 | - $this->registerService('OCSMiddleware', function (SimpleContainer $c) { |
|
| 299 | + $this->registerService('OCSMiddleware', function(SimpleContainer $c) { |
|
| 300 | 300 | return new OCSMiddleware( |
| 301 | 301 | $c['Request'] |
| 302 | 302 | ); |
| 303 | 303 | }); |
| 304 | 304 | |
| 305 | - $this->registerService(OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware::class, function (SimpleContainer $c) { |
|
| 305 | + $this->registerService(OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware::class, function(SimpleContainer $c) { |
|
| 306 | 306 | return new OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware( |
| 307 | 307 | $c['Request'], |
| 308 | 308 | $c['ControllerMethodReflector'] |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | $c->query(\OCP\IConfig::class) |
| 327 | 327 | )); |
| 328 | 328 | |
| 329 | - foreach($middleWares as $middleWare) { |
|
| 329 | + foreach ($middleWares as $middleWare) { |
|
| 330 | 330 | $dispatcher->registerMiddleware($c[$middleWare]); |
| 331 | 331 | } |
| 332 | 332 | |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | * @return mixed |
| 389 | 389 | */ |
| 390 | 390 | public function log($message, $level) { |
| 391 | - switch($level){ |
|
| 391 | + switch ($level) { |
|
| 392 | 392 | case 'debug': |
| 393 | 393 | $level = ILogger::DEBUG; |
| 394 | 394 | break; |
@@ -454,12 +454,12 @@ discard block |
||
| 454 | 454 | return parent::query($name); |
| 455 | 455 | } else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) { |
| 456 | 456 | return parent::query($name); |
| 457 | - } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) { |
|
| 457 | + } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']).'\\') === 0) { |
|
| 458 | 458 | return parent::query($name); |
| 459 | 459 | } |
| 460 | 460 | } |
| 461 | 461 | |
| 462 | - throw new QueryException('Could not resolve ' . $name . '!' . |
|
| 462 | + throw new QueryException('Could not resolve '.$name.'!'. |
|
| 463 | 463 | ' Class can not be instantiated', 1); |
| 464 | 464 | } |
| 465 | 465 | } |
@@ -28,62 +28,62 @@ |
||
| 28 | 28 | |
| 29 | 29 | class Logger implements ILogger { |
| 30 | 30 | |
| 31 | - /** @var ILogger */ |
|
| 32 | - private $logger; |
|
| 31 | + /** @var ILogger */ |
|
| 32 | + private $logger; |
|
| 33 | 33 | |
| 34 | - /** @var string */ |
|
| 35 | - private $appName; |
|
| 34 | + /** @var string */ |
|
| 35 | + private $appName; |
|
| 36 | 36 | |
| 37 | - public function __construct(ILogger $logger, string $appName) { |
|
| 38 | - $this->logger = $logger; |
|
| 39 | - $this->appName = $appName; |
|
| 40 | - } |
|
| 37 | + public function __construct(ILogger $logger, string $appName) { |
|
| 38 | + $this->logger = $logger; |
|
| 39 | + $this->appName = $appName; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - private function extendContext(array $context): array { |
|
| 43 | - if (!isset($context['app'])) { |
|
| 44 | - $context['app'] = $this->appName; |
|
| 45 | - } |
|
| 42 | + private function extendContext(array $context): array { |
|
| 43 | + if (!isset($context['app'])) { |
|
| 44 | + $context['app'] = $this->appName; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - return $context; |
|
| 48 | - } |
|
| 47 | + return $context; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - public function emergency(string $message, array $context = []) { |
|
| 51 | - $this->logger->emergency($message, $this->extendContext($context)); |
|
| 52 | - } |
|
| 50 | + public function emergency(string $message, array $context = []) { |
|
| 51 | + $this->logger->emergency($message, $this->extendContext($context)); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - public function alert(string $message, array $context = []) { |
|
| 55 | - $this->logger->alert($message, $this->extendContext($context)); |
|
| 56 | - } |
|
| 54 | + public function alert(string $message, array $context = []) { |
|
| 55 | + $this->logger->alert($message, $this->extendContext($context)); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - public function critical(string $message, array $context = []) { |
|
| 59 | - $this->logger->critical($message, $this->extendContext($context)); |
|
| 60 | - } |
|
| 58 | + public function critical(string $message, array $context = []) { |
|
| 59 | + $this->logger->critical($message, $this->extendContext($context)); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - public function error(string $message, array $context = []) { |
|
| 63 | - $this->logger->emergency($message, $this->extendContext($context)); |
|
| 64 | - } |
|
| 62 | + public function error(string $message, array $context = []) { |
|
| 63 | + $this->logger->emergency($message, $this->extendContext($context)); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - public function warning(string $message, array $context = []) { |
|
| 67 | - $this->logger->warning($message, $this->extendContext($context)); |
|
| 68 | - } |
|
| 66 | + public function warning(string $message, array $context = []) { |
|
| 67 | + $this->logger->warning($message, $this->extendContext($context)); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - public function notice(string $message, array $context = []) { |
|
| 71 | - $this->logger->notice($message, $this->extendContext($context)); |
|
| 72 | - } |
|
| 70 | + public function notice(string $message, array $context = []) { |
|
| 71 | + $this->logger->notice($message, $this->extendContext($context)); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - public function info(string $message, array $context = []) { |
|
| 75 | - $this->logger->info($message, $this->extendContext($context)); |
|
| 76 | - } |
|
| 74 | + public function info(string $message, array $context = []) { |
|
| 75 | + $this->logger->info($message, $this->extendContext($context)); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - public function debug(string $message, array $context = []) { |
|
| 79 | - $this->logger->debug($message, $this->extendContext($context)); |
|
| 80 | - } |
|
| 78 | + public function debug(string $message, array $context = []) { |
|
| 79 | + $this->logger->debug($message, $this->extendContext($context)); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - public function log(int $level, string $message, array $context = []) { |
|
| 83 | - $this->logger->log($level, $message, $this->extendContext($context)); |
|
| 84 | - } |
|
| 82 | + public function log(int $level, string $message, array $context = []) { |
|
| 83 | + $this->logger->log($level, $message, $this->extendContext($context)); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - public function logException(\Throwable $exception, array $context = []) { |
|
| 87 | - $this->logger->logException($exception, $this->extendContext($context)); |
|
| 88 | - } |
|
| 86 | + public function logException(\Throwable $exception, array $context = []) { |
|
| 87 | + $this->logger->logException($exception, $this->extendContext($context)); |
|
| 88 | + } |
|
| 89 | 89 | } |