You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Server.php 73KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. * @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch>
  5. *
  6. * @author Arne Hamann <kontakt+github@arne.email>
  7. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  8. * @author Bart Visscher <bartv@thisnet.nl>
  9. * @author Bernhard Posselt <dev@bernhard-posselt.com>
  10. * @author Bernhard Reiter <ockham@raz.or.at>
  11. * @author Bjoern Schiessle <bjoern@schiessle.org>
  12. * @author Björn Schießle <bjoern@schiessle.org>
  13. * @author Christopher Schäpers <kondou@ts.unde.re>
  14. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  15. * @author Damjan Georgievski <gdamjan@gmail.com>
  16. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  17. * @author Georg Ehrke <oc.list@georgehrke.com>
  18. * @author Joas Schilling <coding@schilljs.com>
  19. * @author John Molakvoæ <skjnldsv@protonmail.com>
  20. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  21. * @author Julius Haertl <jus@bitgrid.net>
  22. * @author Julius Härtl <jus@bitgrid.net>
  23. * @author Lionel Elie Mamane <lionel@mamane.lu>
  24. * @author Lukas Reschke <lukas@statuscode.ch>
  25. * @author Maxence Lange <maxence@artificial-owl.com>
  26. * @author Michael Weimann <mail@michael-weimann.eu>
  27. * @author Morris Jobke <hey@morrisjobke.de>
  28. * @author Piotr Mrówczyński <mrow4a@yahoo.com>
  29. * @author Robin Appelman <robin@icewind.nl>
  30. * @author Robin McCorkell <robin@mccorkell.me.uk>
  31. * @author Roeland Jago Douma <roeland@famdouma.nl>
  32. * @author root <root@localhost.localdomain>
  33. * @author Thomas Müller <thomas.mueller@tmit.eu>
  34. * @author Thomas Tanghus <thomas@tanghus.net>
  35. * @author Tobia De Koninck <tobia@ledfan.be>
  36. * @author Vincent Petry <vincent@nextcloud.com>
  37. *
  38. * @license AGPL-3.0
  39. *
  40. * This code is free software: you can redistribute it and/or modify
  41. * it under the terms of the GNU Affero General Public License, version 3,
  42. * as published by the Free Software Foundation.
  43. *
  44. * This program is distributed in the hope that it will be useful,
  45. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  46. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  47. * GNU Affero General Public License for more details.
  48. *
  49. * You should have received a copy of the GNU Affero General Public License, version 3,
  50. * along with this program. If not, see <http://www.gnu.org/licenses/>
  51. *
  52. */
  53. namespace OC;
  54. use bantu\IniGetWrapper\IniGetWrapper;
  55. use OC\Accounts\AccountManager;
  56. use OC\App\AppManager;
  57. use OC\App\AppStore\Bundles\BundleFetcher;
  58. use OC\App\AppStore\Fetcher\AppFetcher;
  59. use OC\App\AppStore\Fetcher\CategoryFetcher;
  60. use OC\AppFramework\Bootstrap\Coordinator;
  61. use OC\AppFramework\Http\Request;
  62. use OC\AppFramework\Utility\TimeFactory;
  63. use OC\Authentication\Events\LoginFailed;
  64. use OC\Authentication\Listeners\LoginFailedListener;
  65. use OC\Authentication\Listeners\UserLoggedInListener;
  66. use OC\Authentication\LoginCredentials\Store;
  67. use OC\Authentication\Token\IProvider;
  68. use OC\Avatar\AvatarManager;
  69. use OC\Collaboration\Collaborators\GroupPlugin;
  70. use OC\Collaboration\Collaborators\MailPlugin;
  71. use OC\Collaboration\Collaborators\RemoteGroupPlugin;
  72. use OC\Collaboration\Collaborators\RemotePlugin;
  73. use OC\Collaboration\Collaborators\UserPlugin;
  74. use OC\Command\CronBus;
  75. use OC\Comments\ManagerFactory as CommentsManagerFactory;
  76. use OC\Contacts\ContactsMenu\ActionFactory;
  77. use OC\Contacts\ContactsMenu\ContactsStore;
  78. use OC\Dashboard\DashboardManager;
  79. use OC\DB\Connection;
  80. use OC\DB\ConnectionAdapter;
  81. use OC\Diagnostics\EventLogger;
  82. use OC\Diagnostics\QueryLogger;
  83. use OC\EventDispatcher\SymfonyAdapter;
  84. use OC\Federation\CloudFederationFactory;
  85. use OC\Federation\CloudFederationProviderManager;
  86. use OC\Federation\CloudIdManager;
  87. use OC\Files\Config\UserMountCache;
  88. use OC\Files\Config\UserMountCacheListener;
  89. use OC\Files\Mount\CacheMountProvider;
  90. use OC\Files\Mount\LocalHomeMountProvider;
  91. use OC\Files\Mount\ObjectHomeMountProvider;
  92. use OC\Files\Mount\ObjectStorePreviewCacheMountProvider;
  93. use OC\Files\Node\HookConnector;
  94. use OC\Files\Node\LazyRoot;
  95. use OC\Files\Node\Root;
  96. use OC\Files\Storage\StorageFactory;
  97. use OC\Files\Template\TemplateManager;
  98. use OC\Files\Type\Loader;
  99. use OC\Files\View;
  100. use OC\FullTextSearch\FullTextSearchManager;
  101. use OC\Http\Client\ClientService;
  102. use OC\Http\Client\DnsPinMiddleware;
  103. use OC\Http\Client\LocalAddressChecker;
  104. use OC\Http\Client\NegativeDnsCache;
  105. use OC\IntegrityCheck\Checker;
  106. use OC\IntegrityCheck\Helpers\AppLocator;
  107. use OC\IntegrityCheck\Helpers\EnvironmentHelper;
  108. use OC\IntegrityCheck\Helpers\FileAccessHelper;
  109. use OC\LDAP\NullLDAPProviderFactory;
  110. use OC\KnownUser\KnownUserService;
  111. use OC\Lock\DBLockingProvider;
  112. use OC\Lock\MemcacheLockingProvider;
  113. use OC\Lock\NoopLockingProvider;
  114. use OC\Lockdown\LockdownManager;
  115. use OC\Log\LogFactory;
  116. use OC\Log\PsrLoggerAdapter;
  117. use OC\Mail\Mailer;
  118. use OC\Memcache\ArrayCache;
  119. use OC\Memcache\Factory;
  120. use OC\Notification\Manager;
  121. use OC\OCS\DiscoveryService;
  122. use OC\Preview\GeneratorHelper;
  123. use OC\Remote\Api\ApiFactory;
  124. use OC\Remote\InstanceFactory;
  125. use OC\RichObjectStrings\Validator;
  126. use OC\Route\Router;
  127. use OC\Security\Bruteforce\Throttler;
  128. use OC\Security\CertificateManager;
  129. use OC\Security\CredentialsManager;
  130. use OC\Security\Crypto;
  131. use OC\Security\CSP\ContentSecurityPolicyManager;
  132. use OC\Security\CSP\ContentSecurityPolicyNonceManager;
  133. use OC\Security\CSRF\CsrfTokenManager;
  134. use OC\Security\CSRF\TokenStorage\SessionStorage;
  135. use OC\Security\Hasher;
  136. use OC\Security\SecureRandom;
  137. use OC\Security\TrustedDomainHelper;
  138. use OC\Security\VerificationToken\VerificationToken;
  139. use OC\Session\CryptoWrapper;
  140. use OC\Share20\ProviderFactory;
  141. use OC\Share20\ShareHelper;
  142. use OC\SystemTag\ManagerFactory as SystemTagManagerFactory;
  143. use OC\Tagging\TagMapper;
  144. use OC\Template\JSCombiner;
  145. use OCA\Theming\ImageManager;
  146. use OCA\Theming\ThemingDefaults;
  147. use OCA\Theming\Util;
  148. use OCA\WorkflowEngine\Service\Logger;
  149. use OCP\Accounts\IAccountManager;
  150. use OCP\App\IAppManager;
  151. use OCP\Authentication\LoginCredentials\IStore;
  152. use OCP\BackgroundJob\IJobList;
  153. use OCP\Collaboration\AutoComplete\IManager;
  154. use OCP\Command\IBus;
  155. use OCP\Comments\ICommentsManager;
  156. use OCP\Contacts\ContactsMenu\IActionFactory;
  157. use OCP\Contacts\ContactsMenu\IContactsStore;
  158. use OCP\Dashboard\IDashboardManager;
  159. use OCP\Defaults;
  160. use OCP\Diagnostics\IEventLogger;
  161. use OCP\Diagnostics\IQueryLogger;
  162. use OCP\Encryption\IFile;
  163. use OCP\Encryption\Keys\IStorage;
  164. use OCP\EventDispatcher\IEventDispatcher;
  165. use OCP\Federation\ICloudFederationFactory;
  166. use OCP\Federation\ICloudFederationProviderManager;
  167. use OCP\Federation\ICloudIdManager;
  168. use OCP\Files\Config\IMountProviderCollection;
  169. use OCP\Files\Config\IUserMountCache;
  170. use OCP\Files\IMimeTypeDetector;
  171. use OCP\Files\IMimeTypeLoader;
  172. use OCP\Files\IRootFolder;
  173. use OCP\Files\Mount\IMountManager;
  174. use OCP\Files\NotFoundException;
  175. use OCP\Files\Storage\IStorageFactory;
  176. use OCP\Files\Template\ITemplateManager;
  177. use OCP\FullTextSearch\IFullTextSearchManager;
  178. use OCP\GlobalScale\IConfig;
  179. use OCP\Group\Events\BeforeGroupCreatedEvent;
  180. use OCP\Group\Events\BeforeGroupDeletedEvent;
  181. use OCP\Group\Events\BeforeUserAddedEvent;
  182. use OCP\Group\Events\BeforeUserRemovedEvent;
  183. use OCP\Group\Events\GroupCreatedEvent;
  184. use OCP\Group\Events\GroupDeletedEvent;
  185. use OCP\Group\Events\UserAddedEvent;
  186. use OCP\Group\Events\UserRemovedEvent;
  187. use OCP\Group\ISubAdmin;
  188. use OCP\Http\Client\IClientService;
  189. use OCP\IAppConfig;
  190. use OCP\IAvatarManager;
  191. use OCP\ICache;
  192. use OCP\ICacheFactory;
  193. use OCP\ICertificateManager;
  194. use OCP\IDateTimeFormatter;
  195. use OCP\IDateTimeZone;
  196. use OCP\IDBConnection;
  197. use OCP\IGroupManager;
  198. use OCP\IInitialStateService;
  199. use OCP\IL10N;
  200. use OCP\ILogger;
  201. use OCP\INavigationManager;
  202. use OCP\IPreview;
  203. use OCP\IRequest;
  204. use OCP\ISearch;
  205. use OCP\IServerContainer;
  206. use OCP\ISession;
  207. use OCP\ITagManager;
  208. use OCP\ITempManager;
  209. use OCP\IURLGenerator;
  210. use OCP\IUser;
  211. use OCP\IUserManager;
  212. use OCP\IUserSession;
  213. use OCP\L10N\IFactory;
  214. use OCP\LDAP\ILDAPProvider;
  215. use OCP\LDAP\ILDAPProviderFactory;
  216. use OCP\Lock\ILockingProvider;
  217. use OCP\Log\ILogFactory;
  218. use OCP\Mail\IMailer;
  219. use OCP\Remote\Api\IApiFactory;
  220. use OCP\Remote\IInstanceFactory;
  221. use OCP\RichObjectStrings\IValidator;
  222. use OCP\Route\IRouter;
  223. use OCP\Security\IContentSecurityPolicyManager;
  224. use OCP\Security\ICredentialsManager;
  225. use OCP\Security\ICrypto;
  226. use OCP\Security\IHasher;
  227. use OCP\Security\ISecureRandom;
  228. use OCP\Security\ITrustedDomainHelper;
  229. use OCP\Security\VerificationToken\IVerificationToken;
  230. use OCP\Share\IShareHelper;
  231. use OCP\SystemTag\ISystemTagManager;
  232. use OCP\SystemTag\ISystemTagObjectMapper;
  233. use OCP\User\Events\BeforePasswordUpdatedEvent;
  234. use OCP\User\Events\BeforeUserCreatedEvent;
  235. use OCP\User\Events\BeforeUserDeletedEvent;
  236. use OCP\User\Events\BeforeUserLoggedInEvent;
  237. use OCP\User\Events\BeforeUserLoggedInWithCookieEvent;
  238. use OCP\User\Events\BeforeUserLoggedOutEvent;
  239. use OCP\User\Events\PasswordUpdatedEvent;
  240. use OCP\User\Events\PostLoginEvent;
  241. use OCP\User\Events\UserChangedEvent;
  242. use OCP\User\Events\UserDeletedEvent;
  243. use OCP\User\Events\UserLoggedInEvent;
  244. use OCP\User\Events\UserLoggedInWithCookieEvent;
  245. use OCP\User\Events\UserLoggedOutEvent;
  246. use Psr\Container\ContainerExceptionInterface;
  247. use Psr\Container\ContainerInterface;
  248. use Psr\Log\LoggerInterface;
  249. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  250. use Symfony\Component\EventDispatcher\GenericEvent;
  251. use OCA\Files_External\Service\UserStoragesService;
  252. use OCA\Files_External\Service\UserGlobalStoragesService;
  253. use OCA\Files_External\Service\GlobalStoragesService;
  254. use OCA\Files_External\Service\BackendService;
  255. /**
  256. * Class Server
  257. *
  258. * @package OC
  259. *
  260. * TODO: hookup all manager classes
  261. */
  262. class Server extends ServerContainer implements IServerContainer {
  263. /** @var string */
  264. private $webRoot;
  265. /**
  266. * @param string $webRoot
  267. * @param \OC\Config $config
  268. */
  269. public function __construct($webRoot, \OC\Config $config) {
  270. parent::__construct();
  271. $this->webRoot = $webRoot;
  272. // To find out if we are running from CLI or not
  273. $this->registerParameter('isCLI', \OC::$CLI);
  274. $this->registerParameter('serverRoot', \OC::$SERVERROOT);
  275. $this->registerService(ContainerInterface::class, function (ContainerInterface $c) {
  276. return $c;
  277. });
  278. $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) {
  279. return $c;
  280. });
  281. $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
  282. /** @deprecated 19.0.0 */
  283. $this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class);
  284. $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class);
  285. /** @deprecated 19.0.0 */
  286. $this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class);
  287. $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class);
  288. /** @deprecated 19.0.0 */
  289. $this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class);
  290. $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
  291. /** @deprecated 19.0.0 */
  292. $this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class);
  293. $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class);
  294. $this->registerAlias(ITemplateManager::class, TemplateManager::class);
  295. $this->registerAlias(IActionFactory::class, ActionFactory::class);
  296. $this->registerService(View::class, function (Server $c) {
  297. return new View();
  298. }, false);
  299. $this->registerService(IPreview::class, function (ContainerInterface $c) {
  300. return new PreviewManager(
  301. $c->get(\OCP\IConfig::class),
  302. $c->get(IRootFolder::class),
  303. new \OC\Preview\Storage\Root(
  304. $c->get(IRootFolder::class),
  305. $c->get(SystemConfig::class)
  306. ),
  307. $c->get(SymfonyAdapter::class),
  308. $c->get(GeneratorHelper::class),
  309. $c->get(ISession::class)->get('user_id'),
  310. $c->get(Coordinator::class),
  311. $c->get(IServerContainer::class)
  312. );
  313. });
  314. /** @deprecated 19.0.0 */
  315. $this->registerDeprecatedAlias('PreviewManager', IPreview::class);
  316. $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) {
  317. return new \OC\Preview\Watcher(
  318. new \OC\Preview\Storage\Root(
  319. $c->get(IRootFolder::class),
  320. $c->get(SystemConfig::class)
  321. )
  322. );
  323. });
  324. $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) {
  325. $view = new View();
  326. $util = new Encryption\Util(
  327. $view,
  328. $c->get(IUserManager::class),
  329. $c->get(IGroupManager::class),
  330. $c->get(\OCP\IConfig::class)
  331. );
  332. return new Encryption\Manager(
  333. $c->get(\OCP\IConfig::class),
  334. $c->get(ILogger::class),
  335. $c->getL10N('core'),
  336. new View(),
  337. $util,
  338. new ArrayCache()
  339. );
  340. });
  341. /** @deprecated 19.0.0 */
  342. $this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class);
  343. /** @deprecated 21.0.0 */
  344. $this->registerDeprecatedAlias('EncryptionFileHelper', IFile::class);
  345. $this->registerService(IFile::class, function (ContainerInterface $c) {
  346. $util = new Encryption\Util(
  347. new View(),
  348. $c->get(IUserManager::class),
  349. $c->get(IGroupManager::class),
  350. $c->get(\OCP\IConfig::class)
  351. );
  352. return new Encryption\File(
  353. $util,
  354. $c->get(IRootFolder::class),
  355. $c->get(\OCP\Share\IManager::class)
  356. );
  357. });
  358. /** @deprecated 21.0.0 */
  359. $this->registerDeprecatedAlias('EncryptionKeyStorage', IStorage::class);
  360. $this->registerService(IStorage::class, function (ContainerInterface $c) {
  361. $view = new View();
  362. $util = new Encryption\Util(
  363. $view,
  364. $c->get(IUserManager::class),
  365. $c->get(IGroupManager::class),
  366. $c->get(\OCP\IConfig::class)
  367. );
  368. return new Encryption\Keys\Storage(
  369. $view,
  370. $util,
  371. $c->get(ICrypto::class),
  372. $c->get(\OCP\IConfig::class)
  373. );
  374. });
  375. /** @deprecated 20.0.0 */
  376. $this->registerDeprecatedAlias('TagMapper', TagMapper::class);
  377. $this->registerAlias(\OCP\ITagManager::class, TagManager::class);
  378. /** @deprecated 19.0.0 */
  379. $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class);
  380. $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) {
  381. /** @var \OCP\IConfig $config */
  382. $config = $c->get(\OCP\IConfig::class);
  383. $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
  384. return new $factoryClass($this);
  385. });
  386. $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) {
  387. return $c->get('SystemTagManagerFactory')->getManager();
  388. });
  389. /** @deprecated 19.0.0 */
  390. $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class);
  391. $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) {
  392. return $c->get('SystemTagManagerFactory')->getObjectMapper();
  393. });
  394. $this->registerService('RootFolder', function (ContainerInterface $c) {
  395. $manager = \OC\Files\Filesystem::getMountManager(null);
  396. $view = new View();
  397. $root = new Root(
  398. $manager,
  399. $view,
  400. null,
  401. $c->get(IUserMountCache::class),
  402. $this->get(ILogger::class),
  403. $this->get(IUserManager::class)
  404. );
  405. $previewConnector = new \OC\Preview\WatcherConnector(
  406. $root,
  407. $c->get(SystemConfig::class)
  408. );
  409. $previewConnector->connectWatcher();
  410. return $root;
  411. });
  412. $this->registerService(HookConnector::class, function (ContainerInterface $c) {
  413. return new HookConnector(
  414. $c->get(IRootFolder::class),
  415. new View(),
  416. $c->get(\OC\EventDispatcher\SymfonyAdapter::class),
  417. $c->get(IEventDispatcher::class)
  418. );
  419. });
  420. /** @deprecated 19.0.0 */
  421. $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class);
  422. $this->registerService(IRootFolder::class, function (ContainerInterface $c) {
  423. return new LazyRoot(function () use ($c) {
  424. return $c->get('RootFolder');
  425. });
  426. });
  427. /** @deprecated 19.0.0 */
  428. $this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class);
  429. /** @deprecated 19.0.0 */
  430. $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class);
  431. $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
  432. $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) {
  433. $groupManager = new \OC\Group\Manager($this->get(IUserManager::class), $c->get(SymfonyAdapter::class), $this->get(ILogger::class));
  434. $groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
  435. /** @var IEventDispatcher $dispatcher */
  436. $dispatcher = $this->get(IEventDispatcher::class);
  437. $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid));
  438. });
  439. $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) {
  440. /** @var IEventDispatcher $dispatcher */
  441. $dispatcher = $this->get(IEventDispatcher::class);
  442. $dispatcher->dispatchTyped(new GroupCreatedEvent($group));
  443. });
  444. $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
  445. /** @var IEventDispatcher $dispatcher */
  446. $dispatcher = $this->get(IEventDispatcher::class);
  447. $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group));
  448. });
  449. $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
  450. /** @var IEventDispatcher $dispatcher */
  451. $dispatcher = $this->get(IEventDispatcher::class);
  452. $dispatcher->dispatchTyped(new GroupDeletedEvent($group));
  453. });
  454. $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
  455. /** @var IEventDispatcher $dispatcher */
  456. $dispatcher = $this->get(IEventDispatcher::class);
  457. $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user));
  458. });
  459. $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
  460. /** @var IEventDispatcher $dispatcher */
  461. $dispatcher = $this->get(IEventDispatcher::class);
  462. $dispatcher->dispatchTyped(new UserAddedEvent($group, $user));
  463. });
  464. $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
  465. /** @var IEventDispatcher $dispatcher */
  466. $dispatcher = $this->get(IEventDispatcher::class);
  467. $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user));
  468. });
  469. $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
  470. /** @var IEventDispatcher $dispatcher */
  471. $dispatcher = $this->get(IEventDispatcher::class);
  472. $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user));
  473. });
  474. return $groupManager;
  475. });
  476. /** @deprecated 19.0.0 */
  477. $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class);
  478. $this->registerService(Store::class, function (ContainerInterface $c) {
  479. $session = $c->get(ISession::class);
  480. if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
  481. $tokenProvider = $c->get(IProvider::class);
  482. } else {
  483. $tokenProvider = null;
  484. }
  485. $logger = $c->get(LoggerInterface::class);
  486. return new Store($session, $logger, $tokenProvider);
  487. });
  488. $this->registerAlias(IStore::class, Store::class);
  489. $this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
  490. $this->registerService(\OC\User\Session::class, function (Server $c) {
  491. $manager = $c->get(IUserManager::class);
  492. $session = new \OC\Session\Memory('');
  493. $timeFactory = new TimeFactory();
  494. // Token providers might require a working database. This code
  495. // might however be called when ownCloud is not yet setup.
  496. if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
  497. $defaultTokenProvider = $c->get(IProvider::class);
  498. } else {
  499. $defaultTokenProvider = null;
  500. }
  501. $legacyDispatcher = $c->get(SymfonyAdapter::class);
  502. $userSession = new \OC\User\Session(
  503. $manager,
  504. $session,
  505. $timeFactory,
  506. $defaultTokenProvider,
  507. $c->get(\OCP\IConfig::class),
  508. $c->get(ISecureRandom::class),
  509. $c->getLockdownManager(),
  510. $c->get(ILogger::class),
  511. $c->get(IEventDispatcher::class)
  512. );
  513. /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */
  514. $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
  515. \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]);
  516. });
  517. /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */
  518. $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
  519. /** @var \OC\User\User $user */
  520. \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]);
  521. });
  522. /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */
  523. $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) {
  524. /** @var \OC\User\User $user */
  525. \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]);
  526. $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
  527. });
  528. /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */
  529. $userSession->listen('\OC\User', 'postDelete', function ($user) {
  530. /** @var \OC\User\User $user */
  531. \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]);
  532. });
  533. $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
  534. /** @var \OC\User\User $user */
  535. \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
  536. /** @var IEventDispatcher $dispatcher */
  537. $dispatcher = $this->get(IEventDispatcher::class);
  538. $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword));
  539. });
  540. $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
  541. /** @var \OC\User\User $user */
  542. \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
  543. /** @var IEventDispatcher $dispatcher */
  544. $dispatcher = $this->get(IEventDispatcher::class);
  545. $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword));
  546. });
  547. $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
  548. \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]);
  549. /** @var IEventDispatcher $dispatcher */
  550. $dispatcher = $this->get(IEventDispatcher::class);
  551. $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password));
  552. });
  553. $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) {
  554. /** @var \OC\User\User $user */
  555. \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]);
  556. /** @var IEventDispatcher $dispatcher */
  557. $dispatcher = $this->get(IEventDispatcher::class);
  558. $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin));
  559. });
  560. $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) {
  561. /** @var IEventDispatcher $dispatcher */
  562. $dispatcher = $this->get(IEventDispatcher::class);
  563. $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid));
  564. });
  565. $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
  566. /** @var \OC\User\User $user */
  567. \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]);
  568. /** @var IEventDispatcher $dispatcher */
  569. $dispatcher = $this->get(IEventDispatcher::class);
  570. $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password));
  571. });
  572. $userSession->listen('\OC\User', 'logout', function ($user) {
  573. \OC_Hook::emit('OC_User', 'logout', []);
  574. /** @var IEventDispatcher $dispatcher */
  575. $dispatcher = $this->get(IEventDispatcher::class);
  576. $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user));
  577. });
  578. $userSession->listen('\OC\User', 'postLogout', function ($user) {
  579. /** @var IEventDispatcher $dispatcher */
  580. $dispatcher = $this->get(IEventDispatcher::class);
  581. $dispatcher->dispatchTyped(new UserLoggedOutEvent($user));
  582. });
  583. $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
  584. /** @var \OC\User\User $user */
  585. \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]);
  586. /** @var IEventDispatcher $dispatcher */
  587. $dispatcher = $this->get(IEventDispatcher::class);
  588. $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue));
  589. });
  590. return $userSession;
  591. });
  592. $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class);
  593. /** @deprecated 19.0.0 */
  594. $this->registerDeprecatedAlias('UserSession', \OC\User\Session::class);
  595. $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class);
  596. $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class);
  597. /** @deprecated 19.0.0 */
  598. $this->registerDeprecatedAlias('NavigationManager', INavigationManager::class);
  599. /** @deprecated 19.0.0 */
  600. $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class);
  601. $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
  602. $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) {
  603. return new \OC\SystemConfig($config);
  604. });
  605. /** @deprecated 19.0.0 */
  606. $this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class);
  607. /** @deprecated 19.0.0 */
  608. $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class);
  609. $this->registerAlias(IAppConfig::class, \OC\AppConfig::class);
  610. $this->registerService(IFactory::class, function (Server $c) {
  611. return new \OC\L10N\Factory(
  612. $c->get(\OCP\IConfig::class),
  613. $c->getRequest(),
  614. $c->get(IUserSession::class),
  615. \OC::$SERVERROOT
  616. );
  617. });
  618. /** @deprecated 19.0.0 */
  619. $this->registerDeprecatedAlias('L10NFactory', IFactory::class);
  620. $this->registerAlias(IURLGenerator::class, URLGenerator::class);
  621. /** @deprecated 19.0.0 */
  622. $this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class);
  623. /** @deprecated 19.0.0 */
  624. $this->registerDeprecatedAlias('AppFetcher', AppFetcher::class);
  625. /** @deprecated 19.0.0 */
  626. $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class);
  627. $this->registerService(ICache::class, function ($c) {
  628. return new Cache\File();
  629. });
  630. /** @deprecated 19.0.0 */
  631. $this->registerDeprecatedAlias('UserCache', ICache::class);
  632. $this->registerService(Factory::class, function (Server $c) {
  633. $arrayCacheFactory = new \OC\Memcache\Factory('', $c->get(ILogger::class),
  634. ArrayCache::class,
  635. ArrayCache::class,
  636. ArrayCache::class
  637. );
  638. /** @var \OCP\IConfig $config */
  639. $config = $c->get(\OCP\IConfig::class);
  640. if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
  641. $v = \OC_App::getAppVersions();
  642. $v['core'] = implode(',', \OC_Util::getVersion());
  643. $version = implode(',', $v);
  644. $instanceId = \OC_Util::getInstanceId();
  645. $path = \OC::$SERVERROOT;
  646. $prefix = md5($instanceId . '-' . $version . '-' . $path);
  647. return new \OC\Memcache\Factory($prefix, $c->get(ILogger::class),
  648. $config->getSystemValue('memcache.local', null),
  649. $config->getSystemValue('memcache.distributed', null),
  650. $config->getSystemValue('memcache.locking', null),
  651. $config->getSystemValueString('redis_log_file')
  652. );
  653. }
  654. return $arrayCacheFactory;
  655. });
  656. /** @deprecated 19.0.0 */
  657. $this->registerDeprecatedAlias('MemCacheFactory', Factory::class);
  658. $this->registerAlias(ICacheFactory::class, Factory::class);
  659. $this->registerService('RedisFactory', function (Server $c) {
  660. $systemConfig = $c->get(SystemConfig::class);
  661. return new RedisFactory($systemConfig);
  662. });
  663. $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
  664. $l10n = $this->get(IFactory::class)->get('lib');
  665. return new \OC\Activity\Manager(
  666. $c->getRequest(),
  667. $c->get(IUserSession::class),
  668. $c->get(\OCP\IConfig::class),
  669. $c->get(IValidator::class),
  670. $l10n
  671. );
  672. });
  673. /** @deprecated 19.0.0 */
  674. $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class);
  675. $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
  676. return new \OC\Activity\EventMerger(
  677. $c->getL10N('lib')
  678. );
  679. });
  680. $this->registerAlias(IValidator::class, Validator::class);
  681. $this->registerService(AvatarManager::class, function (Server $c) {
  682. return new AvatarManager(
  683. $c->get(IUserSession::class),
  684. $c->get(\OC\User\Manager::class),
  685. $c->getAppDataDir('avatar'),
  686. $c->getL10N('lib'),
  687. $c->get(LoggerInterface::class),
  688. $c->get(\OCP\IConfig::class),
  689. $c->get(IAccountManager::class),
  690. $c->get(KnownUserService::class)
  691. );
  692. });
  693. $this->registerAlias(IAvatarManager::class, AvatarManager::class);
  694. /** @deprecated 19.0.0 */
  695. $this->registerDeprecatedAlias('AvatarManager', AvatarManager::class);
  696. $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
  697. $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class);
  698. $this->registerService(\OC\Log::class, function (Server $c) {
  699. $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file');
  700. $factory = new LogFactory($c, $this->get(SystemConfig::class));
  701. $logger = $factory->get($logType);
  702. $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class);
  703. return new Log($logger, $this->get(SystemConfig::class), null, $registry);
  704. });
  705. $this->registerAlias(ILogger::class, \OC\Log::class);
  706. /** @deprecated 19.0.0 */
  707. $this->registerDeprecatedAlias('Logger', \OC\Log::class);
  708. // PSR-3 logger
  709. $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class);
  710. $this->registerService(ILogFactory::class, function (Server $c) {
  711. return new LogFactory($c, $this->get(SystemConfig::class));
  712. });
  713. $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class);
  714. /** @deprecated 19.0.0 */
  715. $this->registerDeprecatedAlias('JobList', IJobList::class);
  716. $this->registerService(Router::class, function (Server $c) {
  717. $cacheFactory = $c->get(ICacheFactory::class);
  718. $logger = $c->get(ILogger::class);
  719. if ($cacheFactory->isLocalCacheAvailable()) {
  720. $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger);
  721. } else {
  722. $router = new \OC\Route\Router($logger);
  723. }
  724. return $router;
  725. });
  726. $this->registerAlias(IRouter::class, Router::class);
  727. /** @deprecated 19.0.0 */
  728. $this->registerDeprecatedAlias('Router', IRouter::class);
  729. $this->registerAlias(ISearch::class, Search::class);
  730. /** @deprecated 19.0.0 */
  731. $this->registerDeprecatedAlias('Search', ISearch::class);
  732. $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
  733. $cacheFactory = $c->get(ICacheFactory::class);
  734. if ($cacheFactory->isAvailable()) {
  735. $backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend(
  736. $this->get(ICacheFactory::class),
  737. new \OC\AppFramework\Utility\TimeFactory()
  738. );
  739. } else {
  740. $backend = new \OC\Security\RateLimiting\Backend\DatabaseBackend(
  741. $c->get(IDBConnection::class),
  742. new \OC\AppFramework\Utility\TimeFactory()
  743. );
  744. }
  745. return $backend;
  746. });
  747. $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class);
  748. /** @deprecated 19.0.0 */
  749. $this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
  750. $this->registerAlias(IVerificationToken::class, VerificationToken::class);
  751. $this->registerAlias(ICrypto::class, Crypto::class);
  752. /** @deprecated 19.0.0 */
  753. $this->registerDeprecatedAlias('Crypto', ICrypto::class);
  754. $this->registerAlias(IHasher::class, Hasher::class);
  755. /** @deprecated 19.0.0 */
  756. $this->registerDeprecatedAlias('Hasher', IHasher::class);
  757. $this->registerAlias(ICredentialsManager::class, CredentialsManager::class);
  758. /** @deprecated 19.0.0 */
  759. $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class);
  760. $this->registerAlias(IDBConnection::class, ConnectionAdapter::class);
  761. $this->registerService(Connection::class, function (Server $c) {
  762. $systemConfig = $c->get(SystemConfig::class);
  763. $factory = new \OC\DB\ConnectionFactory($systemConfig);
  764. $type = $systemConfig->getValue('dbtype', 'sqlite');
  765. if (!$factory->isValidType($type)) {
  766. throw new \OC\DatabaseException('Invalid database type');
  767. }
  768. $connectionParams = $factory->createConnectionParams();
  769. $connection = $factory->getConnection($type, $connectionParams);
  770. $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
  771. return $connection;
  772. });
  773. /** @deprecated 19.0.0 */
  774. $this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class);
  775. $this->registerAlias(ICertificateManager::class, CertificateManager::class);
  776. $this->registerAlias(IClientService::class, ClientService::class);
  777. $this->registerService(LocalAddressChecker::class, function (ContainerInterface $c) {
  778. return new LocalAddressChecker(
  779. $c->get(ILogger::class),
  780. );
  781. });
  782. $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) {
  783. return new NegativeDnsCache(
  784. $c->get(ICacheFactory::class),
  785. );
  786. });
  787. $this->registerService(DnsPinMiddleware::class, function (ContainerInterface $c) {
  788. return new DnsPinMiddleware(
  789. $c->get(NegativeDnsCache::class),
  790. $c->get(LocalAddressChecker::class)
  791. );
  792. });
  793. $this->registerDeprecatedAlias('HttpClientService', IClientService::class);
  794. $this->registerService(IEventLogger::class, function (ContainerInterface $c) {
  795. $eventLogger = new EventLogger();
  796. if ($c->get(SystemConfig::class)->getValue('debug', false)) {
  797. // In debug mode, module is being activated by default
  798. $eventLogger->activate();
  799. }
  800. return $eventLogger;
  801. });
  802. /** @deprecated 19.0.0 */
  803. $this->registerDeprecatedAlias('EventLogger', IEventLogger::class);
  804. $this->registerService(IQueryLogger::class, function (ContainerInterface $c) {
  805. $queryLogger = new QueryLogger();
  806. if ($c->get(SystemConfig::class)->getValue('debug', false)) {
  807. // In debug mode, module is being activated by default
  808. $queryLogger->activate();
  809. }
  810. return $queryLogger;
  811. });
  812. /** @deprecated 19.0.0 */
  813. $this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class);
  814. /** @deprecated 19.0.0 */
  815. $this->registerDeprecatedAlias('TempManager', TempManager::class);
  816. $this->registerAlias(ITempManager::class, TempManager::class);
  817. $this->registerService(AppManager::class, function (ContainerInterface $c) {
  818. // TODO: use auto-wiring
  819. return new \OC\App\AppManager(
  820. $c->get(IUserSession::class),
  821. $c->get(\OCP\IConfig::class),
  822. $c->get(\OC\AppConfig::class),
  823. $c->get(IGroupManager::class),
  824. $c->get(ICacheFactory::class),
  825. $c->get(SymfonyAdapter::class),
  826. $c->get(LoggerInterface::class)
  827. );
  828. });
  829. /** @deprecated 19.0.0 */
  830. $this->registerDeprecatedAlias('AppManager', AppManager::class);
  831. $this->registerAlias(IAppManager::class, AppManager::class);
  832. $this->registerAlias(IDateTimeZone::class, DateTimeZone::class);
  833. /** @deprecated 19.0.0 */
  834. $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class);
  835. $this->registerService(IDateTimeFormatter::class, function (Server $c) {
  836. $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null);
  837. return new DateTimeFormatter(
  838. $c->get(IDateTimeZone::class)->getTimeZone(),
  839. $c->getL10N('lib', $language)
  840. );
  841. });
  842. /** @deprecated 19.0.0 */
  843. $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class);
  844. $this->registerService(IUserMountCache::class, function (ContainerInterface $c) {
  845. $mountCache = new UserMountCache(
  846. $c->get(IDBConnection::class),
  847. $c->get(IUserManager::class),
  848. $c->get(ILogger::class)
  849. );
  850. $listener = new UserMountCacheListener($mountCache);
  851. $listener->listen($c->get(IUserManager::class));
  852. return $mountCache;
  853. });
  854. /** @deprecated 19.0.0 */
  855. $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class);
  856. $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) {
  857. $loader = \OC\Files\Filesystem::getLoader();
  858. $mountCache = $c->get(IUserMountCache::class);
  859. $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
  860. // builtin providers
  861. $config = $c->get(\OCP\IConfig::class);
  862. $logger = $c->get(ILogger::class);
  863. $manager->registerProvider(new CacheMountProvider($config));
  864. $manager->registerHomeProvider(new LocalHomeMountProvider());
  865. $manager->registerHomeProvider(new ObjectHomeMountProvider($config));
  866. $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config));
  867. return $manager;
  868. });
  869. /** @deprecated 19.0.0 */
  870. $this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class);
  871. /** @deprecated 20.0.0 */
  872. $this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class);
  873. $this->registerService(IBus::class, function (ContainerInterface $c) {
  874. $busClass = $c->get(\OCP\IConfig::class)->getSystemValue('commandbus');
  875. if ($busClass) {
  876. [$app, $class] = explode('::', $busClass, 2);
  877. if ($c->get(IAppManager::class)->isInstalled($app)) {
  878. \OC_App::loadApp($app);
  879. return $c->get($class);
  880. } else {
  881. throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
  882. }
  883. } else {
  884. $jobList = $c->get(IJobList::class);
  885. return new CronBus($jobList);
  886. }
  887. });
  888. $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class);
  889. /** @deprecated 20.0.0 */
  890. $this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class);
  891. $this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class);
  892. /** @deprecated 19.0.0 */
  893. $this->registerDeprecatedAlias('Throttler', Throttler::class);
  894. $this->registerService('IntegrityCodeChecker', function (ContainerInterface $c) {
  895. // IConfig and IAppManager requires a working database. This code
  896. // might however be called when ownCloud is not yet setup.
  897. if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
  898. $config = $c->get(\OCP\IConfig::class);
  899. $appManager = $c->get(IAppManager::class);
  900. } else {
  901. $config = null;
  902. $appManager = null;
  903. }
  904. return new Checker(
  905. new EnvironmentHelper(),
  906. new FileAccessHelper(),
  907. new AppLocator(),
  908. $config,
  909. $c->get(ICacheFactory::class),
  910. $appManager,
  911. $c->get(IMimeTypeDetector::class)
  912. );
  913. });
  914. $this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) {
  915. if (isset($this['urlParams'])) {
  916. $urlParams = $this['urlParams'];
  917. } else {
  918. $urlParams = [];
  919. }
  920. if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
  921. && in_array('fakeinput', stream_get_wrappers())
  922. ) {
  923. $stream = 'fakeinput://data';
  924. } else {
  925. $stream = 'php://input';
  926. }
  927. return new Request(
  928. [
  929. 'get' => $_GET,
  930. 'post' => $_POST,
  931. 'files' => $_FILES,
  932. 'server' => $_SERVER,
  933. 'env' => $_ENV,
  934. 'cookies' => $_COOKIE,
  935. 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
  936. ? $_SERVER['REQUEST_METHOD']
  937. : '',
  938. 'urlParams' => $urlParams,
  939. ],
  940. $this->get(ISecureRandom::class),
  941. $this->get(\OCP\IConfig::class),
  942. $this->get(CsrfTokenManager::class),
  943. $stream
  944. );
  945. });
  946. /** @deprecated 19.0.0 */
  947. $this->registerDeprecatedAlias('Request', \OCP\IRequest::class);
  948. $this->registerService(IMailer::class, function (Server $c) {
  949. return new Mailer(
  950. $c->get(\OCP\IConfig::class),
  951. $c->get(ILogger::class),
  952. $c->get(Defaults::class),
  953. $c->get(IURLGenerator::class),
  954. $c->getL10N('lib'),
  955. $c->get(IEventDispatcher::class),
  956. $c->get(IFactory::class)
  957. );
  958. });
  959. /** @deprecated 19.0.0 */
  960. $this->registerDeprecatedAlias('Mailer', IMailer::class);
  961. /** @deprecated 21.0.0 */
  962. $this->registerDeprecatedAlias('LDAPProvider', ILDAPProvider::class);
  963. $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) {
  964. $config = $c->get(\OCP\IConfig::class);
  965. $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
  966. if (is_null($factoryClass) || !class_exists($factoryClass)) {
  967. return new NullLDAPProviderFactory($this);
  968. }
  969. /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
  970. return new $factoryClass($this);
  971. });
  972. $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) {
  973. $factory = $c->get(ILDAPProviderFactory::class);
  974. return $factory->getLDAPProvider();
  975. });
  976. $this->registerService(ILockingProvider::class, function (ContainerInterface $c) {
  977. $ini = $c->get(IniGetWrapper::class);
  978. $config = $c->get(\OCP\IConfig::class);
  979. $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
  980. if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
  981. /** @var \OC\Memcache\Factory $memcacheFactory */
  982. $memcacheFactory = $c->get(ICacheFactory::class);
  983. $memcache = $memcacheFactory->createLocking('lock');
  984. if (!($memcache instanceof \OC\Memcache\NullCache)) {
  985. return new MemcacheLockingProvider($memcache, $ttl);
  986. }
  987. return new DBLockingProvider(
  988. $c->get(IDBConnection::class),
  989. $c->get(ILogger::class),
  990. new TimeFactory(),
  991. $ttl,
  992. !\OC::$CLI
  993. );
  994. }
  995. return new NoopLockingProvider();
  996. });
  997. /** @deprecated 19.0.0 */
  998. $this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class);
  999. $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class);
  1000. /** @deprecated 19.0.0 */
  1001. $this->registerDeprecatedAlias('MountManager', IMountManager::class);
  1002. $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) {
  1003. return new \OC\Files\Type\Detection(
  1004. $c->get(IURLGenerator::class),
  1005. $c->get(ILogger::class),
  1006. \OC::$configDir,
  1007. \OC::$SERVERROOT . '/resources/config/'
  1008. );
  1009. });
  1010. /** @deprecated 19.0.0 */
  1011. $this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class);
  1012. $this->registerAlias(IMimeTypeLoader::class, Loader::class);
  1013. /** @deprecated 19.0.0 */
  1014. $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class);
  1015. $this->registerService(BundleFetcher::class, function () {
  1016. return new BundleFetcher($this->getL10N('lib'));
  1017. });
  1018. $this->registerAlias(\OCP\Notification\IManager::class, Manager::class);
  1019. /** @deprecated 19.0.0 */
  1020. $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class);
  1021. $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) {
  1022. $manager = new CapabilitiesManager($c->get(LoggerInterface::class));
  1023. $manager->registerCapability(function () use ($c) {
  1024. return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class));
  1025. });
  1026. $manager->registerCapability(function () use ($c) {
  1027. return $c->get(\OC\Security\Bruteforce\Capabilities::class);
  1028. });
  1029. return $manager;
  1030. });
  1031. /** @deprecated 19.0.0 */
  1032. $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class);
  1033. $this->registerService(ICommentsManager::class, function (Server $c) {
  1034. $config = $c->get(\OCP\IConfig::class);
  1035. $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
  1036. /** @var \OCP\Comments\ICommentsManagerFactory $factory */
  1037. $factory = new $factoryClass($this);
  1038. $manager = $factory->getManager();
  1039. $manager->registerDisplayNameResolver('user', function ($id) use ($c) {
  1040. $manager = $c->get(IUserManager::class);
  1041. $user = $manager->get($id);
  1042. if (is_null($user)) {
  1043. $l = $c->getL10N('core');
  1044. $displayName = $l->t('Unknown user');
  1045. } else {
  1046. $displayName = $user->getDisplayName();
  1047. }
  1048. return $displayName;
  1049. });
  1050. return $manager;
  1051. });
  1052. /** @deprecated 19.0.0 */
  1053. $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class);
  1054. $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults');
  1055. $this->registerService('ThemingDefaults', function (Server $c) {
  1056. /*
  1057. * Dark magic for autoloader.
  1058. * If we do a class_exists it will try to load the class which will
  1059. * make composer cache the result. Resulting in errors when enabling
  1060. * the theming app.
  1061. */
  1062. $prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
  1063. if (isset($prefixes['OCA\\Theming\\'])) {
  1064. $classExists = true;
  1065. } else {
  1066. $classExists = false;
  1067. }
  1068. if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValue('installed', false) && $c->get(IAppManager::class)->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
  1069. return new ThemingDefaults(
  1070. $c->get(\OCP\IConfig::class),
  1071. $c->getL10N('theming'),
  1072. $c->get(IURLGenerator::class),
  1073. $c->get(ICacheFactory::class),
  1074. new Util($c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming')),
  1075. new ImageManager(
  1076. $c->get(\OCP\IConfig::class),
  1077. $c->getAppDataDir('theming'),
  1078. $c->get(IURLGenerator::class),
  1079. $this->get(ICacheFactory::class),
  1080. $this->get(ILogger::class),
  1081. $this->get(ITempManager::class)
  1082. ),
  1083. $c->get(IAppManager::class),
  1084. $c->get(INavigationManager::class)
  1085. );
  1086. }
  1087. return new \OC_Defaults();
  1088. });
  1089. $this->registerService(JSCombiner::class, function (Server $c) {
  1090. return new JSCombiner(
  1091. $c->getAppDataDir('js'),
  1092. $c->get(IURLGenerator::class),
  1093. $this->get(ICacheFactory::class),
  1094. $c->get(SystemConfig::class),
  1095. $c->get(ILogger::class)
  1096. );
  1097. });
  1098. $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class);
  1099. /** @deprecated 19.0.0 */
  1100. $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class);
  1101. $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class);
  1102. $this->registerService('CryptoWrapper', function (ContainerInterface $c) {
  1103. // FIXME: Instantiiated here due to cyclic dependency
  1104. $request = new Request(
  1105. [
  1106. 'get' => $_GET,
  1107. 'post' => $_POST,
  1108. 'files' => $_FILES,
  1109. 'server' => $_SERVER,
  1110. 'env' => $_ENV,
  1111. 'cookies' => $_COOKIE,
  1112. 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
  1113. ? $_SERVER['REQUEST_METHOD']
  1114. : null,
  1115. ],
  1116. $c->get(ISecureRandom::class),
  1117. $c->get(\OCP\IConfig::class)
  1118. );
  1119. return new CryptoWrapper(
  1120. $c->get(\OCP\IConfig::class),
  1121. $c->get(ICrypto::class),
  1122. $c->get(ISecureRandom::class),
  1123. $request
  1124. );
  1125. });
  1126. /** @deprecated 19.0.0 */
  1127. $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class);
  1128. $this->registerService(SessionStorage::class, function (ContainerInterface $c) {
  1129. return new SessionStorage($c->get(ISession::class));
  1130. });
  1131. $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class);
  1132. /** @deprecated 19.0.0 */
  1133. $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class);
  1134. $this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) {
  1135. $config = $c->get(\OCP\IConfig::class);
  1136. $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
  1137. /** @var \OCP\Share\IProviderFactory $factory */
  1138. $factory = new $factoryClass($this);
  1139. $manager = new \OC\Share20\Manager(
  1140. $c->get(ILogger::class),
  1141. $c->get(\OCP\IConfig::class),
  1142. $c->get(ISecureRandom::class),
  1143. $c->get(IHasher::class),
  1144. $c->get(IMountManager::class),
  1145. $c->get(IGroupManager::class),
  1146. $c->getL10N('lib'),
  1147. $c->get(IFactory::class),
  1148. $factory,
  1149. $c->get(IUserManager::class),
  1150. $c->get(IRootFolder::class),
  1151. $c->get(SymfonyAdapter::class),
  1152. $c->get(IMailer::class),
  1153. $c->get(IURLGenerator::class),
  1154. $c->get('ThemingDefaults'),
  1155. $c->get(IEventDispatcher::class),
  1156. $c->get(IUserSession::class),
  1157. $c->get(KnownUserService::class)
  1158. );
  1159. return $manager;
  1160. });
  1161. /** @deprecated 19.0.0 */
  1162. $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class);
  1163. $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) {
  1164. $instance = new Collaboration\Collaborators\Search($c);
  1165. // register default plugins
  1166. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
  1167. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
  1168. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
  1169. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
  1170. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]);
  1171. return $instance;
  1172. });
  1173. /** @deprecated 19.0.0 */
  1174. $this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
  1175. $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class);
  1176. $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
  1177. $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class);
  1178. $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class);
  1179. $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class);
  1180. $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class);
  1181. $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) {
  1182. return new \OC\Files\AppData\Factory(
  1183. $c->get(IRootFolder::class),
  1184. $c->get(SystemConfig::class)
  1185. );
  1186. });
  1187. $this->registerService('LockdownManager', function (ContainerInterface $c) {
  1188. return new LockdownManager(function () use ($c) {
  1189. return $c->get(ISession::class);
  1190. });
  1191. });
  1192. $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) {
  1193. return new DiscoveryService(
  1194. $c->get(ICacheFactory::class),
  1195. $c->get(IClientService::class)
  1196. );
  1197. });
  1198. $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) {
  1199. return new CloudIdManager($c->get(\OCP\Contacts\IManager::class), $c->get(IURLGenerator::class), $c->get(IUserManager::class));
  1200. });
  1201. $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class);
  1202. $this->registerService(ICloudFederationProviderManager::class, function (ContainerInterface $c) {
  1203. return new CloudFederationProviderManager(
  1204. $c->get(IAppManager::class),
  1205. $c->get(IClientService::class),
  1206. $c->get(ICloudIdManager::class),
  1207. $c->get(ILogger::class)
  1208. );
  1209. });
  1210. $this->registerService(ICloudFederationFactory::class, function (Server $c) {
  1211. return new CloudFederationFactory();
  1212. });
  1213. $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
  1214. /** @deprecated 19.0.0 */
  1215. $this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
  1216. $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
  1217. /** @deprecated 19.0.0 */
  1218. $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
  1219. $this->registerService(Defaults::class, function (Server $c) {
  1220. return new Defaults(
  1221. $c->getThemingDefaults()
  1222. );
  1223. });
  1224. /** @deprecated 19.0.0 */
  1225. $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class);
  1226. $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) {
  1227. return $c->get(\OCP\IUserSession::class)->getSession();
  1228. }, false);
  1229. $this->registerService(IShareHelper::class, function (ContainerInterface $c) {
  1230. return new ShareHelper(
  1231. $c->get(\OCP\Share\IManager::class)
  1232. );
  1233. });
  1234. $this->registerService(Installer::class, function (ContainerInterface $c) {
  1235. return new Installer(
  1236. $c->get(AppFetcher::class),
  1237. $c->get(IClientService::class),
  1238. $c->get(ITempManager::class),
  1239. $c->get(LoggerInterface::class),
  1240. $c->get(\OCP\IConfig::class),
  1241. \OC::$CLI
  1242. );
  1243. });
  1244. $this->registerService(IApiFactory::class, function (ContainerInterface $c) {
  1245. return new ApiFactory($c->get(IClientService::class));
  1246. });
  1247. $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) {
  1248. $memcacheFactory = $c->get(ICacheFactory::class);
  1249. return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class));
  1250. });
  1251. $this->registerAlias(IContactsStore::class, ContactsStore::class);
  1252. $this->registerAlias(IAccountManager::class, AccountManager::class);
  1253. $this->registerAlias(IStorageFactory::class, StorageFactory::class);
  1254. $this->registerAlias(IDashboardManager::class, DashboardManager::class);
  1255. $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class);
  1256. $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class);
  1257. $this->registerAlias(ISubAdmin::class, SubAdmin::class);
  1258. $this->registerAlias(IInitialStateService::class, InitialStateService::class);
  1259. $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class);
  1260. $this->connectDispatcher();
  1261. }
  1262. public function boot() {
  1263. /** @var HookConnector $hookConnector */
  1264. $hookConnector = $this->get(HookConnector::class);
  1265. $hookConnector->viewToNode();
  1266. }
  1267. /**
  1268. * @return \OCP\Calendar\IManager
  1269. * @deprecated 20.0.0
  1270. */
  1271. public function getCalendarManager() {
  1272. return $this->get(\OC\Calendar\Manager::class);
  1273. }
  1274. /**
  1275. * @return \OCP\Calendar\Resource\IManager
  1276. * @deprecated 20.0.0
  1277. */
  1278. public function getCalendarResourceBackendManager() {
  1279. return $this->get(\OC\Calendar\Resource\Manager::class);
  1280. }
  1281. /**
  1282. * @return \OCP\Calendar\Room\IManager
  1283. * @deprecated 20.0.0
  1284. */
  1285. public function getCalendarRoomBackendManager() {
  1286. return $this->get(\OC\Calendar\Room\Manager::class);
  1287. }
  1288. private function connectDispatcher() {
  1289. $dispatcher = $this->get(SymfonyAdapter::class);
  1290. // Delete avatar on user deletion
  1291. $dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) {
  1292. $logger = $this->get(ILogger::class);
  1293. $manager = $this->getAvatarManager();
  1294. /** @var IUser $user */
  1295. $user = $e->getSubject();
  1296. try {
  1297. $avatar = $manager->getAvatar($user->getUID());
  1298. $avatar->remove();
  1299. } catch (NotFoundException $e) {
  1300. // no avatar to remove
  1301. } catch (\Exception $e) {
  1302. // Ignore exceptions
  1303. $logger->info('Could not cleanup avatar of ' . $user->getUID());
  1304. }
  1305. });
  1306. $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) {
  1307. $manager = $this->getAvatarManager();
  1308. /** @var IUser $user */
  1309. $user = $e->getSubject();
  1310. $feature = $e->getArgument('feature');
  1311. $oldValue = $e->getArgument('oldValue');
  1312. $value = $e->getArgument('value');
  1313. // We only change the avatar on display name changes
  1314. if ($feature !== 'displayName') {
  1315. return;
  1316. }
  1317. try {
  1318. $avatar = $manager->getAvatar($user->getUID());
  1319. $avatar->userChanged($feature, $oldValue, $value);
  1320. } catch (NotFoundException $e) {
  1321. // no avatar to remove
  1322. }
  1323. });
  1324. /** @var IEventDispatcher $eventDispatched */
  1325. $eventDispatched = $this->get(IEventDispatcher::class);
  1326. $eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class);
  1327. $eventDispatched->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class);
  1328. }
  1329. /**
  1330. * @return \OCP\Contacts\IManager
  1331. * @deprecated 20.0.0
  1332. */
  1333. public function getContactsManager() {
  1334. return $this->get(\OCP\Contacts\IManager::class);
  1335. }
  1336. /**
  1337. * @return \OC\Encryption\Manager
  1338. * @deprecated 20.0.0
  1339. */
  1340. public function getEncryptionManager() {
  1341. return $this->get(\OCP\Encryption\IManager::class);
  1342. }
  1343. /**
  1344. * @return \OC\Encryption\File
  1345. * @deprecated 20.0.0
  1346. */
  1347. public function getEncryptionFilesHelper() {
  1348. return $this->get(IFile::class);
  1349. }
  1350. /**
  1351. * @return \OCP\Encryption\Keys\IStorage
  1352. * @deprecated 20.0.0
  1353. */
  1354. public function getEncryptionKeyStorage() {
  1355. return $this->get(IStorage::class);
  1356. }
  1357. /**
  1358. * The current request object holding all information about the request
  1359. * currently being processed is returned from this method.
  1360. * In case the current execution was not initiated by a web request null is returned
  1361. *
  1362. * @return \OCP\IRequest
  1363. * @deprecated 20.0.0
  1364. */
  1365. public function getRequest() {
  1366. return $this->get(IRequest::class);
  1367. }
  1368. /**
  1369. * Returns the preview manager which can create preview images for a given file
  1370. *
  1371. * @return IPreview
  1372. * @deprecated 20.0.0
  1373. */
  1374. public function getPreviewManager() {
  1375. return $this->get(IPreview::class);
  1376. }
  1377. /**
  1378. * Returns the tag manager which can get and set tags for different object types
  1379. *
  1380. * @see \OCP\ITagManager::load()
  1381. * @return ITagManager
  1382. * @deprecated 20.0.0
  1383. */
  1384. public function getTagManager() {
  1385. return $this->get(ITagManager::class);
  1386. }
  1387. /**
  1388. * Returns the system-tag manager
  1389. *
  1390. * @return ISystemTagManager
  1391. *
  1392. * @since 9.0.0
  1393. * @deprecated 20.0.0
  1394. */
  1395. public function getSystemTagManager() {
  1396. return $this->get(ISystemTagManager::class);
  1397. }
  1398. /**
  1399. * Returns the system-tag object mapper
  1400. *
  1401. * @return ISystemTagObjectMapper
  1402. *
  1403. * @since 9.0.0
  1404. * @deprecated 20.0.0
  1405. */
  1406. public function getSystemTagObjectMapper() {
  1407. return $this->get(ISystemTagObjectMapper::class);
  1408. }
  1409. /**
  1410. * Returns the avatar manager, used for avatar functionality
  1411. *
  1412. * @return IAvatarManager
  1413. * @deprecated 20.0.0
  1414. */
  1415. public function getAvatarManager() {
  1416. return $this->get(IAvatarManager::class);
  1417. }
  1418. /**
  1419. * Returns the root folder of ownCloud's data directory
  1420. *
  1421. * @return IRootFolder
  1422. * @deprecated 20.0.0
  1423. */
  1424. public function getRootFolder() {
  1425. return $this->get(IRootFolder::class);
  1426. }
  1427. /**
  1428. * Returns the root folder of ownCloud's data directory
  1429. * This is the lazy variant so this gets only initialized once it
  1430. * is actually used.
  1431. *
  1432. * @return IRootFolder
  1433. * @deprecated 20.0.0
  1434. */
  1435. public function getLazyRootFolder() {
  1436. return $this->get(IRootFolder::class);
  1437. }
  1438. /**
  1439. * Returns a view to ownCloud's files folder
  1440. *
  1441. * @param string $userId user ID
  1442. * @return \OCP\Files\Folder|null
  1443. * @deprecated 20.0.0
  1444. */
  1445. public function getUserFolder($userId = null) {
  1446. if ($userId === null) {
  1447. $user = $this->get(IUserSession::class)->getUser();
  1448. if (!$user) {
  1449. return null;
  1450. }
  1451. $userId = $user->getUID();
  1452. }
  1453. $root = $this->get(IRootFolder::class);
  1454. return $root->getUserFolder($userId);
  1455. }
  1456. /**
  1457. * @return \OC\User\Manager
  1458. * @deprecated 20.0.0
  1459. */
  1460. public function getUserManager() {
  1461. return $this->get(IUserManager::class);
  1462. }
  1463. /**
  1464. * @return \OC\Group\Manager
  1465. * @deprecated 20.0.0
  1466. */
  1467. public function getGroupManager() {
  1468. return $this->get(IGroupManager::class);
  1469. }
  1470. /**
  1471. * @return \OC\User\Session
  1472. * @deprecated 20.0.0
  1473. */
  1474. public function getUserSession() {
  1475. return $this->get(IUserSession::class);
  1476. }
  1477. /**
  1478. * @return \OCP\ISession
  1479. * @deprecated 20.0.0
  1480. */
  1481. public function getSession() {
  1482. return $this->get(IUserSession::class)->getSession();
  1483. }
  1484. /**
  1485. * @param \OCP\ISession $session
  1486. */
  1487. public function setSession(\OCP\ISession $session) {
  1488. $this->get(SessionStorage::class)->setSession($session);
  1489. $this->get(IUserSession::class)->setSession($session);
  1490. $this->get(Store::class)->setSession($session);
  1491. }
  1492. /**
  1493. * @return \OC\Authentication\TwoFactorAuth\Manager
  1494. * @deprecated 20.0.0
  1495. */
  1496. public function getTwoFactorAuthManager() {
  1497. return $this->get(\OC\Authentication\TwoFactorAuth\Manager::class);
  1498. }
  1499. /**
  1500. * @return \OC\NavigationManager
  1501. * @deprecated 20.0.0
  1502. */
  1503. public function getNavigationManager() {
  1504. return $this->get(INavigationManager::class);
  1505. }
  1506. /**
  1507. * @return \OCP\IConfig
  1508. * @deprecated 20.0.0
  1509. */
  1510. public function getConfig() {
  1511. return $this->get(AllConfig::class);
  1512. }
  1513. /**
  1514. * @return \OC\SystemConfig
  1515. * @deprecated 20.0.0
  1516. */
  1517. public function getSystemConfig() {
  1518. return $this->get(SystemConfig::class);
  1519. }
  1520. /**
  1521. * Returns the app config manager
  1522. *
  1523. * @return IAppConfig
  1524. * @deprecated 20.0.0
  1525. */
  1526. public function getAppConfig() {
  1527. return $this->get(IAppConfig::class);
  1528. }
  1529. /**
  1530. * @return IFactory
  1531. * @deprecated 20.0.0
  1532. */
  1533. public function getL10NFactory() {
  1534. return $this->get(IFactory::class);
  1535. }
  1536. /**
  1537. * get an L10N instance
  1538. *
  1539. * @param string $app appid
  1540. * @param string $lang
  1541. * @return IL10N
  1542. * @deprecated 20.0.0
  1543. */
  1544. public function getL10N($app, $lang = null) {
  1545. return $this->get(IFactory::class)->get($app, $lang);
  1546. }
  1547. /**
  1548. * @return IURLGenerator
  1549. * @deprecated 20.0.0
  1550. */
  1551. public function getURLGenerator() {
  1552. return $this->get(IURLGenerator::class);
  1553. }
  1554. /**
  1555. * @return AppFetcher
  1556. * @deprecated 20.0.0
  1557. */
  1558. public function getAppFetcher() {
  1559. return $this->get(AppFetcher::class);
  1560. }
  1561. /**
  1562. * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
  1563. * getMemCacheFactory() instead.
  1564. *
  1565. * @return ICache
  1566. * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
  1567. */
  1568. public function getCache() {
  1569. return $this->get(ICache::class);
  1570. }
  1571. /**
  1572. * Returns an \OCP\CacheFactory instance
  1573. *
  1574. * @return \OCP\ICacheFactory
  1575. * @deprecated 20.0.0
  1576. */
  1577. public function getMemCacheFactory() {
  1578. return $this->get(ICacheFactory::class);
  1579. }
  1580. /**
  1581. * Returns an \OC\RedisFactory instance
  1582. *
  1583. * @return \OC\RedisFactory
  1584. * @deprecated 20.0.0
  1585. */
  1586. public function getGetRedisFactory() {
  1587. return $this->get('RedisFactory');
  1588. }
  1589. /**
  1590. * Returns the current session
  1591. *
  1592. * @return \OCP\IDBConnection
  1593. * @deprecated 20.0.0
  1594. */
  1595. public function getDatabaseConnection() {
  1596. return $this->get(IDBConnection::class);
  1597. }
  1598. /**
  1599. * Returns the activity manager
  1600. *
  1601. * @return \OCP\Activity\IManager
  1602. * @deprecated 20.0.0
  1603. */
  1604. public function getActivityManager() {
  1605. return $this->get(\OCP\Activity\IManager::class);
  1606. }
  1607. /**
  1608. * Returns an job list for controlling background jobs
  1609. *
  1610. * @return IJobList
  1611. * @deprecated 20.0.0
  1612. */
  1613. public function getJobList() {
  1614. return $this->get(IJobList::class);
  1615. }
  1616. /**
  1617. * Returns a logger instance
  1618. *
  1619. * @return ILogger
  1620. * @deprecated 20.0.0
  1621. */
  1622. public function getLogger() {
  1623. return $this->get(ILogger::class);
  1624. }
  1625. /**
  1626. * @return ILogFactory
  1627. * @throws \OCP\AppFramework\QueryException
  1628. * @deprecated 20.0.0
  1629. */
  1630. public function getLogFactory() {
  1631. return $this->get(ILogFactory::class);
  1632. }
  1633. /**
  1634. * Returns a router for generating and matching urls
  1635. *
  1636. * @return IRouter
  1637. * @deprecated 20.0.0
  1638. */
  1639. public function getRouter() {
  1640. return $this->get(IRouter::class);
  1641. }
  1642. /**
  1643. * Returns a search instance
  1644. *
  1645. * @return ISearch
  1646. * @deprecated 20.0.0
  1647. */
  1648. public function getSearch() {
  1649. return $this->get(ISearch::class);
  1650. }
  1651. /**
  1652. * Returns a SecureRandom instance
  1653. *
  1654. * @return \OCP\Security\ISecureRandom
  1655. * @deprecated 20.0.0
  1656. */
  1657. public function getSecureRandom() {
  1658. return $this->get(ISecureRandom::class);
  1659. }
  1660. /**
  1661. * Returns a Crypto instance
  1662. *
  1663. * @return ICrypto
  1664. * @deprecated 20.0.0
  1665. */
  1666. public function getCrypto() {
  1667. return $this->get(ICrypto::class);
  1668. }
  1669. /**
  1670. * Returns a Hasher instance
  1671. *
  1672. * @return IHasher
  1673. * @deprecated 20.0.0
  1674. */
  1675. public function getHasher() {
  1676. return $this->get(IHasher::class);
  1677. }
  1678. /**
  1679. * Returns a CredentialsManager instance
  1680. *
  1681. * @return ICredentialsManager
  1682. * @deprecated 20.0.0
  1683. */
  1684. public function getCredentialsManager() {
  1685. return $this->get(ICredentialsManager::class);
  1686. }
  1687. /**
  1688. * Get the certificate manager
  1689. *
  1690. * @return \OCP\ICertificateManager
  1691. */
  1692. public function getCertificateManager() {
  1693. return $this->get(ICertificateManager::class);
  1694. }
  1695. /**
  1696. * Returns an instance of the HTTP client service
  1697. *
  1698. * @return IClientService
  1699. * @deprecated 20.0.0
  1700. */
  1701. public function getHTTPClientService() {
  1702. return $this->get(IClientService::class);
  1703. }
  1704. /**
  1705. * Create a new event source
  1706. *
  1707. * @return \OCP\IEventSource
  1708. * @deprecated 20.0.0
  1709. */
  1710. public function createEventSource() {
  1711. return new \OC_EventSource();
  1712. }
  1713. /**
  1714. * Get the active event logger
  1715. *
  1716. * The returned logger only logs data when debug mode is enabled
  1717. *
  1718. * @return IEventLogger
  1719. * @deprecated 20.0.0
  1720. */
  1721. public function getEventLogger() {
  1722. return $this->get(IEventLogger::class);
  1723. }
  1724. /**
  1725. * Get the active query logger
  1726. *
  1727. * The returned logger only logs data when debug mode is enabled
  1728. *
  1729. * @return IQueryLogger
  1730. * @deprecated 20.0.0
  1731. */
  1732. public function getQueryLogger() {
  1733. return $this->get(IQueryLogger::class);
  1734. }
  1735. /**
  1736. * Get the manager for temporary files and folders
  1737. *
  1738. * @return \OCP\ITempManager
  1739. * @deprecated 20.0.0
  1740. */
  1741. public function getTempManager() {
  1742. return $this->get(ITempManager::class);
  1743. }
  1744. /**
  1745. * Get the app manager
  1746. *
  1747. * @return \OCP\App\IAppManager
  1748. * @deprecated 20.0.0
  1749. */
  1750. public function getAppManager() {
  1751. return $this->get(IAppManager::class);
  1752. }
  1753. /**
  1754. * Creates a new mailer
  1755. *
  1756. * @return IMailer
  1757. * @deprecated 20.0.0
  1758. */
  1759. public function getMailer() {
  1760. return $this->get(IMailer::class);
  1761. }
  1762. /**
  1763. * Get the webroot
  1764. *
  1765. * @return string
  1766. * @deprecated 20.0.0
  1767. */
  1768. public function getWebRoot() {
  1769. return $this->webRoot;
  1770. }
  1771. /**
  1772. * @return \OC\OCSClient
  1773. * @deprecated 20.0.0
  1774. */
  1775. public function getOcsClient() {
  1776. return $this->get('OcsClient');
  1777. }
  1778. /**
  1779. * @return IDateTimeZone
  1780. * @deprecated 20.0.0
  1781. */
  1782. public function getDateTimeZone() {
  1783. return $this->get(IDateTimeZone::class);
  1784. }
  1785. /**
  1786. * @return IDateTimeFormatter
  1787. * @deprecated 20.0.0
  1788. */
  1789. public function getDateTimeFormatter() {
  1790. return $this->get(IDateTimeFormatter::class);
  1791. }
  1792. /**
  1793. * @return IMountProviderCollection
  1794. * @deprecated 20.0.0
  1795. */
  1796. public function getMountProviderCollection() {
  1797. return $this->get(IMountProviderCollection::class);
  1798. }
  1799. /**
  1800. * Get the IniWrapper
  1801. *
  1802. * @return IniGetWrapper
  1803. * @deprecated 20.0.0
  1804. */
  1805. public function getIniWrapper() {
  1806. return $this->get(IniGetWrapper::class);
  1807. }
  1808. /**
  1809. * @return \OCP\Command\IBus
  1810. * @deprecated 20.0.0
  1811. */
  1812. public function getCommandBus() {
  1813. return $this->get(IBus::class);
  1814. }
  1815. /**
  1816. * Get the trusted domain helper
  1817. *
  1818. * @return TrustedDomainHelper
  1819. * @deprecated 20.0.0
  1820. */
  1821. public function getTrustedDomainHelper() {
  1822. return $this->get(TrustedDomainHelper::class);
  1823. }
  1824. /**
  1825. * Get the locking provider
  1826. *
  1827. * @return ILockingProvider
  1828. * @since 8.1.0
  1829. * @deprecated 20.0.0
  1830. */
  1831. public function getLockingProvider() {
  1832. return $this->get(ILockingProvider::class);
  1833. }
  1834. /**
  1835. * @return IMountManager
  1836. * @deprecated 20.0.0
  1837. **/
  1838. public function getMountManager() {
  1839. return $this->get(IMountManager::class);
  1840. }
  1841. /**
  1842. * @return IUserMountCache
  1843. * @deprecated 20.0.0
  1844. */
  1845. public function getUserMountCache() {
  1846. return $this->get(IUserMountCache::class);
  1847. }
  1848. /**
  1849. * Get the MimeTypeDetector
  1850. *
  1851. * @return IMimeTypeDetector
  1852. * @deprecated 20.0.0
  1853. */
  1854. public function getMimeTypeDetector() {
  1855. return $this->get(IMimeTypeDetector::class);
  1856. }
  1857. /**
  1858. * Get the MimeTypeLoader
  1859. *
  1860. * @return IMimeTypeLoader
  1861. * @deprecated 20.0.0
  1862. */
  1863. public function getMimeTypeLoader() {
  1864. return $this->get(IMimeTypeLoader::class);
  1865. }
  1866. /**
  1867. * Get the manager of all the capabilities
  1868. *
  1869. * @return CapabilitiesManager
  1870. * @deprecated 20.0.0
  1871. */
  1872. public function getCapabilitiesManager() {
  1873. return $this->get(CapabilitiesManager::class);
  1874. }
  1875. /**
  1876. * Get the EventDispatcher
  1877. *
  1878. * @return EventDispatcherInterface
  1879. * @since 8.2.0
  1880. * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher
  1881. */
  1882. public function getEventDispatcher() {
  1883. return $this->get(\OC\EventDispatcher\SymfonyAdapter::class);
  1884. }
  1885. /**
  1886. * Get the Notification Manager
  1887. *
  1888. * @return \OCP\Notification\IManager
  1889. * @since 8.2.0
  1890. * @deprecated 20.0.0
  1891. */
  1892. public function getNotificationManager() {
  1893. return $this->get(\OCP\Notification\IManager::class);
  1894. }
  1895. /**
  1896. * @return ICommentsManager
  1897. * @deprecated 20.0.0
  1898. */
  1899. public function getCommentsManager() {
  1900. return $this->get(ICommentsManager::class);
  1901. }
  1902. /**
  1903. * @return \OCA\Theming\ThemingDefaults
  1904. * @deprecated 20.0.0
  1905. */
  1906. public function getThemingDefaults() {
  1907. return $this->get('ThemingDefaults');
  1908. }
  1909. /**
  1910. * @return \OC\IntegrityCheck\Checker
  1911. * @deprecated 20.0.0
  1912. */
  1913. public function getIntegrityCodeChecker() {
  1914. return $this->get('IntegrityCodeChecker');
  1915. }
  1916. /**
  1917. * @return \OC\Session\CryptoWrapper
  1918. * @deprecated 20.0.0
  1919. */
  1920. public function getSessionCryptoWrapper() {
  1921. return $this->get('CryptoWrapper');
  1922. }
  1923. /**
  1924. * @return CsrfTokenManager
  1925. * @deprecated 20.0.0
  1926. */
  1927. public function getCsrfTokenManager() {
  1928. return $this->get(CsrfTokenManager::class);
  1929. }
  1930. /**
  1931. * @return Throttler
  1932. * @deprecated 20.0.0
  1933. */
  1934. public function getBruteForceThrottler() {
  1935. return $this->get(Throttler::class);
  1936. }
  1937. /**
  1938. * @return IContentSecurityPolicyManager
  1939. * @deprecated 20.0.0
  1940. */
  1941. public function getContentSecurityPolicyManager() {
  1942. return $this->get(ContentSecurityPolicyManager::class);
  1943. }
  1944. /**
  1945. * @return ContentSecurityPolicyNonceManager
  1946. * @deprecated 20.0.0
  1947. */
  1948. public function getContentSecurityPolicyNonceManager() {
  1949. return $this->get(ContentSecurityPolicyNonceManager::class);
  1950. }
  1951. /**
  1952. * Not a public API as of 8.2, wait for 9.0
  1953. *
  1954. * @return \OCA\Files_External\Service\BackendService
  1955. * @deprecated 20.0.0
  1956. */
  1957. public function getStoragesBackendService() {
  1958. return $this->get(BackendService::class);
  1959. }
  1960. /**
  1961. * Not a public API as of 8.2, wait for 9.0
  1962. *
  1963. * @return \OCA\Files_External\Service\GlobalStoragesService
  1964. * @deprecated 20.0.0
  1965. */
  1966. public function getGlobalStoragesService() {
  1967. return $this->get(GlobalStoragesService::class);
  1968. }
  1969. /**
  1970. * Not a public API as of 8.2, wait for 9.0
  1971. *
  1972. * @return \OCA\Files_External\Service\UserGlobalStoragesService
  1973. * @deprecated 20.0.0
  1974. */
  1975. public function getUserGlobalStoragesService() {
  1976. return $this->get(UserGlobalStoragesService::class);
  1977. }
  1978. /**
  1979. * Not a public API as of 8.2, wait for 9.0
  1980. *
  1981. * @return \OCA\Files_External\Service\UserStoragesService
  1982. * @deprecated 20.0.0
  1983. */
  1984. public function getUserStoragesService() {
  1985. return $this->get(UserStoragesService::class);
  1986. }
  1987. /**
  1988. * @return \OCP\Share\IManager
  1989. * @deprecated 20.0.0
  1990. */
  1991. public function getShareManager() {
  1992. return $this->get(\OCP\Share\IManager::class);
  1993. }
  1994. /**
  1995. * @return \OCP\Collaboration\Collaborators\ISearch
  1996. * @deprecated 20.0.0
  1997. */
  1998. public function getCollaboratorSearch() {
  1999. return $this->get(\OCP\Collaboration\Collaborators\ISearch::class);
  2000. }
  2001. /**
  2002. * @return \OCP\Collaboration\AutoComplete\IManager
  2003. * @deprecated 20.0.0
  2004. */
  2005. public function getAutoCompleteManager() {
  2006. return $this->get(IManager::class);
  2007. }
  2008. /**
  2009. * Returns the LDAP Provider
  2010. *
  2011. * @return \OCP\LDAP\ILDAPProvider
  2012. * @deprecated 20.0.0
  2013. */
  2014. public function getLDAPProvider() {
  2015. return $this->get('LDAPProvider');
  2016. }
  2017. /**
  2018. * @return \OCP\Settings\IManager
  2019. * @deprecated 20.0.0
  2020. */
  2021. public function getSettingsManager() {
  2022. return $this->get(\OC\Settings\Manager::class);
  2023. }
  2024. /**
  2025. * @return \OCP\Files\IAppData
  2026. * @deprecated 20.0.0
  2027. */
  2028. public function getAppDataDir($app) {
  2029. /** @var \OC\Files\AppData\Factory $factory */
  2030. $factory = $this->get(\OC\Files\AppData\Factory::class);
  2031. return $factory->get($app);
  2032. }
  2033. /**
  2034. * @return \OCP\Lockdown\ILockdownManager
  2035. * @deprecated 20.0.0
  2036. */
  2037. public function getLockdownManager() {
  2038. return $this->get('LockdownManager');
  2039. }
  2040. /**
  2041. * @return \OCP\Federation\ICloudIdManager
  2042. * @deprecated 20.0.0
  2043. */
  2044. public function getCloudIdManager() {
  2045. return $this->get(ICloudIdManager::class);
  2046. }
  2047. /**
  2048. * @return \OCP\GlobalScale\IConfig
  2049. * @deprecated 20.0.0
  2050. */
  2051. public function getGlobalScaleConfig() {
  2052. return $this->get(IConfig::class);
  2053. }
  2054. /**
  2055. * @return \OCP\Federation\ICloudFederationProviderManager
  2056. * @deprecated 20.0.0
  2057. */
  2058. public function getCloudFederationProviderManager() {
  2059. return $this->get(ICloudFederationProviderManager::class);
  2060. }
  2061. /**
  2062. * @return \OCP\Remote\Api\IApiFactory
  2063. * @deprecated 20.0.0
  2064. */
  2065. public function getRemoteApiFactory() {
  2066. return $this->get(IApiFactory::class);
  2067. }
  2068. /**
  2069. * @return \OCP\Federation\ICloudFederationFactory
  2070. * @deprecated 20.0.0
  2071. */
  2072. public function getCloudFederationFactory() {
  2073. return $this->get(ICloudFederationFactory::class);
  2074. }
  2075. /**
  2076. * @return \OCP\Remote\IInstanceFactory
  2077. * @deprecated 20.0.0
  2078. */
  2079. public function getRemoteInstanceFactory() {
  2080. return $this->get(IInstanceFactory::class);
  2081. }
  2082. /**
  2083. * @return IStorageFactory
  2084. * @deprecated 20.0.0
  2085. */
  2086. public function getStorageFactory() {
  2087. return $this->get(IStorageFactory::class);
  2088. }
  2089. /**
  2090. * Get the Preview GeneratorHelper
  2091. *
  2092. * @return GeneratorHelper
  2093. * @since 17.0.0
  2094. * @deprecated 20.0.0
  2095. */
  2096. public function getGeneratorHelper() {
  2097. return $this->get(\OC\Preview\GeneratorHelper::class);
  2098. }
  2099. private function registerDeprecatedAlias(string $alias, string $target) {
  2100. $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) {
  2101. try {
  2102. /** @var ILogger $logger */
  2103. $logger = $container->get(ILogger::class);
  2104. $logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']);
  2105. } catch (ContainerExceptionInterface $e) {
  2106. // Could not get logger. Continue
  2107. }
  2108. return $container->get($target);
  2109. }, false);
  2110. }
  2111. }