appName = $appName; $this['appName'] = $appName; $this['urlParams'] = $urlParams; $this->registerAlias('Request', IRequest::class); /** @var \OC\ServerContainer $server */ if ($server === null) { $server = \OC::$server; } $this->server = $server; $this->server->registerAppContainer($appName, $this); // aliases /** @deprecated inject $appName */ $this->registerAlias('AppName', 'appName'); /** @deprecated inject $webRoot*/ $this->registerAlias('WebRoot', 'webRoot'); /** @deprecated inject $userId */ $this->registerAlias('UserId', 'userId'); /** * Core services */ $this->registerService(IOutput::class, function () { return new Output($this->getServer()->getWebRoot()); }); $this->registerService(Folder::class, function () { return $this->getServer()->getUserFolder(); }); $this->registerService(IAppData::class, function (ContainerInterface $c) { return $this->getServer()->getAppDataDir($c->get('AppName')); }); $this->registerService(IL10N::class, function (ContainerInterface $c) { return $this->getServer()->getL10N($c->get('AppName')); }); // Log wrappers $this->registerService(LoggerInterface::class, function (ContainerInterface $c) { return new ScopedPsrLogger( $c->get(PsrLoggerAdapter::class), $c->get('AppName') ); }); $this->registerService(ILogger::class, function (ContainerInterface $c) { return new OC\AppFramework\Logger($this->server->query(ILogger::class), $c->get('AppName')); }); $this->registerService(IServerContainer::class, function () { return $this->getServer(); }); $this->registerAlias('ServerContainer', IServerContainer::class); $this->registerService(\OCP\WorkflowEngine\IManager::class, function (ContainerInterface $c) { return $c->get(Manager::class); }); $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { return $c; }); $this->registerAlias(IAppContainer::class, ContainerInterface::class); // commonly used attributes $this->registerService('userId', function (ContainerInterface $c) { return $c->get(IUserSession::class)->getSession()->get('user_id'); }); $this->registerService('webRoot', function (ContainerInterface $c) { return $c->get(IServerContainer::class)->getWebRoot(); }); $this->registerService('OC_Defaults', function (ContainerInterface $c) { return $c->get(IServerContainer::class)->get('ThemingDefaults'); }); $this->registerService('Protocol', function (ContainerInterface $c) { /** @var \OC\Server $server */ $server = $c->get(IServerContainer::class); $protocol = $server->getRequest()->getHttpProtocol(); return new Http($_SERVER, $protocol); }); $this->registerService('Dispatcher', function (ContainerInterface $c) { return new Dispatcher( $c->get('Protocol'), $c->get(MiddlewareDispatcher::class), $c->get(IControllerMethodReflector::class), $c->get(IRequest::class), $c->get(IConfig::class), $c->get(IDBConnection::class), $c->get(LoggerInterface::class), $c->get(EventLogger::class), $c, ); }); /** * App Framework default arguments */ $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH'); $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept'); $this->registerParameter('corsMaxAge', 1728000); /** * Middleware */ $this->registerAlias('MiddlewareDispatcher', MiddlewareDispatcher::class); $this->registerService(MiddlewareDispatcher::class, function (ContainerInterface $c) { $server = $this->getServer(); $dispatcher = new MiddlewareDispatcher(); $dispatcher->registerMiddleware( $c->get(OC\AppFramework\Middleware\CompressionMiddleware::class) ); $dispatcher->registerMiddleware($c->get(OC\AppFramework\Middleware\NotModifiedMiddleware::class)); $dispatcher->registerMiddleware( $c->get(OC\AppFramework\Middleware\Security\ReloadExecutionMiddleware::class) ); $dispatcher->registerMiddleware( new OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware( $c->get(IRequest::class), $c->get(IControllerMethodReflector::class) ) ); $dispatcher->registerMiddleware( new CORSMiddleware( $c->get(IRequest::class), $c->get(IControllerMethodReflector::class), $c->get(IUserSession::class), $c->get(IThrottler::class), $c->get(LoggerInterface::class) ) ); $dispatcher->registerMiddleware( new OCSMiddleware( $c->get(IRequest::class) ) ); $securityMiddleware = new SecurityMiddleware( $c->get(IRequest::class), $c->get(IControllerMethodReflector::class), $c->get(INavigationManager::class), $c->get(IURLGenerator::class), $server->get(LoggerInterface::class), $c->get('AppName'), $server->getUserSession()->isLoggedIn(), $c->get(IGroupManager::class), $c->get(ISubAdmin::class), $server->getAppManager(), $server->getL10N('lib'), $c->get(AuthorizedGroupMapper::class), $server->get(IUserSession::class), $c->get(IRemoteAddress::class), ); $dispatcher->registerMiddleware($securityMiddleware); $dispatcher->registerMiddleware( new OC\AppFramework\Middleware\Security\CSPMiddleware( $server->query(OC\Security\CSP\ContentSecurityPolicyManager::class), $server->query(OC\Security\CSP\ContentSecurityPolicyNonceManager::class), ) ); $dispatcher->registerMiddleware( $server->query(OC\AppFramework\Middleware\Security\FeaturePolicyMiddleware::class) ); $dispatcher->registerMiddleware( new OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware( $c->get(IControllerMethodReflector::class), $c->get(ISession::class), $c->get(IUserSession::class), $c->get(ITimeFactory::class), $c->get(\OC\Authentication\Token\IProvider::class), $c->get(LoggerInterface::class), ) ); $dispatcher->registerMiddleware( new TwoFactorMiddleware( $c->get(OC\Authentication\TwoFactorAuth\Manager::class), $c->get(IUserSession::class), $c->get(ISession::class), $c->get(IURLGenerator::class), $c->get(IControllerMethodReflector::class), $c->get(IRequest::class) ) ); $dispatcher->registerMiddleware( new OC\AppFramework\Middleware\Security\BruteForceMiddleware( $c->get(IControllerMethodReflector::class), $c->get(IThrottler::class), $c->get(IRequest::class), $c->get(LoggerInterface::class) ) ); $dispatcher->registerMiddleware( new RateLimitingMiddleware( $c->get(IRequest::class), $c->get(IUserSession::class), $c->get(IControllerMethodReflector::class), $c->get(OC\Security\RateLimiting\Limiter::class), $c->get(ISession::class) ) ); $dispatcher->registerMiddleware( new OC\AppFramework\Middleware\PublicShare\PublicShareMiddleware( $c->get(IRequest::class), $c->get(ISession::class), $c->get(IConfig::class), $c->get(IThrottler::class) ) ); $dispatcher->registerMiddleware( $c->get(\OC\AppFramework\Middleware\AdditionalScriptsMiddleware::class) ); /** @var \OC\AppFramework\Bootstrap\Coordinator $coordinator */ $coordinator = $c->get(\OC\AppFramework\Bootstrap\Coordinator::class); $registrationContext = $coordinator->getRegistrationContext(); if ($registrationContext !== null) { $appId = $this->getAppName(); foreach ($registrationContext->getMiddlewareRegistrations() as $middlewareRegistration) { if ($middlewareRegistration->getAppId() === $appId || $middlewareRegistration->isGlobal()) { $dispatcher->registerMiddleware($c->get($middlewareRegistration->getService())); } } } foreach ($this->middleWares as $middleWare) { $dispatcher->registerMiddleware($c->get($middleWare)); } $dispatcher->registerMiddleware( new SessionMiddleware( $c->get(IControllerMethodReflector::class), $c->get(ISession::class) ) ); return $dispatcher; }); $this->registerService(IAppConfig::class, function (ContainerInterface $c) { return new OC\AppFramework\Services\AppConfig( $c->get(IConfig::class), $c->get(\OCP\IAppConfig::class), $c->get('AppName') ); }); $this->registerService(IInitialState::class, function (ContainerInterface $c) { return new OC\AppFramework\Services\InitialState( $c->get(IInitialStateService::class), $c->get('AppName') ); }); } /** * @return \OCP\IServerContainer */ public function getServer() { return $this->server; } /** * @param string $middleWare * @return boolean|null */ public function registerMiddleWare($middleWare) { if (in_array($middleWare, $this->middleWares, true) !== false) { return false; } $this->middleWares[] = $middleWare; } /** * used to return the appname of the set application * @return string the name of your application */ public function getAppName() { return $this->query('AppName'); } /** * @deprecated use IUserSession->isLoggedIn() * @return boolean */ public function isLoggedIn() { return \OC::$server->getUserSession()->isLoggedIn(); } /** * @deprecated use IGroupManager->isAdmin($userId) * @return boolean */ public function isAdminUser() { $uid = $this->getUserId(); return \OC_User::isAdminUser($uid); } private function getUserId() { return $this->getServer()->getSession()->get('user_id'); } /** * Register a capability * * @param string $serviceName e.g. 'OCA\Files\Capabilities' */ public function registerCapability($serviceName) { $this->query('OC\CapabilitiesManager')->registerCapability(function () use ($serviceName) { return $this->query($serviceName); }); } public function has($id): bool { if (parent::has($id)) { return true; } if ($this->server->has($id, true)) { return true; } return false; } public function query(string $name, bool $autoload = true) { if ($name === 'AppName' || $name === 'appName') { return $this->appName; } $isServerClass = str_starts_with($name, 'OCP\\') || str_starts_with($name, 'OC\\'); if ($isServerClass && !$this->has($name)) { return $this->getServer()->query($name, $autoload); } try { return $this->queryNoFallback($name); } catch (QueryException $firstException) { try { return $this->getServer()->query($name, $autoload); } catch (QueryException $secondException) { if ($firstException->getCode() === 1) { throw $secondException; } throw $firstException; } } } /** * @param string $name * @return mixed * @throws QueryException if the query could not be resolved */ public function queryNoFallback($name) { $name = $this->sanitizeName($name); if ($this->offsetExists($name)) { return parent::query($name); } elseif ($this->appName === 'settings' && str_starts_with($name, 'OC\\Settings\\')) { return parent::query($name); } elseif ($this->appName === 'core' && str_starts_with($name, 'OC\\Core\\')) { return parent::query($name); } elseif (str_starts_with($name, \OC\AppFramework\App::buildAppNamespace($this->appName) . '\\')) { return parent::query($name); } throw new QueryException('Could not resolve ' . $name . '!' . ' Class can not be instantiated', 1); } } stable28-fix-npm-audit Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Files/SimpleFS/NewSimpleFile.php
blob: d0986592c0349874f7d10d0c9b2abfccd714cd58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211