@@ -37,127 +37,127 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | class TemplateResponse extends Response { |
| 39 | 39 | |
| 40 | - const EVENT_LOAD_ADDITIONAL_SCRIPTS = self::class . '::loadAdditionalScripts'; |
|
| 41 | - const EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN = self::class . '::loadAdditionalScriptsLoggedIn'; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * name of the template |
|
| 45 | - * @var string |
|
| 46 | - */ |
|
| 47 | - protected $templateName; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * parameters |
|
| 51 | - * @var array |
|
| 52 | - */ |
|
| 53 | - protected $params; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * rendering type (admin, user, blank) |
|
| 57 | - * @var string |
|
| 58 | - */ |
|
| 59 | - protected $renderAs; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * app name |
|
| 63 | - * @var string |
|
| 64 | - */ |
|
| 65 | - protected $appName; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * constructor of TemplateResponse |
|
| 69 | - * @param string $appName the name of the app to load the template from |
|
| 70 | - * @param string $templateName the name of the template |
|
| 71 | - * @param array $params an array of parameters which should be passed to the |
|
| 72 | - * template |
|
| 73 | - * @param string $renderAs how the page should be rendered, defaults to user |
|
| 74 | - * @since 6.0.0 - parameters $params and $renderAs were added in 7.0.0 |
|
| 75 | - */ |
|
| 76 | - public function __construct($appName, $templateName, array $params=array(), |
|
| 77 | - $renderAs='user') { |
|
| 78 | - $this->templateName = $templateName; |
|
| 79 | - $this->appName = $appName; |
|
| 80 | - $this->params = $params; |
|
| 81 | - $this->renderAs = $renderAs; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Sets template parameters |
|
| 87 | - * @param array $params an array with key => value structure which sets template |
|
| 88 | - * variables |
|
| 89 | - * @return TemplateResponse Reference to this object |
|
| 90 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
| 91 | - */ |
|
| 92 | - public function setParams(array $params){ |
|
| 93 | - $this->params = $params; |
|
| 94 | - |
|
| 95 | - return $this; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Used for accessing the set parameters |
|
| 101 | - * @return array the params |
|
| 102 | - * @since 6.0.0 |
|
| 103 | - */ |
|
| 104 | - public function getParams(){ |
|
| 105 | - return $this->params; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Used for accessing the name of the set template |
|
| 111 | - * @return string the name of the used template |
|
| 112 | - * @since 6.0.0 |
|
| 113 | - */ |
|
| 114 | - public function getTemplateName(){ |
|
| 115 | - return $this->templateName; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Sets the template page |
|
| 121 | - * @param string $renderAs admin, user or blank. Admin also prints the admin |
|
| 122 | - * settings header and footer, user renders the normal |
|
| 123 | - * normal page including footer and header and blank |
|
| 124 | - * just renders the plain template |
|
| 125 | - * @return TemplateResponse Reference to this object |
|
| 126 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
| 127 | - */ |
|
| 128 | - public function renderAs($renderAs){ |
|
| 129 | - $this->renderAs = $renderAs; |
|
| 130 | - |
|
| 131 | - return $this; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Returns the set renderAs |
|
| 137 | - * @return string the renderAs value |
|
| 138 | - * @since 6.0.0 |
|
| 139 | - */ |
|
| 140 | - public function getRenderAs(){ |
|
| 141 | - return $this->renderAs; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Returns the rendered html |
|
| 147 | - * @return string the rendered html |
|
| 148 | - * @since 6.0.0 |
|
| 149 | - */ |
|
| 150 | - public function render(){ |
|
| 151 | - // \OCP\Template needs an empty string instead of 'blank' for an unwrapped response |
|
| 152 | - $renderAs = $this->renderAs === 'blank' ? '' : $this->renderAs; |
|
| 153 | - |
|
| 154 | - $template = new \OCP\Template($this->appName, $this->templateName, $renderAs); |
|
| 155 | - |
|
| 156 | - foreach($this->params as $key => $value){ |
|
| 157 | - $template->assign($key, $value); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - return $template->fetchPage($this->params); |
|
| 161 | - } |
|
| 40 | + const EVENT_LOAD_ADDITIONAL_SCRIPTS = self::class . '::loadAdditionalScripts'; |
|
| 41 | + const EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN = self::class . '::loadAdditionalScriptsLoggedIn'; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * name of the template |
|
| 45 | + * @var string |
|
| 46 | + */ |
|
| 47 | + protected $templateName; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * parameters |
|
| 51 | + * @var array |
|
| 52 | + */ |
|
| 53 | + protected $params; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * rendering type (admin, user, blank) |
|
| 57 | + * @var string |
|
| 58 | + */ |
|
| 59 | + protected $renderAs; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * app name |
|
| 63 | + * @var string |
|
| 64 | + */ |
|
| 65 | + protected $appName; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * constructor of TemplateResponse |
|
| 69 | + * @param string $appName the name of the app to load the template from |
|
| 70 | + * @param string $templateName the name of the template |
|
| 71 | + * @param array $params an array of parameters which should be passed to the |
|
| 72 | + * template |
|
| 73 | + * @param string $renderAs how the page should be rendered, defaults to user |
|
| 74 | + * @since 6.0.0 - parameters $params and $renderAs were added in 7.0.0 |
|
| 75 | + */ |
|
| 76 | + public function __construct($appName, $templateName, array $params=array(), |
|
| 77 | + $renderAs='user') { |
|
| 78 | + $this->templateName = $templateName; |
|
| 79 | + $this->appName = $appName; |
|
| 80 | + $this->params = $params; |
|
| 81 | + $this->renderAs = $renderAs; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Sets template parameters |
|
| 87 | + * @param array $params an array with key => value structure which sets template |
|
| 88 | + * variables |
|
| 89 | + * @return TemplateResponse Reference to this object |
|
| 90 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
| 91 | + */ |
|
| 92 | + public function setParams(array $params){ |
|
| 93 | + $this->params = $params; |
|
| 94 | + |
|
| 95 | + return $this; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Used for accessing the set parameters |
|
| 101 | + * @return array the params |
|
| 102 | + * @since 6.0.0 |
|
| 103 | + */ |
|
| 104 | + public function getParams(){ |
|
| 105 | + return $this->params; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Used for accessing the name of the set template |
|
| 111 | + * @return string the name of the used template |
|
| 112 | + * @since 6.0.0 |
|
| 113 | + */ |
|
| 114 | + public function getTemplateName(){ |
|
| 115 | + return $this->templateName; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Sets the template page |
|
| 121 | + * @param string $renderAs admin, user or blank. Admin also prints the admin |
|
| 122 | + * settings header and footer, user renders the normal |
|
| 123 | + * normal page including footer and header and blank |
|
| 124 | + * just renders the plain template |
|
| 125 | + * @return TemplateResponse Reference to this object |
|
| 126 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
| 127 | + */ |
|
| 128 | + public function renderAs($renderAs){ |
|
| 129 | + $this->renderAs = $renderAs; |
|
| 130 | + |
|
| 131 | + return $this; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Returns the set renderAs |
|
| 137 | + * @return string the renderAs value |
|
| 138 | + * @since 6.0.0 |
|
| 139 | + */ |
|
| 140 | + public function getRenderAs(){ |
|
| 141 | + return $this->renderAs; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Returns the rendered html |
|
| 147 | + * @return string the rendered html |
|
| 148 | + * @since 6.0.0 |
|
| 149 | + */ |
|
| 150 | + public function render(){ |
|
| 151 | + // \OCP\Template needs an empty string instead of 'blank' for an unwrapped response |
|
| 152 | + $renderAs = $this->renderAs === 'blank' ? '' : $this->renderAs; |
|
| 153 | + |
|
| 154 | + $template = new \OCP\Template($this->appName, $this->templateName, $renderAs); |
|
| 155 | + |
|
| 156 | + foreach($this->params as $key => $value){ |
|
| 157 | + $template->assign($key, $value); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + return $template->fetchPage($this->params); |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | 163 | } |
@@ -37,8 +37,8 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | class TemplateResponse extends Response { |
| 39 | 39 | |
| 40 | - const EVENT_LOAD_ADDITIONAL_SCRIPTS = self::class . '::loadAdditionalScripts'; |
|
| 41 | - const EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN = self::class . '::loadAdditionalScriptsLoggedIn'; |
|
| 40 | + const EVENT_LOAD_ADDITIONAL_SCRIPTS = self::class.'::loadAdditionalScripts'; |
|
| 41 | + const EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN = self::class.'::loadAdditionalScriptsLoggedIn'; |
|
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | 44 | * name of the template |
@@ -73,8 +73,8 @@ discard block |
||
| 73 | 73 | * @param string $renderAs how the page should be rendered, defaults to user |
| 74 | 74 | * @since 6.0.0 - parameters $params and $renderAs were added in 7.0.0 |
| 75 | 75 | */ |
| 76 | - public function __construct($appName, $templateName, array $params=array(), |
|
| 77 | - $renderAs='user') { |
|
| 76 | + public function __construct($appName, $templateName, array $params = array(), |
|
| 77 | + $renderAs = 'user') { |
|
| 78 | 78 | $this->templateName = $templateName; |
| 79 | 79 | $this->appName = $appName; |
| 80 | 80 | $this->params = $params; |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | * @return TemplateResponse Reference to this object |
| 90 | 90 | * @since 6.0.0 - return value was added in 7.0.0 |
| 91 | 91 | */ |
| 92 | - public function setParams(array $params){ |
|
| 92 | + public function setParams(array $params) { |
|
| 93 | 93 | $this->params = $params; |
| 94 | 94 | |
| 95 | 95 | return $this; |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | * @return array the params |
| 102 | 102 | * @since 6.0.0 |
| 103 | 103 | */ |
| 104 | - public function getParams(){ |
|
| 104 | + public function getParams() { |
|
| 105 | 105 | return $this->params; |
| 106 | 106 | } |
| 107 | 107 | |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | * @return string the name of the used template |
| 112 | 112 | * @since 6.0.0 |
| 113 | 113 | */ |
| 114 | - public function getTemplateName(){ |
|
| 114 | + public function getTemplateName() { |
|
| 115 | 115 | return $this->templateName; |
| 116 | 116 | } |
| 117 | 117 | |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | * @return TemplateResponse Reference to this object |
| 126 | 126 | * @since 6.0.0 - return value was added in 7.0.0 |
| 127 | 127 | */ |
| 128 | - public function renderAs($renderAs){ |
|
| 128 | + public function renderAs($renderAs) { |
|
| 129 | 129 | $this->renderAs = $renderAs; |
| 130 | 130 | |
| 131 | 131 | return $this; |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | * @return string the renderAs value |
| 138 | 138 | * @since 6.0.0 |
| 139 | 139 | */ |
| 140 | - public function getRenderAs(){ |
|
| 140 | + public function getRenderAs() { |
|
| 141 | 141 | return $this->renderAs; |
| 142 | 142 | } |
| 143 | 143 | |
@@ -147,13 +147,13 @@ discard block |
||
| 147 | 147 | * @return string the rendered html |
| 148 | 148 | * @since 6.0.0 |
| 149 | 149 | */ |
| 150 | - public function render(){ |
|
| 150 | + public function render() { |
|
| 151 | 151 | // \OCP\Template needs an empty string instead of 'blank' for an unwrapped response |
| 152 | 152 | $renderAs = $this->renderAs === 'blank' ? '' : $this->renderAs; |
| 153 | 153 | |
| 154 | 154 | $template = new \OCP\Template($this->appName, $this->templateName, $renderAs); |
| 155 | 155 | |
| 156 | - foreach($this->params as $key => $value){ |
|
| 156 | + foreach ($this->params as $key => $value) { |
|
| 157 | 157 | $template->assign($key, $value); |
| 158 | 158 | } |
| 159 | 159 | |
@@ -68,343 +68,343 @@ |
||
| 68 | 68 | |
| 69 | 69 | class DIContainer extends SimpleContainer implements IAppContainer { |
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @var array |
|
| 73 | - */ |
|
| 74 | - private $middleWares = []; |
|
| 75 | - |
|
| 76 | - /** @var ServerContainer */ |
|
| 77 | - private $server; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Put your class dependencies in here |
|
| 81 | - * @param string $appName the name of the app |
|
| 82 | - * @param array $urlParams |
|
| 83 | - * @param ServerContainer|null $server |
|
| 84 | - */ |
|
| 85 | - public function __construct($appName, $urlParams = array(), ServerContainer $server = null){ |
|
| 86 | - parent::__construct(); |
|
| 87 | - $this['AppName'] = $appName; |
|
| 88 | - $this['urlParams'] = $urlParams; |
|
| 89 | - |
|
| 90 | - $this->registerAlias('Request', IRequest::class); |
|
| 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(){ |
|
| 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->registerService(IServerContainer::class, function () { |
|
| 129 | - return $this->getServer(); |
|
| 130 | - }); |
|
| 131 | - $this->registerAlias('ServerContainer', IServerContainer::class); |
|
| 132 | - |
|
| 133 | - $this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) { |
|
| 134 | - return $c->query(Manager::class); |
|
| 135 | - }); |
|
| 136 | - |
|
| 137 | - $this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) { |
|
| 138 | - return $c; |
|
| 139 | - }); |
|
| 140 | - |
|
| 141 | - // commonly used attributes |
|
| 142 | - $this->registerService('UserId', function ($c) { |
|
| 143 | - return $c->query(IUserSession::class)->getSession()->get('user_id'); |
|
| 144 | - }); |
|
| 145 | - |
|
| 146 | - $this->registerService('WebRoot', function ($c) { |
|
| 147 | - return $c->query('ServerContainer')->getWebRoot(); |
|
| 148 | - }); |
|
| 149 | - |
|
| 150 | - $this->registerService('OC_Defaults', function ($c) { |
|
| 151 | - return $c->getServer()->getThemingDefaults(); |
|
| 152 | - }); |
|
| 153 | - |
|
| 154 | - $this->registerService(IConfig::class, function ($c) { |
|
| 155 | - return $c->query(OC\GlobalScale\Config::class); |
|
| 156 | - }); |
|
| 157 | - |
|
| 158 | - $this->registerService('Protocol', function($c){ |
|
| 159 | - /** @var \OC\Server $server */ |
|
| 160 | - $server = $c->query('ServerContainer'); |
|
| 161 | - $protocol = $server->getRequest()->getHttpProtocol(); |
|
| 162 | - return new Http($_SERVER, $protocol); |
|
| 163 | - }); |
|
| 164 | - |
|
| 165 | - $this->registerService('Dispatcher', function($c) { |
|
| 166 | - return new Dispatcher( |
|
| 167 | - $c['Protocol'], |
|
| 168 | - $c['MiddlewareDispatcher'], |
|
| 169 | - $c->query(IControllerMethodReflector::class), |
|
| 170 | - $c['Request'] |
|
| 171 | - ); |
|
| 172 | - }); |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * App Framework default arguments |
|
| 176 | - */ |
|
| 177 | - $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH'); |
|
| 178 | - $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept'); |
|
| 179 | - $this->registerParameter('corsMaxAge', 1728000); |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Middleware |
|
| 183 | - */ |
|
| 184 | - $this->registerService('MiddlewareDispatcher', function(SimpleContainer $c) { |
|
| 185 | - $server = $this->getServer(); |
|
| 186 | - |
|
| 187 | - $dispatcher = new MiddlewareDispatcher(); |
|
| 188 | - $dispatcher->registerMiddleware( |
|
| 189 | - new OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware( |
|
| 190 | - $c->query(IRequest::class), |
|
| 191 | - $c->query(IControllerMethodReflector::class) |
|
| 192 | - ) |
|
| 193 | - ); |
|
| 194 | - $dispatcher->registerMiddleware( |
|
| 195 | - new CORSMiddleware( |
|
| 196 | - $c->query(IRequest::class), |
|
| 197 | - $c->query(IControllerMethodReflector::class), |
|
| 198 | - $c->query(IUserSession::class), |
|
| 199 | - $c->query(OC\Security\Bruteforce\Throttler::class) |
|
| 200 | - ) |
|
| 201 | - ); |
|
| 202 | - $dispatcher->registerMiddleware( |
|
| 203 | - new OCSMiddleware( |
|
| 204 | - $c->query(IRequest::class) |
|
| 205 | - ) |
|
| 206 | - ); |
|
| 207 | - |
|
| 208 | - $securityMiddleware = new SecurityMiddleware( |
|
| 209 | - $c->query(IRequest::class), |
|
| 210 | - $c->query(IControllerMethodReflector::class), |
|
| 211 | - $c->query(INavigationManager::class), |
|
| 212 | - $c->query(IURLGenerator::class), |
|
| 213 | - $server->getLogger(), |
|
| 214 | - $c['AppName'], |
|
| 215 | - $server->getUserSession()->isLoggedIn(), |
|
| 216 | - $server->getGroupManager()->isAdmin($this->getUserId()), |
|
| 217 | - $server->getContentSecurityPolicyManager(), |
|
| 218 | - $server->getCsrfTokenManager(), |
|
| 219 | - $server->getContentSecurityPolicyNonceManager(), |
|
| 220 | - $server->getAppManager(), |
|
| 221 | - $server->getL10N('lib') |
|
| 222 | - ); |
|
| 223 | - $dispatcher->registerMiddleware($securityMiddleware); |
|
| 224 | - $dispatcher->registerMiddleware( |
|
| 225 | - new OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware( |
|
| 226 | - $c->query(IControllerMethodReflector::class), |
|
| 227 | - $c->query(ISession::class), |
|
| 228 | - $c->query(IUserSession::class), |
|
| 229 | - $c->query(ITimeFactory::class) |
|
| 230 | - ) |
|
| 231 | - ); |
|
| 232 | - $dispatcher->registerMiddleware( |
|
| 233 | - new TwoFactorMiddleware( |
|
| 234 | - $c->query(OC\Authentication\TwoFactorAuth\Manager::class), |
|
| 235 | - $c->query(IUserSession::class), |
|
| 236 | - $c->query(ISession::class), |
|
| 237 | - $c->query(IURLGenerator::class), |
|
| 238 | - $c->query(IControllerMethodReflector::class), |
|
| 239 | - $c->query(IRequest::class) |
|
| 240 | - ) |
|
| 241 | - ); |
|
| 242 | - $dispatcher->registerMiddleware( |
|
| 243 | - new OC\AppFramework\Middleware\Security\BruteForceMiddleware( |
|
| 244 | - $c->query(IControllerMethodReflector::class), |
|
| 245 | - $c->query(OC\Security\Bruteforce\Throttler::class), |
|
| 246 | - $c->query(IRequest::class) |
|
| 247 | - ) |
|
| 248 | - ); |
|
| 249 | - $dispatcher->registerMiddleware( |
|
| 250 | - new RateLimitingMiddleware( |
|
| 251 | - $c->query(IRequest::class), |
|
| 252 | - $c->query(IUserSession::class), |
|
| 253 | - $c->query(IControllerMethodReflector::class), |
|
| 254 | - $c->query(OC\Security\RateLimiting\Limiter::class) |
|
| 255 | - ) |
|
| 256 | - ); |
|
| 257 | - $dispatcher->registerMiddleware( |
|
| 258 | - new OC\AppFramework\Middleware\PublicShare\PublicShareMiddleware( |
|
| 259 | - $c->query(IRequest::class), |
|
| 260 | - $c->query(ISession::class), |
|
| 261 | - $c->query(\OCP\IConfig::class) |
|
| 262 | - ) |
|
| 263 | - ); |
|
| 264 | - $dispatcher->registerMiddleware( |
|
| 265 | - $c->query(\OC\AppFramework\Middleware\AdditionalScriptsMiddleware::class) |
|
| 266 | - ); |
|
| 267 | - |
|
| 268 | - foreach($this->middleWares as $middleWare) { |
|
| 269 | - $dispatcher->registerMiddleware($c[$middleWare]); |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - $dispatcher->registerMiddleware( |
|
| 273 | - new SessionMiddleware( |
|
| 274 | - $c->query(IRequest::class), |
|
| 275 | - $c->query(IControllerMethodReflector::class), |
|
| 276 | - $c->query(ISession::class) |
|
| 277 | - ) |
|
| 278 | - ); |
|
| 279 | - return $dispatcher; |
|
| 280 | - }); |
|
| 281 | - |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * @return \OCP\IServerContainer |
|
| 286 | - */ |
|
| 287 | - public function getServer() |
|
| 288 | - { |
|
| 289 | - return $this->server; |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * @param string $middleWare |
|
| 294 | - * @return boolean|null |
|
| 295 | - */ |
|
| 296 | - public function registerMiddleWare($middleWare) { |
|
| 297 | - $this->middleWares[] = $middleWare; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * used to return the appname of the set application |
|
| 302 | - * @return string the name of your application |
|
| 303 | - */ |
|
| 304 | - public function getAppName() { |
|
| 305 | - return $this->query('AppName'); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * @deprecated use IUserSession->isLoggedIn() |
|
| 310 | - * @return boolean |
|
| 311 | - */ |
|
| 312 | - public function isLoggedIn() { |
|
| 313 | - return \OC::$server->getUserSession()->isLoggedIn(); |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * @deprecated use IGroupManager->isAdmin($userId) |
|
| 318 | - * @return boolean |
|
| 319 | - */ |
|
| 320 | - public function isAdminUser() { |
|
| 321 | - $uid = $this->getUserId(); |
|
| 322 | - return \OC_User::isAdminUser($uid); |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - private function getUserId() { |
|
| 326 | - return $this->getServer()->getSession()->get('user_id'); |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * @deprecated use the ILogger instead |
|
| 331 | - * @param string $message |
|
| 332 | - * @param string $level |
|
| 333 | - * @return mixed |
|
| 334 | - */ |
|
| 335 | - public function log($message, $level) { |
|
| 336 | - switch($level){ |
|
| 337 | - case 'debug': |
|
| 338 | - $level = ILogger::DEBUG; |
|
| 339 | - break; |
|
| 340 | - case 'info': |
|
| 341 | - $level = ILogger::INFO; |
|
| 342 | - break; |
|
| 343 | - case 'warn': |
|
| 344 | - $level = ILogger::WARN; |
|
| 345 | - break; |
|
| 346 | - case 'fatal': |
|
| 347 | - $level = ILogger::FATAL; |
|
| 348 | - break; |
|
| 349 | - default: |
|
| 350 | - $level = ILogger::ERROR; |
|
| 351 | - break; |
|
| 352 | - } |
|
| 353 | - \OCP\Util::writeLog($this->getAppName(), $message, $level); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * Register a capability |
|
| 358 | - * |
|
| 359 | - * @param string $serviceName e.g. 'OCA\Files\Capabilities' |
|
| 360 | - */ |
|
| 361 | - public function registerCapability($serviceName) { |
|
| 362 | - $this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) { |
|
| 363 | - return $this->query($serviceName); |
|
| 364 | - }); |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * @param string $name |
|
| 369 | - * @return mixed |
|
| 370 | - * @throws QueryException if the query could not be resolved |
|
| 371 | - */ |
|
| 372 | - public function query($name) { |
|
| 373 | - try { |
|
| 374 | - return $this->queryNoFallback($name); |
|
| 375 | - } catch (QueryException $firstException) { |
|
| 376 | - try { |
|
| 377 | - return $this->getServer()->query($name); |
|
| 378 | - } catch (QueryException $secondException) { |
|
| 379 | - if ($firstException->getCode() === 1) { |
|
| 380 | - throw $secondException; |
|
| 381 | - } |
|
| 382 | - throw $firstException; |
|
| 383 | - } |
|
| 384 | - } |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * @param string $name |
|
| 389 | - * @return mixed |
|
| 390 | - * @throws QueryException if the query could not be resolved |
|
| 391 | - */ |
|
| 392 | - public function queryNoFallback($name) { |
|
| 393 | - $name = $this->sanitizeName($name); |
|
| 394 | - |
|
| 395 | - if ($this->offsetExists($name)) { |
|
| 396 | - return parent::query($name); |
|
| 397 | - } else { |
|
| 398 | - if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) { |
|
| 399 | - return parent::query($name); |
|
| 400 | - } else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) { |
|
| 401 | - return parent::query($name); |
|
| 402 | - } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) { |
|
| 403 | - return parent::query($name); |
|
| 404 | - } |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - throw new QueryException('Could not resolve ' . $name . '!' . |
|
| 408 | - ' Class can not be instantiated', 1); |
|
| 409 | - } |
|
| 71 | + /** |
|
| 72 | + * @var array |
|
| 73 | + */ |
|
| 74 | + private $middleWares = []; |
|
| 75 | + |
|
| 76 | + /** @var ServerContainer */ |
|
| 77 | + private $server; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Put your class dependencies in here |
|
| 81 | + * @param string $appName the name of the app |
|
| 82 | + * @param array $urlParams |
|
| 83 | + * @param ServerContainer|null $server |
|
| 84 | + */ |
|
| 85 | + public function __construct($appName, $urlParams = array(), ServerContainer $server = null){ |
|
| 86 | + parent::__construct(); |
|
| 87 | + $this['AppName'] = $appName; |
|
| 88 | + $this['urlParams'] = $urlParams; |
|
| 89 | + |
|
| 90 | + $this->registerAlias('Request', IRequest::class); |
|
| 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(){ |
|
| 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->registerService(IServerContainer::class, function () { |
|
| 129 | + return $this->getServer(); |
|
| 130 | + }); |
|
| 131 | + $this->registerAlias('ServerContainer', IServerContainer::class); |
|
| 132 | + |
|
| 133 | + $this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) { |
|
| 134 | + return $c->query(Manager::class); |
|
| 135 | + }); |
|
| 136 | + |
|
| 137 | + $this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) { |
|
| 138 | + return $c; |
|
| 139 | + }); |
|
| 140 | + |
|
| 141 | + // commonly used attributes |
|
| 142 | + $this->registerService('UserId', function ($c) { |
|
| 143 | + return $c->query(IUserSession::class)->getSession()->get('user_id'); |
|
| 144 | + }); |
|
| 145 | + |
|
| 146 | + $this->registerService('WebRoot', function ($c) { |
|
| 147 | + return $c->query('ServerContainer')->getWebRoot(); |
|
| 148 | + }); |
|
| 149 | + |
|
| 150 | + $this->registerService('OC_Defaults', function ($c) { |
|
| 151 | + return $c->getServer()->getThemingDefaults(); |
|
| 152 | + }); |
|
| 153 | + |
|
| 154 | + $this->registerService(IConfig::class, function ($c) { |
|
| 155 | + return $c->query(OC\GlobalScale\Config::class); |
|
| 156 | + }); |
|
| 157 | + |
|
| 158 | + $this->registerService('Protocol', function($c){ |
|
| 159 | + /** @var \OC\Server $server */ |
|
| 160 | + $server = $c->query('ServerContainer'); |
|
| 161 | + $protocol = $server->getRequest()->getHttpProtocol(); |
|
| 162 | + return new Http($_SERVER, $protocol); |
|
| 163 | + }); |
|
| 164 | + |
|
| 165 | + $this->registerService('Dispatcher', function($c) { |
|
| 166 | + return new Dispatcher( |
|
| 167 | + $c['Protocol'], |
|
| 168 | + $c['MiddlewareDispatcher'], |
|
| 169 | + $c->query(IControllerMethodReflector::class), |
|
| 170 | + $c['Request'] |
|
| 171 | + ); |
|
| 172 | + }); |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * App Framework default arguments |
|
| 176 | + */ |
|
| 177 | + $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH'); |
|
| 178 | + $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept'); |
|
| 179 | + $this->registerParameter('corsMaxAge', 1728000); |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Middleware |
|
| 183 | + */ |
|
| 184 | + $this->registerService('MiddlewareDispatcher', function(SimpleContainer $c) { |
|
| 185 | + $server = $this->getServer(); |
|
| 186 | + |
|
| 187 | + $dispatcher = new MiddlewareDispatcher(); |
|
| 188 | + $dispatcher->registerMiddleware( |
|
| 189 | + new OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware( |
|
| 190 | + $c->query(IRequest::class), |
|
| 191 | + $c->query(IControllerMethodReflector::class) |
|
| 192 | + ) |
|
| 193 | + ); |
|
| 194 | + $dispatcher->registerMiddleware( |
|
| 195 | + new CORSMiddleware( |
|
| 196 | + $c->query(IRequest::class), |
|
| 197 | + $c->query(IControllerMethodReflector::class), |
|
| 198 | + $c->query(IUserSession::class), |
|
| 199 | + $c->query(OC\Security\Bruteforce\Throttler::class) |
|
| 200 | + ) |
|
| 201 | + ); |
|
| 202 | + $dispatcher->registerMiddleware( |
|
| 203 | + new OCSMiddleware( |
|
| 204 | + $c->query(IRequest::class) |
|
| 205 | + ) |
|
| 206 | + ); |
|
| 207 | + |
|
| 208 | + $securityMiddleware = new SecurityMiddleware( |
|
| 209 | + $c->query(IRequest::class), |
|
| 210 | + $c->query(IControllerMethodReflector::class), |
|
| 211 | + $c->query(INavigationManager::class), |
|
| 212 | + $c->query(IURLGenerator::class), |
|
| 213 | + $server->getLogger(), |
|
| 214 | + $c['AppName'], |
|
| 215 | + $server->getUserSession()->isLoggedIn(), |
|
| 216 | + $server->getGroupManager()->isAdmin($this->getUserId()), |
|
| 217 | + $server->getContentSecurityPolicyManager(), |
|
| 218 | + $server->getCsrfTokenManager(), |
|
| 219 | + $server->getContentSecurityPolicyNonceManager(), |
|
| 220 | + $server->getAppManager(), |
|
| 221 | + $server->getL10N('lib') |
|
| 222 | + ); |
|
| 223 | + $dispatcher->registerMiddleware($securityMiddleware); |
|
| 224 | + $dispatcher->registerMiddleware( |
|
| 225 | + new OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware( |
|
| 226 | + $c->query(IControllerMethodReflector::class), |
|
| 227 | + $c->query(ISession::class), |
|
| 228 | + $c->query(IUserSession::class), |
|
| 229 | + $c->query(ITimeFactory::class) |
|
| 230 | + ) |
|
| 231 | + ); |
|
| 232 | + $dispatcher->registerMiddleware( |
|
| 233 | + new TwoFactorMiddleware( |
|
| 234 | + $c->query(OC\Authentication\TwoFactorAuth\Manager::class), |
|
| 235 | + $c->query(IUserSession::class), |
|
| 236 | + $c->query(ISession::class), |
|
| 237 | + $c->query(IURLGenerator::class), |
|
| 238 | + $c->query(IControllerMethodReflector::class), |
|
| 239 | + $c->query(IRequest::class) |
|
| 240 | + ) |
|
| 241 | + ); |
|
| 242 | + $dispatcher->registerMiddleware( |
|
| 243 | + new OC\AppFramework\Middleware\Security\BruteForceMiddleware( |
|
| 244 | + $c->query(IControllerMethodReflector::class), |
|
| 245 | + $c->query(OC\Security\Bruteforce\Throttler::class), |
|
| 246 | + $c->query(IRequest::class) |
|
| 247 | + ) |
|
| 248 | + ); |
|
| 249 | + $dispatcher->registerMiddleware( |
|
| 250 | + new RateLimitingMiddleware( |
|
| 251 | + $c->query(IRequest::class), |
|
| 252 | + $c->query(IUserSession::class), |
|
| 253 | + $c->query(IControllerMethodReflector::class), |
|
| 254 | + $c->query(OC\Security\RateLimiting\Limiter::class) |
|
| 255 | + ) |
|
| 256 | + ); |
|
| 257 | + $dispatcher->registerMiddleware( |
|
| 258 | + new OC\AppFramework\Middleware\PublicShare\PublicShareMiddleware( |
|
| 259 | + $c->query(IRequest::class), |
|
| 260 | + $c->query(ISession::class), |
|
| 261 | + $c->query(\OCP\IConfig::class) |
|
| 262 | + ) |
|
| 263 | + ); |
|
| 264 | + $dispatcher->registerMiddleware( |
|
| 265 | + $c->query(\OC\AppFramework\Middleware\AdditionalScriptsMiddleware::class) |
|
| 266 | + ); |
|
| 267 | + |
|
| 268 | + foreach($this->middleWares as $middleWare) { |
|
| 269 | + $dispatcher->registerMiddleware($c[$middleWare]); |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + $dispatcher->registerMiddleware( |
|
| 273 | + new SessionMiddleware( |
|
| 274 | + $c->query(IRequest::class), |
|
| 275 | + $c->query(IControllerMethodReflector::class), |
|
| 276 | + $c->query(ISession::class) |
|
| 277 | + ) |
|
| 278 | + ); |
|
| 279 | + return $dispatcher; |
|
| 280 | + }); |
|
| 281 | + |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * @return \OCP\IServerContainer |
|
| 286 | + */ |
|
| 287 | + public function getServer() |
|
| 288 | + { |
|
| 289 | + return $this->server; |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * @param string $middleWare |
|
| 294 | + * @return boolean|null |
|
| 295 | + */ |
|
| 296 | + public function registerMiddleWare($middleWare) { |
|
| 297 | + $this->middleWares[] = $middleWare; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * used to return the appname of the set application |
|
| 302 | + * @return string the name of your application |
|
| 303 | + */ |
|
| 304 | + public function getAppName() { |
|
| 305 | + return $this->query('AppName'); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * @deprecated use IUserSession->isLoggedIn() |
|
| 310 | + * @return boolean |
|
| 311 | + */ |
|
| 312 | + public function isLoggedIn() { |
|
| 313 | + return \OC::$server->getUserSession()->isLoggedIn(); |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * @deprecated use IGroupManager->isAdmin($userId) |
|
| 318 | + * @return boolean |
|
| 319 | + */ |
|
| 320 | + public function isAdminUser() { |
|
| 321 | + $uid = $this->getUserId(); |
|
| 322 | + return \OC_User::isAdminUser($uid); |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + private function getUserId() { |
|
| 326 | + return $this->getServer()->getSession()->get('user_id'); |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * @deprecated use the ILogger instead |
|
| 331 | + * @param string $message |
|
| 332 | + * @param string $level |
|
| 333 | + * @return mixed |
|
| 334 | + */ |
|
| 335 | + public function log($message, $level) { |
|
| 336 | + switch($level){ |
|
| 337 | + case 'debug': |
|
| 338 | + $level = ILogger::DEBUG; |
|
| 339 | + break; |
|
| 340 | + case 'info': |
|
| 341 | + $level = ILogger::INFO; |
|
| 342 | + break; |
|
| 343 | + case 'warn': |
|
| 344 | + $level = ILogger::WARN; |
|
| 345 | + break; |
|
| 346 | + case 'fatal': |
|
| 347 | + $level = ILogger::FATAL; |
|
| 348 | + break; |
|
| 349 | + default: |
|
| 350 | + $level = ILogger::ERROR; |
|
| 351 | + break; |
|
| 352 | + } |
|
| 353 | + \OCP\Util::writeLog($this->getAppName(), $message, $level); |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * Register a capability |
|
| 358 | + * |
|
| 359 | + * @param string $serviceName e.g. 'OCA\Files\Capabilities' |
|
| 360 | + */ |
|
| 361 | + public function registerCapability($serviceName) { |
|
| 362 | + $this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) { |
|
| 363 | + return $this->query($serviceName); |
|
| 364 | + }); |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * @param string $name |
|
| 369 | + * @return mixed |
|
| 370 | + * @throws QueryException if the query could not be resolved |
|
| 371 | + */ |
|
| 372 | + public function query($name) { |
|
| 373 | + try { |
|
| 374 | + return $this->queryNoFallback($name); |
|
| 375 | + } catch (QueryException $firstException) { |
|
| 376 | + try { |
|
| 377 | + return $this->getServer()->query($name); |
|
| 378 | + } catch (QueryException $secondException) { |
|
| 379 | + if ($firstException->getCode() === 1) { |
|
| 380 | + throw $secondException; |
|
| 381 | + } |
|
| 382 | + throw $firstException; |
|
| 383 | + } |
|
| 384 | + } |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * @param string $name |
|
| 389 | + * @return mixed |
|
| 390 | + * @throws QueryException if the query could not be resolved |
|
| 391 | + */ |
|
| 392 | + public function queryNoFallback($name) { |
|
| 393 | + $name = $this->sanitizeName($name); |
|
| 394 | + |
|
| 395 | + if ($this->offsetExists($name)) { |
|
| 396 | + return parent::query($name); |
|
| 397 | + } else { |
|
| 398 | + if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) { |
|
| 399 | + return parent::query($name); |
|
| 400 | + } else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) { |
|
| 401 | + return parent::query($name); |
|
| 402 | + } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) { |
|
| 403 | + return parent::query($name); |
|
| 404 | + } |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + throw new QueryException('Could not resolve ' . $name . '!' . |
|
| 408 | + ' Class can not be instantiated', 1); |
|
| 409 | + } |
|
| 410 | 410 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | * @param array $urlParams |
| 83 | 83 | * @param ServerContainer|null $server |
| 84 | 84 | */ |
| 85 | - public function __construct($appName, $urlParams = array(), ServerContainer $server = null){ |
|
| 85 | + public function __construct($appName, $urlParams = array(), ServerContainer $server = null) { |
|
| 86 | 86 | parent::__construct(); |
| 87 | 87 | $this['AppName'] = $appName; |
| 88 | 88 | $this['urlParams'] = $urlParams; |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | /** |
| 105 | 105 | * Core services |
| 106 | 106 | */ |
| 107 | - $this->registerService(IOutput::class, function(){ |
|
| 107 | + $this->registerService(IOutput::class, function() { |
|
| 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,41 +121,41 @@ 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 | |
| 128 | - $this->registerService(IServerContainer::class, function () { |
|
| 128 | + $this->registerService(IServerContainer::class, function() { |
|
| 129 | 129 | return $this->getServer(); |
| 130 | 130 | }); |
| 131 | 131 | $this->registerAlias('ServerContainer', IServerContainer::class); |
| 132 | 132 | |
| 133 | - $this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) { |
|
| 133 | + $this->registerService(\OCP\WorkflowEngine\IManager::class, function($c) { |
|
| 134 | 134 | return $c->query(Manager::class); |
| 135 | 135 | }); |
| 136 | 136 | |
| 137 | - $this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) { |
|
| 137 | + $this->registerService(\OCP\AppFramework\IAppContainer::class, function($c) { |
|
| 138 | 138 | return $c; |
| 139 | 139 | }); |
| 140 | 140 | |
| 141 | 141 | // commonly used attributes |
| 142 | - $this->registerService('UserId', function ($c) { |
|
| 142 | + $this->registerService('UserId', function($c) { |
|
| 143 | 143 | return $c->query(IUserSession::class)->getSession()->get('user_id'); |
| 144 | 144 | }); |
| 145 | 145 | |
| 146 | - $this->registerService('WebRoot', function ($c) { |
|
| 146 | + $this->registerService('WebRoot', function($c) { |
|
| 147 | 147 | return $c->query('ServerContainer')->getWebRoot(); |
| 148 | 148 | }); |
| 149 | 149 | |
| 150 | - $this->registerService('OC_Defaults', function ($c) { |
|
| 150 | + $this->registerService('OC_Defaults', function($c) { |
|
| 151 | 151 | return $c->getServer()->getThemingDefaults(); |
| 152 | 152 | }); |
| 153 | 153 | |
| 154 | - $this->registerService(IConfig::class, function ($c) { |
|
| 154 | + $this->registerService(IConfig::class, function($c) { |
|
| 155 | 155 | return $c->query(OC\GlobalScale\Config::class); |
| 156 | 156 | }); |
| 157 | 157 | |
| 158 | - $this->registerService('Protocol', function($c){ |
|
| 158 | + $this->registerService('Protocol', function($c) { |
|
| 159 | 159 | /** @var \OC\Server $server */ |
| 160 | 160 | $server = $c->query('ServerContainer'); |
| 161 | 161 | $protocol = $server->getRequest()->getHttpProtocol(); |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | * Middleware |
| 183 | 183 | */ |
| 184 | 184 | $this->registerService('MiddlewareDispatcher', function(SimpleContainer $c) { |
| 185 | - $server = $this->getServer(); |
|
| 185 | + $server = $this->getServer(); |
|
| 186 | 186 | |
| 187 | 187 | $dispatcher = new MiddlewareDispatcher(); |
| 188 | 188 | $dispatcher->registerMiddleware( |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | $c->query(\OC\AppFramework\Middleware\AdditionalScriptsMiddleware::class) |
| 266 | 266 | ); |
| 267 | 267 | |
| 268 | - foreach($this->middleWares as $middleWare) { |
|
| 268 | + foreach ($this->middleWares as $middleWare) { |
|
| 269 | 269 | $dispatcher->registerMiddleware($c[$middleWare]); |
| 270 | 270 | } |
| 271 | 271 | |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | * @return mixed |
| 334 | 334 | */ |
| 335 | 335 | public function log($message, $level) { |
| 336 | - switch($level){ |
|
| 336 | + switch ($level) { |
|
| 337 | 337 | case 'debug': |
| 338 | 338 | $level = ILogger::DEBUG; |
| 339 | 339 | break; |
@@ -399,12 +399,12 @@ discard block |
||
| 399 | 399 | return parent::query($name); |
| 400 | 400 | } else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) { |
| 401 | 401 | return parent::query($name); |
| 402 | - } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) { |
|
| 402 | + } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']).'\\') === 0) { |
|
| 403 | 403 | return parent::query($name); |
| 404 | 404 | } |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | - throw new QueryException('Could not resolve ' . $name . '!' . |
|
| 407 | + throw new QueryException('Could not resolve '.$name.'!'. |
|
| 408 | 408 | ' Class can not be instantiated', 1); |
| 409 | 409 | } |
| 410 | 410 | } |
@@ -31,26 +31,26 @@ |
||
| 31 | 31 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
| 32 | 32 | |
| 33 | 33 | class AdditionalScriptsMiddleware extends Middleware { |
| 34 | - /** @var EventDispatcherInterface */ |
|
| 35 | - private $dispatcher; |
|
| 36 | - /** @var IUserSession */ |
|
| 37 | - private $userSession; |
|
| 38 | - |
|
| 39 | - public function __construct(EventDispatcherInterface $dispatcher, IUserSession $userSession) { |
|
| 40 | - $this->dispatcher = $dispatcher; |
|
| 41 | - $this->userSession = $userSession; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - public function afterController($controller, $methodName, Response $response): Response { |
|
| 45 | - if ($response instanceof TemplateResponse) { |
|
| 46 | - $this->dispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS); |
|
| 47 | - |
|
| 48 | - if ($this->userSession->isLoggedIn()) { |
|
| 49 | - $this->dispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN); |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - return $response; |
|
| 54 | - } |
|
| 34 | + /** @var EventDispatcherInterface */ |
|
| 35 | + private $dispatcher; |
|
| 36 | + /** @var IUserSession */ |
|
| 37 | + private $userSession; |
|
| 38 | + |
|
| 39 | + public function __construct(EventDispatcherInterface $dispatcher, IUserSession $userSession) { |
|
| 40 | + $this->dispatcher = $dispatcher; |
|
| 41 | + $this->userSession = $userSession; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + public function afterController($controller, $methodName, Response $response): Response { |
|
| 45 | + if ($response instanceof TemplateResponse) { |
|
| 46 | + $this->dispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS); |
|
| 47 | + |
|
| 48 | + if ($this->userSession->isLoggedIn()) { |
|
| 49 | + $this->dispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN); |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + return $response; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | 56 | } |