@@ -47,58 +47,58 @@ |
||
| 47 | 47 | */ |
| 48 | 48 | interface IContainer { |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * If a parameter is not registered in the container try to instantiate it |
|
| 52 | - * by using reflection to find out how to build the class |
|
| 53 | - * @param string $name the class name to resolve |
|
| 54 | - * @return \stdClass |
|
| 55 | - * @since 8.2.0 |
|
| 56 | - * @throws QueryException if the class could not be found or instantiated |
|
| 57 | - */ |
|
| 58 | - public function resolve($name); |
|
| 50 | + /** |
|
| 51 | + * If a parameter is not registered in the container try to instantiate it |
|
| 52 | + * by using reflection to find out how to build the class |
|
| 53 | + * @param string $name the class name to resolve |
|
| 54 | + * @return \stdClass |
|
| 55 | + * @since 8.2.0 |
|
| 56 | + * @throws QueryException if the class could not be found or instantiated |
|
| 57 | + */ |
|
| 58 | + public function resolve($name); |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Look up a service for a given name in the container. |
|
| 62 | - * |
|
| 63 | - * @param string $name |
|
| 64 | - * @return mixed |
|
| 65 | - * @throws QueryException if the query could not be resolved |
|
| 66 | - * @since 6.0.0 |
|
| 67 | - */ |
|
| 68 | - public function query($name); |
|
| 60 | + /** |
|
| 61 | + * Look up a service for a given name in the container. |
|
| 62 | + * |
|
| 63 | + * @param string $name |
|
| 64 | + * @return mixed |
|
| 65 | + * @throws QueryException if the query could not be resolved |
|
| 66 | + * @since 6.0.0 |
|
| 67 | + */ |
|
| 68 | + public function query($name); |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * A value is stored in the container with it's corresponding name |
|
| 72 | - * |
|
| 73 | - * @param string $name |
|
| 74 | - * @param mixed $value |
|
| 75 | - * @return void |
|
| 76 | - * @since 6.0.0 |
|
| 77 | - */ |
|
| 78 | - public function registerParameter($name, $value); |
|
| 70 | + /** |
|
| 71 | + * A value is stored in the container with it's corresponding name |
|
| 72 | + * |
|
| 73 | + * @param string $name |
|
| 74 | + * @param mixed $value |
|
| 75 | + * @return void |
|
| 76 | + * @since 6.0.0 |
|
| 77 | + */ |
|
| 78 | + public function registerParameter($name, $value); |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * A service is registered in the container where a closure is passed in which will actually |
|
| 82 | - * create the service on demand. |
|
| 83 | - * In case the parameter $shared is set to true (the default usage) the once created service will remain in |
|
| 84 | - * memory and be reused on subsequent calls. |
|
| 85 | - * In case the parameter is false the service will be recreated on every call. |
|
| 86 | - * |
|
| 87 | - * @param string $name |
|
| 88 | - * @param \Closure $closure |
|
| 89 | - * @param bool $shared |
|
| 90 | - * @return void |
|
| 91 | - * @since 6.0.0 |
|
| 92 | - */ |
|
| 93 | - public function registerService($name, Closure $closure, $shared = true); |
|
| 80 | + /** |
|
| 81 | + * A service is registered in the container where a closure is passed in which will actually |
|
| 82 | + * create the service on demand. |
|
| 83 | + * In case the parameter $shared is set to true (the default usage) the once created service will remain in |
|
| 84 | + * memory and be reused on subsequent calls. |
|
| 85 | + * In case the parameter is false the service will be recreated on every call. |
|
| 86 | + * |
|
| 87 | + * @param string $name |
|
| 88 | + * @param \Closure $closure |
|
| 89 | + * @param bool $shared |
|
| 90 | + * @return void |
|
| 91 | + * @since 6.0.0 |
|
| 92 | + */ |
|
| 93 | + public function registerService($name, Closure $closure, $shared = true); |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Shortcut for returning a service from a service under a different key, |
|
| 97 | - * e.g. to tell the container to return a class when queried for an |
|
| 98 | - * interface |
|
| 99 | - * @param string $alias the alias that should be registered |
|
| 100 | - * @param string $target the target that should be resolved instead |
|
| 101 | - * @since 8.2.0 |
|
| 102 | - */ |
|
| 103 | - public function registerAlias($alias, $target); |
|
| 95 | + /** |
|
| 96 | + * Shortcut for returning a service from a service under a different key, |
|
| 97 | + * e.g. to tell the container to return a class when queried for an |
|
| 98 | + * interface |
|
| 99 | + * @param string $alias the alias that should be registered |
|
| 100 | + * @param string $target the target that should be resolved instead |
|
| 101 | + * @since 8.2.0 |
|
| 102 | + */ |
|
| 103 | + public function registerAlias($alias, $target); |
|
| 104 | 104 | } |
@@ -34,58 +34,58 @@ |
||
| 34 | 34 | * @package OC |
| 35 | 35 | */ |
| 36 | 36 | class ServerContainer extends SimpleContainer { |
| 37 | - /** @var DIContainer[] */ |
|
| 38 | - protected $appContainers; |
|
| 37 | + /** @var DIContainer[] */ |
|
| 38 | + protected $appContainers; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * ServerContainer constructor. |
|
| 42 | - */ |
|
| 43 | - public function __construct() { |
|
| 44 | - parent::__construct(); |
|
| 45 | - $this->appContainers = []; |
|
| 46 | - } |
|
| 40 | + /** |
|
| 41 | + * ServerContainer constructor. |
|
| 42 | + */ |
|
| 43 | + public function __construct() { |
|
| 44 | + parent::__construct(); |
|
| 45 | + $this->appContainers = []; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @param string $appName |
|
| 50 | - * @param DIContainer $container |
|
| 51 | - */ |
|
| 52 | - public function registerAppContainer($appName, DIContainer $container) { |
|
| 53 | - $this->appContainers[strtolower(App::buildAppNamespace($appName, ''))] = $container; |
|
| 54 | - } |
|
| 48 | + /** |
|
| 49 | + * @param string $appName |
|
| 50 | + * @param DIContainer $container |
|
| 51 | + */ |
|
| 52 | + public function registerAppContainer($appName, DIContainer $container) { |
|
| 53 | + $this->appContainers[strtolower(App::buildAppNamespace($appName, ''))] = $container; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @param string $appName |
|
| 58 | - * @return DIContainer |
|
| 59 | - */ |
|
| 60 | - public function getAppContainer($appName) { |
|
| 61 | - if (isset($this->appContainers[$appName])) { |
|
| 62 | - return $this->appContainers[$appName]; |
|
| 63 | - } |
|
| 56 | + /** |
|
| 57 | + * @param string $appName |
|
| 58 | + * @return DIContainer |
|
| 59 | + */ |
|
| 60 | + public function getAppContainer($appName) { |
|
| 61 | + if (isset($this->appContainers[$appName])) { |
|
| 62 | + return $this->appContainers[$appName]; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - return new DIContainer($appName); |
|
| 66 | - } |
|
| 65 | + return new DIContainer($appName); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @param string $name name of the service to query for |
|
| 70 | - * @return mixed registered service for the given $name |
|
| 71 | - * @throws QueryException if the query could not be resolved |
|
| 72 | - */ |
|
| 73 | - public function query($name) { |
|
| 74 | - $name = $this->sanitizeName($name); |
|
| 68 | + /** |
|
| 69 | + * @param string $name name of the service to query for |
|
| 70 | + * @return mixed registered service for the given $name |
|
| 71 | + * @throws QueryException if the query could not be resolved |
|
| 72 | + */ |
|
| 73 | + public function query($name) { |
|
| 74 | + $name = $this->sanitizeName($name); |
|
| 75 | 75 | |
| 76 | - // In case the service starts with OCA\ we try to find the service in |
|
| 77 | - // the apps container first. |
|
| 78 | - if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 79 | - $segments = explode('\\', $name); |
|
| 80 | - $appContainer = $this->getAppContainer(strtolower($segments[1])); |
|
| 81 | - try { |
|
| 82 | - return $appContainer->queryNoFallback($name); |
|
| 83 | - } catch (QueryException $e) { |
|
| 84 | - // Didn't find the service in the respective app container, |
|
| 85 | - // ignore it and fall back to the core container. |
|
| 86 | - } |
|
| 87 | - } |
|
| 76 | + // In case the service starts with OCA\ we try to find the service in |
|
| 77 | + // the apps container first. |
|
| 78 | + if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 79 | + $segments = explode('\\', $name); |
|
| 80 | + $appContainer = $this->getAppContainer(strtolower($segments[1])); |
|
| 81 | + try { |
|
| 82 | + return $appContainer->queryNoFallback($name); |
|
| 83 | + } catch (QueryException $e) { |
|
| 84 | + // Didn't find the service in the respective app container, |
|
| 85 | + // ignore it and fall back to the core container. |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - return parent::query($name); |
|
| 90 | - } |
|
| 89 | + return parent::query($name); |
|
| 90 | + } |
|
| 91 | 91 | } |
@@ -61,353 +61,353 @@ |
||
| 61 | 61 | |
| 62 | 62 | class DIContainer extends SimpleContainer implements IAppContainer { |
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @var array |
|
| 66 | - */ |
|
| 67 | - private $middleWares = array(); |
|
| 68 | - |
|
| 69 | - /** @var ServerContainer */ |
|
| 70 | - private $server; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Put your class dependencies in here |
|
| 74 | - * @param string $appName the name of the app |
|
| 75 | - * @param array $urlParams |
|
| 76 | - * @param ServerContainer $server |
|
| 77 | - */ |
|
| 78 | - public function __construct($appName, $urlParams = array(), ServerContainer $server = null){ |
|
| 79 | - parent::__construct(); |
|
| 80 | - $this['AppName'] = $appName; |
|
| 81 | - $this['urlParams'] = $urlParams; |
|
| 82 | - |
|
| 83 | - /** @var \OC\ServerContainer $server */ |
|
| 84 | - if ($server === null) { |
|
| 85 | - $server = \OC::$server; |
|
| 86 | - } |
|
| 87 | - $this->server = $server; |
|
| 88 | - $this->server->registerAppContainer($appName, $this); |
|
| 89 | - |
|
| 90 | - // aliases |
|
| 91 | - $this->registerAlias('appName', 'AppName'); |
|
| 92 | - $this->registerAlias('webRoot', 'WebRoot'); |
|
| 93 | - $this->registerAlias('userId', 'UserId'); |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Core services |
|
| 97 | - */ |
|
| 98 | - $this->registerService(IOutput::class, function($c){ |
|
| 99 | - return new Output($this->getServer()->getWebRoot()); |
|
| 100 | - }); |
|
| 101 | - |
|
| 102 | - $this->registerService(Folder::class, function() { |
|
| 103 | - return $this->getServer()->getUserFolder(); |
|
| 104 | - }); |
|
| 105 | - |
|
| 106 | - $this->registerService(IAppData::class, function (SimpleContainer $c) { |
|
| 107 | - return $this->getServer()->getAppDataDir($c->query('AppName')); |
|
| 108 | - }); |
|
| 109 | - |
|
| 110 | - $this->registerService(IL10N::class, function($c) { |
|
| 111 | - return $this->getServer()->getL10N($c->query('AppName')); |
|
| 112 | - }); |
|
| 113 | - |
|
| 114 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 115 | - $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 116 | - |
|
| 117 | - $this->registerService(IRequest::class, function() { |
|
| 118 | - return $this->getServer()->query(IRequest::class); |
|
| 119 | - }); |
|
| 120 | - $this->registerAlias('Request', IRequest::class); |
|
| 121 | - |
|
| 122 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 123 | - $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 124 | - |
|
| 125 | - $this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class); |
|
| 126 | - |
|
| 127 | - $this->registerService(IServerContainer::class, function ($c) { |
|
| 128 | - return $this->getServer(); |
|
| 129 | - }); |
|
| 130 | - $this->registerAlias('ServerContainer', IServerContainer::class); |
|
| 131 | - |
|
| 132 | - $this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) { |
|
| 133 | - return $c->query('OCA\WorkflowEngine\Manager'); |
|
| 134 | - }); |
|
| 135 | - |
|
| 136 | - $this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) { |
|
| 137 | - return $c; |
|
| 138 | - }); |
|
| 139 | - |
|
| 140 | - // commonly used attributes |
|
| 141 | - $this->registerService('UserId', function ($c) { |
|
| 142 | - return $c->query('OCP\\IUserSession')->getSession()->get('user_id'); |
|
| 143 | - }); |
|
| 144 | - |
|
| 145 | - $this->registerService('WebRoot', function ($c) { |
|
| 146 | - return $c->query('ServerContainer')->getWebRoot(); |
|
| 147 | - }); |
|
| 148 | - |
|
| 149 | - $this->registerService('fromMailAddress', function() { |
|
| 150 | - return Util::getDefaultEmailAddress('no-reply'); |
|
| 151 | - }); |
|
| 152 | - |
|
| 153 | - $this->registerService('OC_Defaults', function ($c) { |
|
| 154 | - return $c->getServer()->getThemingDefaults(); |
|
| 155 | - }); |
|
| 156 | - |
|
| 157 | - $this->registerService('OCP\Encryption\IManager', function ($c) { |
|
| 158 | - return $this->getServer()->getEncryptionManager(); |
|
| 159 | - }); |
|
| 160 | - |
|
| 161 | - $this->registerService(IValidator::class, function($c) { |
|
| 162 | - return $c->query(Validator::class); |
|
| 163 | - }); |
|
| 164 | - |
|
| 165 | - $this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) { |
|
| 166 | - return new \OC\Security\IdentityProof\Manager( |
|
| 167 | - $this->getServer()->getAppDataDir('identityproof'), |
|
| 168 | - $this->getServer()->getCrypto() |
|
| 169 | - ); |
|
| 170 | - }); |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * App Framework APIs |
|
| 175 | - */ |
|
| 176 | - $this->registerService('API', function($c){ |
|
| 177 | - $c->query('OCP\\ILogger')->debug( |
|
| 178 | - 'Accessing the API class is deprecated! Use the appropriate ' . |
|
| 179 | - 'services instead!' |
|
| 180 | - ); |
|
| 181 | - return new API($c['AppName']); |
|
| 182 | - }); |
|
| 183 | - |
|
| 184 | - $this->registerService('Protocol', function($c){ |
|
| 185 | - /** @var \OC\Server $server */ |
|
| 186 | - $server = $c->query('ServerContainer'); |
|
| 187 | - $protocol = $server->getRequest()->getHttpProtocol(); |
|
| 188 | - return new Http($_SERVER, $protocol); |
|
| 189 | - }); |
|
| 190 | - |
|
| 191 | - $this->registerService('Dispatcher', function($c) { |
|
| 192 | - return new Dispatcher( |
|
| 193 | - $c['Protocol'], |
|
| 194 | - $c['MiddlewareDispatcher'], |
|
| 195 | - $c['ControllerMethodReflector'], |
|
| 196 | - $c['Request'] |
|
| 197 | - ); |
|
| 198 | - }); |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * App Framework default arguments |
|
| 202 | - */ |
|
| 203 | - $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH'); |
|
| 204 | - $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept'); |
|
| 205 | - $this->registerParameter('corsMaxAge', 1728000); |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * Middleware |
|
| 209 | - */ |
|
| 210 | - $app = $this; |
|
| 211 | - $this->registerService('SecurityMiddleware', function($c) use ($app){ |
|
| 212 | - /** @var \OC\Server $server */ |
|
| 213 | - $server = $app->getServer(); |
|
| 214 | - |
|
| 215 | - return new SecurityMiddleware( |
|
| 216 | - $c['Request'], |
|
| 217 | - $c['ControllerMethodReflector'], |
|
| 218 | - $server->getNavigationManager(), |
|
| 219 | - $server->getURLGenerator(), |
|
| 220 | - $server->getLogger(), |
|
| 221 | - $server->getSession(), |
|
| 222 | - $c['AppName'], |
|
| 223 | - $app->isLoggedIn(), |
|
| 224 | - $app->isAdminUser(), |
|
| 225 | - $server->getContentSecurityPolicyManager(), |
|
| 226 | - $server->getCsrfTokenManager(), |
|
| 227 | - $server->getContentSecurityPolicyNonceManager(), |
|
| 228 | - $server->getBruteForceThrottler() |
|
| 229 | - ); |
|
| 230 | - |
|
| 231 | - }); |
|
| 232 | - |
|
| 233 | - $this->registerService('CORSMiddleware', function($c) { |
|
| 234 | - return new CORSMiddleware( |
|
| 235 | - $c['Request'], |
|
| 236 | - $c['ControllerMethodReflector'], |
|
| 237 | - $c->query(IUserSession::class), |
|
| 238 | - $c->getServer()->getBruteForceThrottler() |
|
| 239 | - ); |
|
| 240 | - }); |
|
| 241 | - |
|
| 242 | - $this->registerService('SessionMiddleware', function($c) use ($app) { |
|
| 243 | - return new SessionMiddleware( |
|
| 244 | - $c['Request'], |
|
| 245 | - $c['ControllerMethodReflector'], |
|
| 246 | - $app->getServer()->getSession() |
|
| 247 | - ); |
|
| 248 | - }); |
|
| 249 | - |
|
| 250 | - $this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) { |
|
| 251 | - $twoFactorManager = $c->getServer()->getTwoFactorAuthManager(); |
|
| 252 | - $userSession = $app->getServer()->getUserSession(); |
|
| 253 | - $session = $app->getServer()->getSession(); |
|
| 254 | - $urlGenerator = $app->getServer()->getURLGenerator(); |
|
| 255 | - $reflector = $c['ControllerMethodReflector']; |
|
| 256 | - $request = $app->getServer()->getRequest(); |
|
| 257 | - return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request); |
|
| 258 | - }); |
|
| 259 | - |
|
| 260 | - $this->registerService('OCSMiddleware', function (SimpleContainer $c) { |
|
| 261 | - return new OCSMiddleware( |
|
| 262 | - $c['Request'] |
|
| 263 | - ); |
|
| 264 | - }); |
|
| 265 | - |
|
| 266 | - $middleWares = &$this->middleWares; |
|
| 267 | - $this->registerService('MiddlewareDispatcher', function($c) use (&$middleWares) { |
|
| 268 | - $dispatcher = new MiddlewareDispatcher(); |
|
| 269 | - $dispatcher->registerMiddleware($c['CORSMiddleware']); |
|
| 270 | - $dispatcher->registerMiddleware($c['OCSMiddleware']); |
|
| 271 | - $dispatcher->registerMiddleware($c['SecurityMiddleware']); |
|
| 272 | - $dispatcher->registerMiddleWare($c['TwoFactorMiddleware']); |
|
| 273 | - |
|
| 274 | - foreach($middleWares as $middleWare) { |
|
| 275 | - $dispatcher->registerMiddleware($c[$middleWare]); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - $dispatcher->registerMiddleware($c['SessionMiddleware']); |
|
| 279 | - return $dispatcher; |
|
| 280 | - }); |
|
| 281 | - |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * @deprecated implements only deprecated methods |
|
| 287 | - * @return IApi |
|
| 288 | - */ |
|
| 289 | - function getCoreApi() |
|
| 290 | - { |
|
| 291 | - return $this->query('API'); |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * @return \OCP\IServerContainer |
|
| 296 | - */ |
|
| 297 | - function getServer() |
|
| 298 | - { |
|
| 299 | - return $this->server; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * @param string $middleWare |
|
| 304 | - * @return boolean|null |
|
| 305 | - */ |
|
| 306 | - function registerMiddleWare($middleWare) { |
|
| 307 | - array_push($this->middleWares, $middleWare); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * used to return the appname of the set application |
|
| 312 | - * @return string the name of your application |
|
| 313 | - */ |
|
| 314 | - function getAppName() { |
|
| 315 | - return $this->query('AppName'); |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * @deprecated use IUserSession->isLoggedIn() |
|
| 320 | - * @return boolean |
|
| 321 | - */ |
|
| 322 | - function isLoggedIn() { |
|
| 323 | - return \OC::$server->getUserSession()->isLoggedIn(); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * @deprecated use IGroupManager->isAdmin($userId) |
|
| 328 | - * @return boolean |
|
| 329 | - */ |
|
| 330 | - function isAdminUser() { |
|
| 331 | - $uid = $this->getUserId(); |
|
| 332 | - return \OC_User::isAdminUser($uid); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - private function getUserId() { |
|
| 336 | - return $this->getServer()->getSession()->get('user_id'); |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * @deprecated use the ILogger instead |
|
| 341 | - * @param string $message |
|
| 342 | - * @param string $level |
|
| 343 | - * @return mixed |
|
| 344 | - */ |
|
| 345 | - function log($message, $level) { |
|
| 346 | - switch($level){ |
|
| 347 | - case 'debug': |
|
| 348 | - $level = \OCP\Util::DEBUG; |
|
| 349 | - break; |
|
| 350 | - case 'info': |
|
| 351 | - $level = \OCP\Util::INFO; |
|
| 352 | - break; |
|
| 353 | - case 'warn': |
|
| 354 | - $level = \OCP\Util::WARN; |
|
| 355 | - break; |
|
| 356 | - case 'fatal': |
|
| 357 | - $level = \OCP\Util::FATAL; |
|
| 358 | - break; |
|
| 359 | - default: |
|
| 360 | - $level = \OCP\Util::ERROR; |
|
| 361 | - break; |
|
| 362 | - } |
|
| 363 | - \OCP\Util::writeLog($this->getAppName(), $message, $level); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * Register a capability |
|
| 368 | - * |
|
| 369 | - * @param string $serviceName e.g. 'OCA\Files\Capabilities' |
|
| 370 | - */ |
|
| 371 | - public function registerCapability($serviceName) { |
|
| 372 | - $this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) { |
|
| 373 | - return $this->query($serviceName); |
|
| 374 | - }); |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * @param string $name |
|
| 379 | - * @return mixed |
|
| 380 | - * @throws QueryException if the query could not be resolved |
|
| 381 | - */ |
|
| 382 | - public function query($name) { |
|
| 383 | - try { |
|
| 384 | - return $this->queryNoFallback($name); |
|
| 385 | - } catch (QueryException $e) { |
|
| 386 | - return $this->getServer()->query($name); |
|
| 387 | - } |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * @param string $name |
|
| 392 | - * @return mixed |
|
| 393 | - * @throws QueryException if the query could not be resolved |
|
| 394 | - */ |
|
| 395 | - public function queryNoFallback($name) { |
|
| 396 | - $name = $this->sanitizeName($name); |
|
| 397 | - |
|
| 398 | - if ($this->offsetExists($name)) { |
|
| 399 | - return parent::query($name); |
|
| 400 | - } else { |
|
| 401 | - if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) { |
|
| 402 | - return parent::query($name); |
|
| 403 | - } else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) { |
|
| 404 | - return parent::query($name); |
|
| 405 | - } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) { |
|
| 406 | - return parent::query($name); |
|
| 407 | - } |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - throw new QueryException('Could not resolve ' . $name . '!' . |
|
| 411 | - ' Class can not be instantiated'); |
|
| 412 | - } |
|
| 64 | + /** |
|
| 65 | + * @var array |
|
| 66 | + */ |
|
| 67 | + private $middleWares = array(); |
|
| 68 | + |
|
| 69 | + /** @var ServerContainer */ |
|
| 70 | + private $server; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Put your class dependencies in here |
|
| 74 | + * @param string $appName the name of the app |
|
| 75 | + * @param array $urlParams |
|
| 76 | + * @param ServerContainer $server |
|
| 77 | + */ |
|
| 78 | + public function __construct($appName, $urlParams = array(), ServerContainer $server = null){ |
|
| 79 | + parent::__construct(); |
|
| 80 | + $this['AppName'] = $appName; |
|
| 81 | + $this['urlParams'] = $urlParams; |
|
| 82 | + |
|
| 83 | + /** @var \OC\ServerContainer $server */ |
|
| 84 | + if ($server === null) { |
|
| 85 | + $server = \OC::$server; |
|
| 86 | + } |
|
| 87 | + $this->server = $server; |
|
| 88 | + $this->server->registerAppContainer($appName, $this); |
|
| 89 | + |
|
| 90 | + // aliases |
|
| 91 | + $this->registerAlias('appName', 'AppName'); |
|
| 92 | + $this->registerAlias('webRoot', 'WebRoot'); |
|
| 93 | + $this->registerAlias('userId', 'UserId'); |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Core services |
|
| 97 | + */ |
|
| 98 | + $this->registerService(IOutput::class, function($c){ |
|
| 99 | + return new Output($this->getServer()->getWebRoot()); |
|
| 100 | + }); |
|
| 101 | + |
|
| 102 | + $this->registerService(Folder::class, function() { |
|
| 103 | + return $this->getServer()->getUserFolder(); |
|
| 104 | + }); |
|
| 105 | + |
|
| 106 | + $this->registerService(IAppData::class, function (SimpleContainer $c) { |
|
| 107 | + return $this->getServer()->getAppDataDir($c->query('AppName')); |
|
| 108 | + }); |
|
| 109 | + |
|
| 110 | + $this->registerService(IL10N::class, function($c) { |
|
| 111 | + return $this->getServer()->getL10N($c->query('AppName')); |
|
| 112 | + }); |
|
| 113 | + |
|
| 114 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 115 | + $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 116 | + |
|
| 117 | + $this->registerService(IRequest::class, function() { |
|
| 118 | + return $this->getServer()->query(IRequest::class); |
|
| 119 | + }); |
|
| 120 | + $this->registerAlias('Request', IRequest::class); |
|
| 121 | + |
|
| 122 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 123 | + $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 124 | + |
|
| 125 | + $this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class); |
|
| 126 | + |
|
| 127 | + $this->registerService(IServerContainer::class, function ($c) { |
|
| 128 | + return $this->getServer(); |
|
| 129 | + }); |
|
| 130 | + $this->registerAlias('ServerContainer', IServerContainer::class); |
|
| 131 | + |
|
| 132 | + $this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) { |
|
| 133 | + return $c->query('OCA\WorkflowEngine\Manager'); |
|
| 134 | + }); |
|
| 135 | + |
|
| 136 | + $this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) { |
|
| 137 | + return $c; |
|
| 138 | + }); |
|
| 139 | + |
|
| 140 | + // commonly used attributes |
|
| 141 | + $this->registerService('UserId', function ($c) { |
|
| 142 | + return $c->query('OCP\\IUserSession')->getSession()->get('user_id'); |
|
| 143 | + }); |
|
| 144 | + |
|
| 145 | + $this->registerService('WebRoot', function ($c) { |
|
| 146 | + return $c->query('ServerContainer')->getWebRoot(); |
|
| 147 | + }); |
|
| 148 | + |
|
| 149 | + $this->registerService('fromMailAddress', function() { |
|
| 150 | + return Util::getDefaultEmailAddress('no-reply'); |
|
| 151 | + }); |
|
| 152 | + |
|
| 153 | + $this->registerService('OC_Defaults', function ($c) { |
|
| 154 | + return $c->getServer()->getThemingDefaults(); |
|
| 155 | + }); |
|
| 156 | + |
|
| 157 | + $this->registerService('OCP\Encryption\IManager', function ($c) { |
|
| 158 | + return $this->getServer()->getEncryptionManager(); |
|
| 159 | + }); |
|
| 160 | + |
|
| 161 | + $this->registerService(IValidator::class, function($c) { |
|
| 162 | + return $c->query(Validator::class); |
|
| 163 | + }); |
|
| 164 | + |
|
| 165 | + $this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) { |
|
| 166 | + return new \OC\Security\IdentityProof\Manager( |
|
| 167 | + $this->getServer()->getAppDataDir('identityproof'), |
|
| 168 | + $this->getServer()->getCrypto() |
|
| 169 | + ); |
|
| 170 | + }); |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * App Framework APIs |
|
| 175 | + */ |
|
| 176 | + $this->registerService('API', function($c){ |
|
| 177 | + $c->query('OCP\\ILogger')->debug( |
|
| 178 | + 'Accessing the API class is deprecated! Use the appropriate ' . |
|
| 179 | + 'services instead!' |
|
| 180 | + ); |
|
| 181 | + return new API($c['AppName']); |
|
| 182 | + }); |
|
| 183 | + |
|
| 184 | + $this->registerService('Protocol', function($c){ |
|
| 185 | + /** @var \OC\Server $server */ |
|
| 186 | + $server = $c->query('ServerContainer'); |
|
| 187 | + $protocol = $server->getRequest()->getHttpProtocol(); |
|
| 188 | + return new Http($_SERVER, $protocol); |
|
| 189 | + }); |
|
| 190 | + |
|
| 191 | + $this->registerService('Dispatcher', function($c) { |
|
| 192 | + return new Dispatcher( |
|
| 193 | + $c['Protocol'], |
|
| 194 | + $c['MiddlewareDispatcher'], |
|
| 195 | + $c['ControllerMethodReflector'], |
|
| 196 | + $c['Request'] |
|
| 197 | + ); |
|
| 198 | + }); |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * App Framework default arguments |
|
| 202 | + */ |
|
| 203 | + $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH'); |
|
| 204 | + $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept'); |
|
| 205 | + $this->registerParameter('corsMaxAge', 1728000); |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * Middleware |
|
| 209 | + */ |
|
| 210 | + $app = $this; |
|
| 211 | + $this->registerService('SecurityMiddleware', function($c) use ($app){ |
|
| 212 | + /** @var \OC\Server $server */ |
|
| 213 | + $server = $app->getServer(); |
|
| 214 | + |
|
| 215 | + return new SecurityMiddleware( |
|
| 216 | + $c['Request'], |
|
| 217 | + $c['ControllerMethodReflector'], |
|
| 218 | + $server->getNavigationManager(), |
|
| 219 | + $server->getURLGenerator(), |
|
| 220 | + $server->getLogger(), |
|
| 221 | + $server->getSession(), |
|
| 222 | + $c['AppName'], |
|
| 223 | + $app->isLoggedIn(), |
|
| 224 | + $app->isAdminUser(), |
|
| 225 | + $server->getContentSecurityPolicyManager(), |
|
| 226 | + $server->getCsrfTokenManager(), |
|
| 227 | + $server->getContentSecurityPolicyNonceManager(), |
|
| 228 | + $server->getBruteForceThrottler() |
|
| 229 | + ); |
|
| 230 | + |
|
| 231 | + }); |
|
| 232 | + |
|
| 233 | + $this->registerService('CORSMiddleware', function($c) { |
|
| 234 | + return new CORSMiddleware( |
|
| 235 | + $c['Request'], |
|
| 236 | + $c['ControllerMethodReflector'], |
|
| 237 | + $c->query(IUserSession::class), |
|
| 238 | + $c->getServer()->getBruteForceThrottler() |
|
| 239 | + ); |
|
| 240 | + }); |
|
| 241 | + |
|
| 242 | + $this->registerService('SessionMiddleware', function($c) use ($app) { |
|
| 243 | + return new SessionMiddleware( |
|
| 244 | + $c['Request'], |
|
| 245 | + $c['ControllerMethodReflector'], |
|
| 246 | + $app->getServer()->getSession() |
|
| 247 | + ); |
|
| 248 | + }); |
|
| 249 | + |
|
| 250 | + $this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) { |
|
| 251 | + $twoFactorManager = $c->getServer()->getTwoFactorAuthManager(); |
|
| 252 | + $userSession = $app->getServer()->getUserSession(); |
|
| 253 | + $session = $app->getServer()->getSession(); |
|
| 254 | + $urlGenerator = $app->getServer()->getURLGenerator(); |
|
| 255 | + $reflector = $c['ControllerMethodReflector']; |
|
| 256 | + $request = $app->getServer()->getRequest(); |
|
| 257 | + return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request); |
|
| 258 | + }); |
|
| 259 | + |
|
| 260 | + $this->registerService('OCSMiddleware', function (SimpleContainer $c) { |
|
| 261 | + return new OCSMiddleware( |
|
| 262 | + $c['Request'] |
|
| 263 | + ); |
|
| 264 | + }); |
|
| 265 | + |
|
| 266 | + $middleWares = &$this->middleWares; |
|
| 267 | + $this->registerService('MiddlewareDispatcher', function($c) use (&$middleWares) { |
|
| 268 | + $dispatcher = new MiddlewareDispatcher(); |
|
| 269 | + $dispatcher->registerMiddleware($c['CORSMiddleware']); |
|
| 270 | + $dispatcher->registerMiddleware($c['OCSMiddleware']); |
|
| 271 | + $dispatcher->registerMiddleware($c['SecurityMiddleware']); |
|
| 272 | + $dispatcher->registerMiddleWare($c['TwoFactorMiddleware']); |
|
| 273 | + |
|
| 274 | + foreach($middleWares as $middleWare) { |
|
| 275 | + $dispatcher->registerMiddleware($c[$middleWare]); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + $dispatcher->registerMiddleware($c['SessionMiddleware']); |
|
| 279 | + return $dispatcher; |
|
| 280 | + }); |
|
| 281 | + |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * @deprecated implements only deprecated methods |
|
| 287 | + * @return IApi |
|
| 288 | + */ |
|
| 289 | + function getCoreApi() |
|
| 290 | + { |
|
| 291 | + return $this->query('API'); |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * @return \OCP\IServerContainer |
|
| 296 | + */ |
|
| 297 | + function getServer() |
|
| 298 | + { |
|
| 299 | + return $this->server; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * @param string $middleWare |
|
| 304 | + * @return boolean|null |
|
| 305 | + */ |
|
| 306 | + function registerMiddleWare($middleWare) { |
|
| 307 | + array_push($this->middleWares, $middleWare); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * used to return the appname of the set application |
|
| 312 | + * @return string the name of your application |
|
| 313 | + */ |
|
| 314 | + function getAppName() { |
|
| 315 | + return $this->query('AppName'); |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * @deprecated use IUserSession->isLoggedIn() |
|
| 320 | + * @return boolean |
|
| 321 | + */ |
|
| 322 | + function isLoggedIn() { |
|
| 323 | + return \OC::$server->getUserSession()->isLoggedIn(); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * @deprecated use IGroupManager->isAdmin($userId) |
|
| 328 | + * @return boolean |
|
| 329 | + */ |
|
| 330 | + function isAdminUser() { |
|
| 331 | + $uid = $this->getUserId(); |
|
| 332 | + return \OC_User::isAdminUser($uid); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + private function getUserId() { |
|
| 336 | + return $this->getServer()->getSession()->get('user_id'); |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * @deprecated use the ILogger instead |
|
| 341 | + * @param string $message |
|
| 342 | + * @param string $level |
|
| 343 | + * @return mixed |
|
| 344 | + */ |
|
| 345 | + function log($message, $level) { |
|
| 346 | + switch($level){ |
|
| 347 | + case 'debug': |
|
| 348 | + $level = \OCP\Util::DEBUG; |
|
| 349 | + break; |
|
| 350 | + case 'info': |
|
| 351 | + $level = \OCP\Util::INFO; |
|
| 352 | + break; |
|
| 353 | + case 'warn': |
|
| 354 | + $level = \OCP\Util::WARN; |
|
| 355 | + break; |
|
| 356 | + case 'fatal': |
|
| 357 | + $level = \OCP\Util::FATAL; |
|
| 358 | + break; |
|
| 359 | + default: |
|
| 360 | + $level = \OCP\Util::ERROR; |
|
| 361 | + break; |
|
| 362 | + } |
|
| 363 | + \OCP\Util::writeLog($this->getAppName(), $message, $level); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * Register a capability |
|
| 368 | + * |
|
| 369 | + * @param string $serviceName e.g. 'OCA\Files\Capabilities' |
|
| 370 | + */ |
|
| 371 | + public function registerCapability($serviceName) { |
|
| 372 | + $this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) { |
|
| 373 | + return $this->query($serviceName); |
|
| 374 | + }); |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * @param string $name |
|
| 379 | + * @return mixed |
|
| 380 | + * @throws QueryException if the query could not be resolved |
|
| 381 | + */ |
|
| 382 | + public function query($name) { |
|
| 383 | + try { |
|
| 384 | + return $this->queryNoFallback($name); |
|
| 385 | + } catch (QueryException $e) { |
|
| 386 | + return $this->getServer()->query($name); |
|
| 387 | + } |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * @param string $name |
|
| 392 | + * @return mixed |
|
| 393 | + * @throws QueryException if the query could not be resolved |
|
| 394 | + */ |
|
| 395 | + public function queryNoFallback($name) { |
|
| 396 | + $name = $this->sanitizeName($name); |
|
| 397 | + |
|
| 398 | + if ($this->offsetExists($name)) { |
|
| 399 | + return parent::query($name); |
|
| 400 | + } else { |
|
| 401 | + if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) { |
|
| 402 | + return parent::query($name); |
|
| 403 | + } else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) { |
|
| 404 | + return parent::query($name); |
|
| 405 | + } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) { |
|
| 406 | + return parent::query($name); |
|
| 407 | + } |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + throw new QueryException('Could not resolve ' . $name . '!' . |
|
| 411 | + ' Class can not be instantiated'); |
|
| 412 | + } |
|
| 413 | 413 | } |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * @param array $urlParams |
| 76 | 76 | * @param ServerContainer $server |
| 77 | 77 | */ |
| 78 | - public function __construct($appName, $urlParams = array(), ServerContainer $server = null){ |
|
| 78 | + public function __construct($appName, $urlParams = array(), ServerContainer $server = null) { |
|
| 79 | 79 | parent::__construct(); |
| 80 | 80 | $this['AppName'] = $appName; |
| 81 | 81 | $this['urlParams'] = $urlParams; |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | /** |
| 96 | 96 | * Core services |
| 97 | 97 | */ |
| 98 | - $this->registerService(IOutput::class, function($c){ |
|
| 98 | + $this->registerService(IOutput::class, function($c) { |
|
| 99 | 99 | return new Output($this->getServer()->getWebRoot()); |
| 100 | 100 | }); |
| 101 | 101 | |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | return $this->getServer()->getUserFolder(); |
| 104 | 104 | }); |
| 105 | 105 | |
| 106 | - $this->registerService(IAppData::class, function (SimpleContainer $c) { |
|
| 106 | + $this->registerService(IAppData::class, function(SimpleContainer $c) { |
|
| 107 | 107 | return $this->getServer()->getAppDataDir($c->query('AppName')); |
| 108 | 108 | }); |
| 109 | 109 | |
@@ -124,25 +124,25 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | $this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class); |
| 126 | 126 | |
| 127 | - $this->registerService(IServerContainer::class, function ($c) { |
|
| 127 | + $this->registerService(IServerContainer::class, function($c) { |
|
| 128 | 128 | return $this->getServer(); |
| 129 | 129 | }); |
| 130 | 130 | $this->registerAlias('ServerContainer', IServerContainer::class); |
| 131 | 131 | |
| 132 | - $this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) { |
|
| 132 | + $this->registerService(\OCP\WorkflowEngine\IManager::class, function($c) { |
|
| 133 | 133 | return $c->query('OCA\WorkflowEngine\Manager'); |
| 134 | 134 | }); |
| 135 | 135 | |
| 136 | - $this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) { |
|
| 136 | + $this->registerService(\OCP\AppFramework\IAppContainer::class, function($c) { |
|
| 137 | 137 | return $c; |
| 138 | 138 | }); |
| 139 | 139 | |
| 140 | 140 | // commonly used attributes |
| 141 | - $this->registerService('UserId', function ($c) { |
|
| 141 | + $this->registerService('UserId', function($c) { |
|
| 142 | 142 | return $c->query('OCP\\IUserSession')->getSession()->get('user_id'); |
| 143 | 143 | }); |
| 144 | 144 | |
| 145 | - $this->registerService('WebRoot', function ($c) { |
|
| 145 | + $this->registerService('WebRoot', function($c) { |
|
| 146 | 146 | return $c->query('ServerContainer')->getWebRoot(); |
| 147 | 147 | }); |
| 148 | 148 | |
@@ -150,11 +150,11 @@ discard block |
||
| 150 | 150 | return Util::getDefaultEmailAddress('no-reply'); |
| 151 | 151 | }); |
| 152 | 152 | |
| 153 | - $this->registerService('OC_Defaults', function ($c) { |
|
| 153 | + $this->registerService('OC_Defaults', function($c) { |
|
| 154 | 154 | return $c->getServer()->getThemingDefaults(); |
| 155 | 155 | }); |
| 156 | 156 | |
| 157 | - $this->registerService('OCP\Encryption\IManager', function ($c) { |
|
| 157 | + $this->registerService('OCP\Encryption\IManager', function($c) { |
|
| 158 | 158 | return $this->getServer()->getEncryptionManager(); |
| 159 | 159 | }); |
| 160 | 160 | |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | return $c->query(Validator::class); |
| 163 | 163 | }); |
| 164 | 164 | |
| 165 | - $this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) { |
|
| 165 | + $this->registerService(\OC\Security\IdentityProof\Manager::class, function($c) { |
|
| 166 | 166 | return new \OC\Security\IdentityProof\Manager( |
| 167 | 167 | $this->getServer()->getAppDataDir('identityproof'), |
| 168 | 168 | $this->getServer()->getCrypto() |
@@ -173,15 +173,15 @@ discard block |
||
| 173 | 173 | /** |
| 174 | 174 | * App Framework APIs |
| 175 | 175 | */ |
| 176 | - $this->registerService('API', function($c){ |
|
| 176 | + $this->registerService('API', function($c) { |
|
| 177 | 177 | $c->query('OCP\\ILogger')->debug( |
| 178 | - 'Accessing the API class is deprecated! Use the appropriate ' . |
|
| 178 | + 'Accessing the API class is deprecated! Use the appropriate '. |
|
| 179 | 179 | 'services instead!' |
| 180 | 180 | ); |
| 181 | 181 | return new API($c['AppName']); |
| 182 | 182 | }); |
| 183 | 183 | |
| 184 | - $this->registerService('Protocol', function($c){ |
|
| 184 | + $this->registerService('Protocol', function($c) { |
|
| 185 | 185 | /** @var \OC\Server $server */ |
| 186 | 186 | $server = $c->query('ServerContainer'); |
| 187 | 187 | $protocol = $server->getRequest()->getHttpProtocol(); |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | ); |
| 248 | 248 | }); |
| 249 | 249 | |
| 250 | - $this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) { |
|
| 250 | + $this->registerService('TwoFactorMiddleware', function(SimpleContainer $c) use ($app) { |
|
| 251 | 251 | $twoFactorManager = $c->getServer()->getTwoFactorAuthManager(); |
| 252 | 252 | $userSession = $app->getServer()->getUserSession(); |
| 253 | 253 | $session = $app->getServer()->getSession(); |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request); |
| 258 | 258 | }); |
| 259 | 259 | |
| 260 | - $this->registerService('OCSMiddleware', function (SimpleContainer $c) { |
|
| 260 | + $this->registerService('OCSMiddleware', function(SimpleContainer $c) { |
|
| 261 | 261 | return new OCSMiddleware( |
| 262 | 262 | $c['Request'] |
| 263 | 263 | ); |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | $dispatcher->registerMiddleware($c['SecurityMiddleware']); |
| 272 | 272 | $dispatcher->registerMiddleWare($c['TwoFactorMiddleware']); |
| 273 | 273 | |
| 274 | - foreach($middleWares as $middleWare) { |
|
| 274 | + foreach ($middleWares as $middleWare) { |
|
| 275 | 275 | $dispatcher->registerMiddleware($c[$middleWare]); |
| 276 | 276 | } |
| 277 | 277 | |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | * @return mixed |
| 344 | 344 | */ |
| 345 | 345 | function log($message, $level) { |
| 346 | - switch($level){ |
|
| 346 | + switch ($level) { |
|
| 347 | 347 | case 'debug': |
| 348 | 348 | $level = \OCP\Util::DEBUG; |
| 349 | 349 | break; |
@@ -402,12 +402,12 @@ discard block |
||
| 402 | 402 | return parent::query($name); |
| 403 | 403 | } else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) { |
| 404 | 404 | return parent::query($name); |
| 405 | - } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) { |
|
| 405 | + } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']).'\\') === 0) { |
|
| 406 | 406 | return parent::query($name); |
| 407 | 407 | } |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | - throw new QueryException('Could not resolve ' . $name . '!' . |
|
| 410 | + throw new QueryException('Could not resolve '.$name.'!'. |
|
| 411 | 411 | ' Class can not be instantiated'); |
| 412 | 412 | } |
| 413 | 413 | } |