Application.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Roeland Jago Douma <roeland@famdouma.nl>
  6. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCA\Files_Versions\AppInfo;
  24. use OCA\DAV\CalDAV\Proxy\ProxyMapper;
  25. use OCA\DAV\Connector\Sabre\Principal;
  26. use OCA\Files_Versions\Versions\IVersionManager;
  27. use OCA\Files_Versions\Versions\VersionManager;
  28. use OCP\AppFramework\App;
  29. use OCP\AppFramework\IAppContainer;
  30. use OCA\Files_Versions\Capabilities;
  31. class Application extends App {
  32. public function __construct(array $urlParams = array()) {
  33. parent::__construct('files_versions', $urlParams);
  34. $container = $this->getContainer();
  35. /*
  36. * Register capabilities
  37. */
  38. $container->registerCapability(Capabilities::class);
  39. /*
  40. * Register $principalBackend for the DAV collection
  41. */
  42. $container->registerService('principalBackend', function (IAppContainer $c) {
  43. $server = $c->getServer();
  44. return new Principal(
  45. $server->getUserManager(),
  46. $server->getGroupManager(),
  47. $server->getShareManager(),
  48. $server->getUserSession(),
  49. $server->getAppManager(),
  50. $server->query(ProxyMapper::class)
  51. );
  52. });
  53. $container->registerService(IVersionManager::class, function(IAppContainer $c) {
  54. return new VersionManager();
  55. });
  56. $this->registerVersionBackends();
  57. }
  58. public function registerVersionBackends() {
  59. $server = $this->getContainer()->getServer();
  60. $appManager = $server->getAppManager();
  61. foreach($appManager->getInstalledApps() as $app) {
  62. $appInfo = $appManager->getAppInfo($app);
  63. if (isset($appInfo['versions'])) {
  64. $backends = $appInfo['versions'];
  65. foreach($backends as $backend) {
  66. if (isset($backend['@value'])) {
  67. $this->loadBackend($backend);
  68. } else {
  69. foreach ($backend as $singleBackend) {
  70. $this->loadBackend($singleBackend);
  71. }
  72. }
  73. }
  74. }
  75. }
  76. }
  77. private function loadBackend(array $backend) {
  78. $server = $this->getContainer()->getServer();
  79. $logger = $server->getLogger();
  80. /** @var IVersionManager $versionManager */
  81. $versionManager = $this->getContainer()->getServer()->query(IVersionManager::class);
  82. $class = $backend['@value'];
  83. $for = $backend['@attributes']['for'];
  84. try {
  85. $backendObject = $server->query($class);
  86. $versionManager->registerBackend($for, $backendObject);
  87. } catch (\Exception $e) {
  88. $logger->logException($e);
  89. }
  90. }
  91. }