@@ -43,185 +43,185 @@ |
||
| 43 | 43 | |
| 44 | 44 | class Application extends App { |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Application constructor. |
|
| 48 | - */ |
|
| 49 | - public function __construct() { |
|
| 50 | - parent::__construct('dav'); |
|
| 51 | - |
|
| 52 | - $container = $this->getContainer(); |
|
| 53 | - $server = $container->getServer(); |
|
| 54 | - |
|
| 55 | - $container->registerService(PhotoCache::class, function(SimpleContainer $s) use ($server) { |
|
| 56 | - return new PhotoCache( |
|
| 57 | - $server->getAppDataDir('dav-photocache'), |
|
| 58 | - $server->getLogger() |
|
| 59 | - ); |
|
| 60 | - }); |
|
| 61 | - |
|
| 62 | - /* |
|
| 46 | + /** |
|
| 47 | + * Application constructor. |
|
| 48 | + */ |
|
| 49 | + public function __construct() { |
|
| 50 | + parent::__construct('dav'); |
|
| 51 | + |
|
| 52 | + $container = $this->getContainer(); |
|
| 53 | + $server = $container->getServer(); |
|
| 54 | + |
|
| 55 | + $container->registerService(PhotoCache::class, function(SimpleContainer $s) use ($server) { |
|
| 56 | + return new PhotoCache( |
|
| 57 | + $server->getAppDataDir('dav-photocache'), |
|
| 58 | + $server->getLogger() |
|
| 59 | + ); |
|
| 60 | + }); |
|
| 61 | + |
|
| 62 | + /* |
|
| 63 | 63 | * Register capabilities |
| 64 | 64 | */ |
| 65 | - $container->registerCapability(Capabilities::class); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @param IContactsManager $contactsManager |
|
| 70 | - * @param string $userID |
|
| 71 | - */ |
|
| 72 | - public function setupContactsProvider(IContactsManager $contactsManager, $userID) { |
|
| 73 | - /** @var ContactsManager $cm */ |
|
| 74 | - $cm = $this->getContainer()->query(ContactsManager::class); |
|
| 75 | - $urlGenerator = $this->getContainer()->getServer()->getURLGenerator(); |
|
| 76 | - $cm->setupContactsProvider($contactsManager, $userID, $urlGenerator); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @param IContactsManager $contactsManager |
|
| 81 | - */ |
|
| 82 | - public function setupSystemContactsProvider(IContactsManager $contactsManager) { |
|
| 83 | - /** @var ContactsManager $cm */ |
|
| 84 | - $cm = $this->getContainer()->query(ContactsManager::class); |
|
| 85 | - $urlGenerator = $this->getContainer()->getServer()->getURLGenerator(); |
|
| 86 | - $cm->setupSystemContactsProvider($contactsManager, $urlGenerator); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @param ICalendarManager $calendarManager |
|
| 91 | - * @param string $userId |
|
| 92 | - */ |
|
| 93 | - public function setupCalendarProvider(ICalendarManager $calendarManager, $userId) { |
|
| 94 | - $cm = $this->getContainer()->query(CalendarManager::class); |
|
| 95 | - $cm->setupCalendarProvider($calendarManager, $userId); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - public function registerHooks() { |
|
| 99 | - /** @var HookManager $hm */ |
|
| 100 | - $hm = $this->getContainer()->query(HookManager::class); |
|
| 101 | - $hm->setup(); |
|
| 102 | - |
|
| 103 | - $dispatcher = $this->getContainer()->getServer()->getEventDispatcher(); |
|
| 104 | - |
|
| 105 | - // first time login event setup |
|
| 106 | - $dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) { |
|
| 107 | - if ($event instanceof GenericEvent) { |
|
| 108 | - $hm->firstLogin($event->getSubject()); |
|
| 109 | - } |
|
| 110 | - }); |
|
| 111 | - |
|
| 112 | - // carddav/caldav sync event setup |
|
| 113 | - $listener = function($event) { |
|
| 114 | - if ($event instanceof GenericEvent) { |
|
| 115 | - /** @var BirthdayService $b */ |
|
| 116 | - $b = $this->getContainer()->query(BirthdayService::class); |
|
| 117 | - $b->onCardChanged( |
|
| 118 | - $event->getArgument('addressBookId'), |
|
| 119 | - $event->getArgument('cardUri'), |
|
| 120 | - $event->getArgument('cardData') |
|
| 121 | - ); |
|
| 122 | - } |
|
| 123 | - }; |
|
| 124 | - |
|
| 125 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $listener); |
|
| 126 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $listener); |
|
| 127 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function($event) { |
|
| 128 | - if ($event instanceof GenericEvent) { |
|
| 129 | - /** @var BirthdayService $b */ |
|
| 130 | - $b = $this->getContainer()->query(BirthdayService::class); |
|
| 131 | - $b->onCardDeleted( |
|
| 132 | - $event->getArgument('addressBookId'), |
|
| 133 | - $event->getArgument('cardUri') |
|
| 134 | - ); |
|
| 135 | - } |
|
| 136 | - }); |
|
| 137 | - |
|
| 138 | - $clearPhotoCache = function($event) { |
|
| 139 | - if ($event instanceof GenericEvent) { |
|
| 140 | - /** @var PhotoCache $p */ |
|
| 141 | - $p = $this->getContainer()->query(PhotoCache::class); |
|
| 142 | - $p->delete( |
|
| 143 | - $event->getArgument('addressBookId'), |
|
| 144 | - $event->getArgument('cardUri') |
|
| 145 | - ); |
|
| 146 | - } |
|
| 147 | - }; |
|
| 148 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache); |
|
| 149 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache); |
|
| 150 | - |
|
| 151 | - $dispatcher->addListener('OC\AccountManager::userUpdated', function(GenericEvent $event) { |
|
| 152 | - $user = $event->getSubject(); |
|
| 153 | - $syncService = $this->getContainer()->query(SyncService::class); |
|
| 154 | - $syncService->updateUser($user); |
|
| 155 | - }); |
|
| 156 | - |
|
| 157 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function(GenericEvent $event) { |
|
| 158 | - /** @var Backend $backend */ |
|
| 159 | - $backend = $this->getContainer()->query(Backend::class); |
|
| 160 | - $backend->onCalendarAdd( |
|
| 161 | - $event->getArgument('calendarData') |
|
| 162 | - ); |
|
| 163 | - }); |
|
| 164 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function(GenericEvent $event) { |
|
| 165 | - /** @var Backend $backend */ |
|
| 166 | - $backend = $this->getContainer()->query(Backend::class); |
|
| 167 | - $backend->onCalendarUpdate( |
|
| 168 | - $event->getArgument('calendarData'), |
|
| 169 | - $event->getArgument('shares'), |
|
| 170 | - $event->getArgument('propertyMutations') |
|
| 171 | - ); |
|
| 172 | - }); |
|
| 173 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function(GenericEvent $event) { |
|
| 174 | - /** @var Backend $backend */ |
|
| 175 | - $backend = $this->getContainer()->query(Backend::class); |
|
| 176 | - $backend->onCalendarDelete( |
|
| 177 | - $event->getArgument('calendarData'), |
|
| 178 | - $event->getArgument('shares') |
|
| 179 | - ); |
|
| 180 | - }); |
|
| 181 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function(GenericEvent $event) { |
|
| 182 | - /** @var Backend $backend */ |
|
| 183 | - $backend = $this->getContainer()->query(Backend::class); |
|
| 184 | - $backend->onCalendarUpdateShares( |
|
| 185 | - $event->getArgument('calendarData'), |
|
| 186 | - $event->getArgument('shares'), |
|
| 187 | - $event->getArgument('add'), |
|
| 188 | - $event->getArgument('remove') |
|
| 189 | - ); |
|
| 190 | - }); |
|
| 191 | - |
|
| 192 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::publishCalendar', function(GenericEvent $event) { |
|
| 193 | - /** @var Backend $backend */ |
|
| 194 | - $backend = $this->getContainer()->query(Backend::class); |
|
| 195 | - $backend->onCalendarPublication( |
|
| 196 | - $event->getArgument('calendarData'), |
|
| 197 | - $event->getArgument('public') |
|
| 198 | - ); |
|
| 199 | - }); |
|
| 200 | - |
|
| 201 | - $listener = function(GenericEvent $event, $eventName) { |
|
| 202 | - /** @var Backend $backend */ |
|
| 203 | - $backend = $this->getContainer()->query(Backend::class); |
|
| 204 | - |
|
| 205 | - $subject = Event::SUBJECT_OBJECT_ADD; |
|
| 206 | - if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') { |
|
| 207 | - $subject = Event::SUBJECT_OBJECT_UPDATE; |
|
| 208 | - } else if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') { |
|
| 209 | - $subject = Event::SUBJECT_OBJECT_DELETE; |
|
| 210 | - } |
|
| 211 | - $backend->onTouchCalendarObject( |
|
| 212 | - $subject, |
|
| 213 | - $event->getArgument('calendarData'), |
|
| 214 | - $event->getArgument('shares'), |
|
| 215 | - $event->getArgument('objectData') |
|
| 216 | - ); |
|
| 217 | - }; |
|
| 218 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener); |
|
| 219 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener); |
|
| 220 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - public function getSyncService() { |
|
| 224 | - return $this->getContainer()->query(SyncService::class); |
|
| 225 | - } |
|
| 65 | + $container->registerCapability(Capabilities::class); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @param IContactsManager $contactsManager |
|
| 70 | + * @param string $userID |
|
| 71 | + */ |
|
| 72 | + public function setupContactsProvider(IContactsManager $contactsManager, $userID) { |
|
| 73 | + /** @var ContactsManager $cm */ |
|
| 74 | + $cm = $this->getContainer()->query(ContactsManager::class); |
|
| 75 | + $urlGenerator = $this->getContainer()->getServer()->getURLGenerator(); |
|
| 76 | + $cm->setupContactsProvider($contactsManager, $userID, $urlGenerator); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @param IContactsManager $contactsManager |
|
| 81 | + */ |
|
| 82 | + public function setupSystemContactsProvider(IContactsManager $contactsManager) { |
|
| 83 | + /** @var ContactsManager $cm */ |
|
| 84 | + $cm = $this->getContainer()->query(ContactsManager::class); |
|
| 85 | + $urlGenerator = $this->getContainer()->getServer()->getURLGenerator(); |
|
| 86 | + $cm->setupSystemContactsProvider($contactsManager, $urlGenerator); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @param ICalendarManager $calendarManager |
|
| 91 | + * @param string $userId |
|
| 92 | + */ |
|
| 93 | + public function setupCalendarProvider(ICalendarManager $calendarManager, $userId) { |
|
| 94 | + $cm = $this->getContainer()->query(CalendarManager::class); |
|
| 95 | + $cm->setupCalendarProvider($calendarManager, $userId); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + public function registerHooks() { |
|
| 99 | + /** @var HookManager $hm */ |
|
| 100 | + $hm = $this->getContainer()->query(HookManager::class); |
|
| 101 | + $hm->setup(); |
|
| 102 | + |
|
| 103 | + $dispatcher = $this->getContainer()->getServer()->getEventDispatcher(); |
|
| 104 | + |
|
| 105 | + // first time login event setup |
|
| 106 | + $dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) { |
|
| 107 | + if ($event instanceof GenericEvent) { |
|
| 108 | + $hm->firstLogin($event->getSubject()); |
|
| 109 | + } |
|
| 110 | + }); |
|
| 111 | + |
|
| 112 | + // carddav/caldav sync event setup |
|
| 113 | + $listener = function($event) { |
|
| 114 | + if ($event instanceof GenericEvent) { |
|
| 115 | + /** @var BirthdayService $b */ |
|
| 116 | + $b = $this->getContainer()->query(BirthdayService::class); |
|
| 117 | + $b->onCardChanged( |
|
| 118 | + $event->getArgument('addressBookId'), |
|
| 119 | + $event->getArgument('cardUri'), |
|
| 120 | + $event->getArgument('cardData') |
|
| 121 | + ); |
|
| 122 | + } |
|
| 123 | + }; |
|
| 124 | + |
|
| 125 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $listener); |
|
| 126 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $listener); |
|
| 127 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function($event) { |
|
| 128 | + if ($event instanceof GenericEvent) { |
|
| 129 | + /** @var BirthdayService $b */ |
|
| 130 | + $b = $this->getContainer()->query(BirthdayService::class); |
|
| 131 | + $b->onCardDeleted( |
|
| 132 | + $event->getArgument('addressBookId'), |
|
| 133 | + $event->getArgument('cardUri') |
|
| 134 | + ); |
|
| 135 | + } |
|
| 136 | + }); |
|
| 137 | + |
|
| 138 | + $clearPhotoCache = function($event) { |
|
| 139 | + if ($event instanceof GenericEvent) { |
|
| 140 | + /** @var PhotoCache $p */ |
|
| 141 | + $p = $this->getContainer()->query(PhotoCache::class); |
|
| 142 | + $p->delete( |
|
| 143 | + $event->getArgument('addressBookId'), |
|
| 144 | + $event->getArgument('cardUri') |
|
| 145 | + ); |
|
| 146 | + } |
|
| 147 | + }; |
|
| 148 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache); |
|
| 149 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache); |
|
| 150 | + |
|
| 151 | + $dispatcher->addListener('OC\AccountManager::userUpdated', function(GenericEvent $event) { |
|
| 152 | + $user = $event->getSubject(); |
|
| 153 | + $syncService = $this->getContainer()->query(SyncService::class); |
|
| 154 | + $syncService->updateUser($user); |
|
| 155 | + }); |
|
| 156 | + |
|
| 157 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function(GenericEvent $event) { |
|
| 158 | + /** @var Backend $backend */ |
|
| 159 | + $backend = $this->getContainer()->query(Backend::class); |
|
| 160 | + $backend->onCalendarAdd( |
|
| 161 | + $event->getArgument('calendarData') |
|
| 162 | + ); |
|
| 163 | + }); |
|
| 164 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function(GenericEvent $event) { |
|
| 165 | + /** @var Backend $backend */ |
|
| 166 | + $backend = $this->getContainer()->query(Backend::class); |
|
| 167 | + $backend->onCalendarUpdate( |
|
| 168 | + $event->getArgument('calendarData'), |
|
| 169 | + $event->getArgument('shares'), |
|
| 170 | + $event->getArgument('propertyMutations') |
|
| 171 | + ); |
|
| 172 | + }); |
|
| 173 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function(GenericEvent $event) { |
|
| 174 | + /** @var Backend $backend */ |
|
| 175 | + $backend = $this->getContainer()->query(Backend::class); |
|
| 176 | + $backend->onCalendarDelete( |
|
| 177 | + $event->getArgument('calendarData'), |
|
| 178 | + $event->getArgument('shares') |
|
| 179 | + ); |
|
| 180 | + }); |
|
| 181 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function(GenericEvent $event) { |
|
| 182 | + /** @var Backend $backend */ |
|
| 183 | + $backend = $this->getContainer()->query(Backend::class); |
|
| 184 | + $backend->onCalendarUpdateShares( |
|
| 185 | + $event->getArgument('calendarData'), |
|
| 186 | + $event->getArgument('shares'), |
|
| 187 | + $event->getArgument('add'), |
|
| 188 | + $event->getArgument('remove') |
|
| 189 | + ); |
|
| 190 | + }); |
|
| 191 | + |
|
| 192 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::publishCalendar', function(GenericEvent $event) { |
|
| 193 | + /** @var Backend $backend */ |
|
| 194 | + $backend = $this->getContainer()->query(Backend::class); |
|
| 195 | + $backend->onCalendarPublication( |
|
| 196 | + $event->getArgument('calendarData'), |
|
| 197 | + $event->getArgument('public') |
|
| 198 | + ); |
|
| 199 | + }); |
|
| 200 | + |
|
| 201 | + $listener = function(GenericEvent $event, $eventName) { |
|
| 202 | + /** @var Backend $backend */ |
|
| 203 | + $backend = $this->getContainer()->query(Backend::class); |
|
| 204 | + |
|
| 205 | + $subject = Event::SUBJECT_OBJECT_ADD; |
|
| 206 | + if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') { |
|
| 207 | + $subject = Event::SUBJECT_OBJECT_UPDATE; |
|
| 208 | + } else if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') { |
|
| 209 | + $subject = Event::SUBJECT_OBJECT_DELETE; |
|
| 210 | + } |
|
| 211 | + $backend->onTouchCalendarObject( |
|
| 212 | + $subject, |
|
| 213 | + $event->getArgument('calendarData'), |
|
| 214 | + $event->getArgument('shares'), |
|
| 215 | + $event->getArgument('objectData') |
|
| 216 | + ); |
|
| 217 | + }; |
|
| 218 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener); |
|
| 219 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener); |
|
| 220 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + public function getSyncService() { |
|
| 224 | + return $this->getContainer()->query(SyncService::class); |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | 227 | } |
@@ -47,101 +47,101 @@ |
||
| 47 | 47 | */ |
| 48 | 48 | class App { |
| 49 | 49 | |
| 50 | - /** @var IAppContainer */ |
|
| 51 | - private $container; |
|
| 50 | + /** @var IAppContainer */ |
|
| 51 | + private $container; |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Turns an app id into a namespace by convetion. The id is split at the |
|
| 55 | - * underscores, all parts are camelcased and reassembled. e.g.: |
|
| 56 | - * some_app_id -> OCA\SomeAppId |
|
| 57 | - * @param string $appId the app id |
|
| 58 | - * @param string $topNamespace the namespace which should be prepended to |
|
| 59 | - * the transformed app id, defaults to OCA\ |
|
| 60 | - * @return string the starting namespace for the app |
|
| 61 | - * @since 8.0.0 |
|
| 62 | - */ |
|
| 63 | - public static function buildAppNamespace(string $appId, string $topNamespace='OCA\\'): string { |
|
| 64 | - return \OC\AppFramework\App::buildAppNamespace($appId, $topNamespace); |
|
| 65 | - } |
|
| 53 | + /** |
|
| 54 | + * Turns an app id into a namespace by convetion. The id is split at the |
|
| 55 | + * underscores, all parts are camelcased and reassembled. e.g.: |
|
| 56 | + * some_app_id -> OCA\SomeAppId |
|
| 57 | + * @param string $appId the app id |
|
| 58 | + * @param string $topNamespace the namespace which should be prepended to |
|
| 59 | + * the transformed app id, defaults to OCA\ |
|
| 60 | + * @return string the starting namespace for the app |
|
| 61 | + * @since 8.0.0 |
|
| 62 | + */ |
|
| 63 | + public static function buildAppNamespace(string $appId, string $topNamespace='OCA\\'): string { |
|
| 64 | + return \OC\AppFramework\App::buildAppNamespace($appId, $topNamespace); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @param string $appName |
|
| 70 | - * @param array $urlParams an array with variables extracted from the routes |
|
| 71 | - * @since 6.0.0 |
|
| 72 | - */ |
|
| 73 | - public function __construct(string $appName, array $urlParams = []) { |
|
| 74 | - try { |
|
| 75 | - $this->container = \OC::$server->getRegisteredAppContainer($appName); |
|
| 76 | - } catch (QueryException $e) { |
|
| 77 | - $this->container = new \OC\AppFramework\DependencyInjection\DIContainer($appName, $urlParams); |
|
| 78 | - } |
|
| 79 | - } |
|
| 68 | + /** |
|
| 69 | + * @param string $appName |
|
| 70 | + * @param array $urlParams an array with variables extracted from the routes |
|
| 71 | + * @since 6.0.0 |
|
| 72 | + */ |
|
| 73 | + public function __construct(string $appName, array $urlParams = []) { |
|
| 74 | + try { |
|
| 75 | + $this->container = \OC::$server->getRegisteredAppContainer($appName); |
|
| 76 | + } catch (QueryException $e) { |
|
| 77 | + $this->container = new \OC\AppFramework\DependencyInjection\DIContainer($appName, $urlParams); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * @return IAppContainer |
|
| 83 | - * @since 6.0.0 |
|
| 84 | - */ |
|
| 85 | - public function getContainer(): IAppContainer { |
|
| 86 | - return $this->container; |
|
| 87 | - } |
|
| 81 | + /** |
|
| 82 | + * @return IAppContainer |
|
| 83 | + * @since 6.0.0 |
|
| 84 | + */ |
|
| 85 | + public function getContainer(): IAppContainer { |
|
| 86 | + return $this->container; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * This function is to be called to create single routes and restful routes based on the given $routes array. |
|
| 91 | - * |
|
| 92 | - * Example code in routes.php of tasks app (it will register two restful resources): |
|
| 93 | - * $routes = array( |
|
| 94 | - * 'resources' => array( |
|
| 95 | - * 'lists' => array('url' => '/tasklists'), |
|
| 96 | - * 'tasks' => array('url' => '/tasklists/{listId}/tasks') |
|
| 97 | - * ) |
|
| 98 | - * ); |
|
| 99 | - * |
|
| 100 | - * $a = new TasksApp(); |
|
| 101 | - * $a->registerRoutes($this, $routes); |
|
| 102 | - * |
|
| 103 | - * @param \OCP\Route\IRouter $router |
|
| 104 | - * @param array $routes |
|
| 105 | - * @since 6.0.0 |
|
| 106 | - * @suppress PhanAccessMethodInternal |
|
| 107 | - */ |
|
| 108 | - public function registerRoutes(IRouter $router, array $routes) { |
|
| 109 | - $routeConfig = new RouteConfig($this->container, $router, $routes); |
|
| 110 | - $routeConfig->register(); |
|
| 111 | - } |
|
| 89 | + /** |
|
| 90 | + * This function is to be called to create single routes and restful routes based on the given $routes array. |
|
| 91 | + * |
|
| 92 | + * Example code in routes.php of tasks app (it will register two restful resources): |
|
| 93 | + * $routes = array( |
|
| 94 | + * 'resources' => array( |
|
| 95 | + * 'lists' => array('url' => '/tasklists'), |
|
| 96 | + * 'tasks' => array('url' => '/tasklists/{listId}/tasks') |
|
| 97 | + * ) |
|
| 98 | + * ); |
|
| 99 | + * |
|
| 100 | + * $a = new TasksApp(); |
|
| 101 | + * $a->registerRoutes($this, $routes); |
|
| 102 | + * |
|
| 103 | + * @param \OCP\Route\IRouter $router |
|
| 104 | + * @param array $routes |
|
| 105 | + * @since 6.0.0 |
|
| 106 | + * @suppress PhanAccessMethodInternal |
|
| 107 | + */ |
|
| 108 | + public function registerRoutes(IRouter $router, array $routes) { |
|
| 109 | + $routeConfig = new RouteConfig($this->container, $router, $routes); |
|
| 110 | + $routeConfig->register(); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * This function is called by the routing component to fire up the frameworks dispatch mechanism. |
|
| 115 | - * |
|
| 116 | - * Example code in routes.php of the task app: |
|
| 117 | - * $this->create('tasks_index', '/')->get()->action( |
|
| 118 | - * function($params){ |
|
| 119 | - * $app = new TaskApp($params); |
|
| 120 | - * $app->dispatch('PageController', 'index'); |
|
| 121 | - * } |
|
| 122 | - * ); |
|
| 123 | - * |
|
| 124 | - * |
|
| 125 | - * Example for for TaskApp implementation: |
|
| 126 | - * class TaskApp extends \OCP\AppFramework\App { |
|
| 127 | - * |
|
| 128 | - * public function __construct($params){ |
|
| 129 | - * parent::__construct('tasks', $params); |
|
| 130 | - * |
|
| 131 | - * $this->getContainer()->registerService('PageController', function(IAppContainer $c){ |
|
| 132 | - * $a = $c->query('API'); |
|
| 133 | - * $r = $c->query('Request'); |
|
| 134 | - * return new PageController($a, $r); |
|
| 135 | - * }); |
|
| 136 | - * } |
|
| 137 | - * } |
|
| 138 | - * |
|
| 139 | - * @param string $controllerName the name of the controller under which it is |
|
| 140 | - * stored in the DI container |
|
| 141 | - * @param string $methodName the method that you want to call |
|
| 142 | - * @since 6.0.0 |
|
| 143 | - */ |
|
| 144 | - public function dispatch(string $controllerName, string $methodName) { |
|
| 145 | - \OC\AppFramework\App::main($controllerName, $methodName, $this->container); |
|
| 146 | - } |
|
| 113 | + /** |
|
| 114 | + * This function is called by the routing component to fire up the frameworks dispatch mechanism. |
|
| 115 | + * |
|
| 116 | + * Example code in routes.php of the task app: |
|
| 117 | + * $this->create('tasks_index', '/')->get()->action( |
|
| 118 | + * function($params){ |
|
| 119 | + * $app = new TaskApp($params); |
|
| 120 | + * $app->dispatch('PageController', 'index'); |
|
| 121 | + * } |
|
| 122 | + * ); |
|
| 123 | + * |
|
| 124 | + * |
|
| 125 | + * Example for for TaskApp implementation: |
|
| 126 | + * class TaskApp extends \OCP\AppFramework\App { |
|
| 127 | + * |
|
| 128 | + * public function __construct($params){ |
|
| 129 | + * parent::__construct('tasks', $params); |
|
| 130 | + * |
|
| 131 | + * $this->getContainer()->registerService('PageController', function(IAppContainer $c){ |
|
| 132 | + * $a = $c->query('API'); |
|
| 133 | + * $r = $c->query('Request'); |
|
| 134 | + * return new PageController($a, $r); |
|
| 135 | + * }); |
|
| 136 | + * } |
|
| 137 | + * } |
|
| 138 | + * |
|
| 139 | + * @param string $controllerName the name of the controller under which it is |
|
| 140 | + * stored in the DI container |
|
| 141 | + * @param string $methodName the method that you want to call |
|
| 142 | + * @since 6.0.0 |
|
| 143 | + */ |
|
| 144 | + public function dispatch(string $controllerName, string $methodName) { |
|
| 145 | + \OC\AppFramework\App::main($controllerName, $methodName, $this->container); |
|
| 146 | + } |
|
| 147 | 147 | } |
@@ -35,118 +35,118 @@ |
||
| 35 | 35 | * @package OC |
| 36 | 36 | */ |
| 37 | 37 | class ServerContainer extends SimpleContainer { |
| 38 | - /** @var DIContainer[] */ |
|
| 39 | - protected $appContainers; |
|
| 40 | - |
|
| 41 | - /** @var string[] */ |
|
| 42 | - protected $hasNoAppContainer; |
|
| 43 | - |
|
| 44 | - /** @var string[] */ |
|
| 45 | - protected $namespaces; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * ServerContainer constructor. |
|
| 49 | - */ |
|
| 50 | - public function __construct() { |
|
| 51 | - parent::__construct(); |
|
| 52 | - $this->appContainers = []; |
|
| 53 | - $this->namespaces = []; |
|
| 54 | - $this->hasNoAppContainer = []; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param string $appName |
|
| 59 | - * @param string $appNamespace |
|
| 60 | - */ |
|
| 61 | - public function registerNamespace(string $appName, string $appNamespace): void { |
|
| 62 | - // Cut of OCA\ and lowercase |
|
| 63 | - $appNamespace = strtolower(substr($appNamespace, strrpos($appNamespace, '\\') + 1)); |
|
| 64 | - $this->namespaces[$appNamespace] = $appName; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @param string $appName |
|
| 69 | - * @param DIContainer $container |
|
| 70 | - */ |
|
| 71 | - public function registerAppContainer(string $appName, DIContainer $container): void { |
|
| 72 | - $this->appContainers[strtolower(App::buildAppNamespace($appName, ''))] = $container; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @param string $appName |
|
| 77 | - * @return DIContainer |
|
| 78 | - * @throws QueryException |
|
| 79 | - */ |
|
| 80 | - public function getRegisteredAppContainer(string $appName): DIContainer { |
|
| 81 | - if (isset($this->appContainers[strtolower(App::buildAppNamespace($appName, ''))])) { |
|
| 82 | - return $this->appContainers[strtolower(App::buildAppNamespace($appName, ''))]; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - throw new QueryException(); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @param string $namespace |
|
| 90 | - * @param string $sensitiveNamespace |
|
| 91 | - * @return DIContainer |
|
| 92 | - * @throws QueryException |
|
| 93 | - */ |
|
| 94 | - protected function getAppContainer(string $namespace, string $sensitiveNamespace): DIContainer { |
|
| 95 | - if (isset($this->appContainers[$namespace])) { |
|
| 96 | - return $this->appContainers[$namespace]; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - if (isset($this->namespaces[$namespace])) { |
|
| 100 | - if (!isset($this->hasNoAppContainer[$namespace])) { |
|
| 101 | - $applicationClassName = 'OCA\\' . $sensitiveNamespace . '\\AppInfo\\Application'; |
|
| 102 | - if (class_exists($applicationClassName)) { |
|
| 103 | - new $applicationClassName(); |
|
| 104 | - if (isset($this->appContainers[$namespace])) { |
|
| 105 | - return $this->appContainers[$namespace]; |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - $this->hasNoAppContainer[$namespace] = true; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return new DIContainer($this->namespaces[$namespace]); |
|
| 112 | - } |
|
| 113 | - throw new QueryException(); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @param string $name name of the service to query for |
|
| 118 | - * @return mixed registered service for the given $name |
|
| 119 | - * @throws QueryException if the query could not be resolved |
|
| 120 | - */ |
|
| 121 | - public function query($name) { |
|
| 122 | - $name = $this->sanitizeName($name); |
|
| 123 | - |
|
| 124 | - if (isset($this[$name])) { |
|
| 125 | - return $this[$name]; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - // In case the service starts with OCA\ we try to find the service in |
|
| 129 | - // the apps container first. |
|
| 130 | - if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 131 | - $segments = explode('\\', $name); |
|
| 132 | - try { |
|
| 133 | - $appContainer = $this->getAppContainer(strtolower($segments[1]), $segments[1]); |
|
| 134 | - return $appContainer->queryNoFallback($name); |
|
| 135 | - } catch (QueryException $e) { |
|
| 136 | - // Didn't find the service or the respective app container, |
|
| 137 | - // ignore it and fall back to the core container. |
|
| 138 | - } |
|
| 139 | - } else if (strpos($name, 'OC\\Settings\\') === 0 && substr_count($name, '\\') >= 3) { |
|
| 140 | - $segments = explode('\\', $name); |
|
| 141 | - try { |
|
| 142 | - $appContainer = $this->getAppContainer(strtolower($segments[1]), $segments[1]); |
|
| 143 | - return $appContainer->queryNoFallback($name); |
|
| 144 | - } catch (QueryException $e) { |
|
| 145 | - // Didn't find the service or the respective app container, |
|
| 146 | - // ignore it and fall back to the core container. |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - return parent::query($name); |
|
| 151 | - } |
|
| 38 | + /** @var DIContainer[] */ |
|
| 39 | + protected $appContainers; |
|
| 40 | + |
|
| 41 | + /** @var string[] */ |
|
| 42 | + protected $hasNoAppContainer; |
|
| 43 | + |
|
| 44 | + /** @var string[] */ |
|
| 45 | + protected $namespaces; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * ServerContainer constructor. |
|
| 49 | + */ |
|
| 50 | + public function __construct() { |
|
| 51 | + parent::__construct(); |
|
| 52 | + $this->appContainers = []; |
|
| 53 | + $this->namespaces = []; |
|
| 54 | + $this->hasNoAppContainer = []; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param string $appName |
|
| 59 | + * @param string $appNamespace |
|
| 60 | + */ |
|
| 61 | + public function registerNamespace(string $appName, string $appNamespace): void { |
|
| 62 | + // Cut of OCA\ and lowercase |
|
| 63 | + $appNamespace = strtolower(substr($appNamespace, strrpos($appNamespace, '\\') + 1)); |
|
| 64 | + $this->namespaces[$appNamespace] = $appName; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @param string $appName |
|
| 69 | + * @param DIContainer $container |
|
| 70 | + */ |
|
| 71 | + public function registerAppContainer(string $appName, DIContainer $container): void { |
|
| 72 | + $this->appContainers[strtolower(App::buildAppNamespace($appName, ''))] = $container; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @param string $appName |
|
| 77 | + * @return DIContainer |
|
| 78 | + * @throws QueryException |
|
| 79 | + */ |
|
| 80 | + public function getRegisteredAppContainer(string $appName): DIContainer { |
|
| 81 | + if (isset($this->appContainers[strtolower(App::buildAppNamespace($appName, ''))])) { |
|
| 82 | + return $this->appContainers[strtolower(App::buildAppNamespace($appName, ''))]; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + throw new QueryException(); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @param string $namespace |
|
| 90 | + * @param string $sensitiveNamespace |
|
| 91 | + * @return DIContainer |
|
| 92 | + * @throws QueryException |
|
| 93 | + */ |
|
| 94 | + protected function getAppContainer(string $namespace, string $sensitiveNamespace): DIContainer { |
|
| 95 | + if (isset($this->appContainers[$namespace])) { |
|
| 96 | + return $this->appContainers[$namespace]; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + if (isset($this->namespaces[$namespace])) { |
|
| 100 | + if (!isset($this->hasNoAppContainer[$namespace])) { |
|
| 101 | + $applicationClassName = 'OCA\\' . $sensitiveNamespace . '\\AppInfo\\Application'; |
|
| 102 | + if (class_exists($applicationClassName)) { |
|
| 103 | + new $applicationClassName(); |
|
| 104 | + if (isset($this->appContainers[$namespace])) { |
|
| 105 | + return $this->appContainers[$namespace]; |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + $this->hasNoAppContainer[$namespace] = true; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return new DIContainer($this->namespaces[$namespace]); |
|
| 112 | + } |
|
| 113 | + throw new QueryException(); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @param string $name name of the service to query for |
|
| 118 | + * @return mixed registered service for the given $name |
|
| 119 | + * @throws QueryException if the query could not be resolved |
|
| 120 | + */ |
|
| 121 | + public function query($name) { |
|
| 122 | + $name = $this->sanitizeName($name); |
|
| 123 | + |
|
| 124 | + if (isset($this[$name])) { |
|
| 125 | + return $this[$name]; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + // In case the service starts with OCA\ we try to find the service in |
|
| 129 | + // the apps container first. |
|
| 130 | + if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 131 | + $segments = explode('\\', $name); |
|
| 132 | + try { |
|
| 133 | + $appContainer = $this->getAppContainer(strtolower($segments[1]), $segments[1]); |
|
| 134 | + return $appContainer->queryNoFallback($name); |
|
| 135 | + } catch (QueryException $e) { |
|
| 136 | + // Didn't find the service or the respective app container, |
|
| 137 | + // ignore it and fall back to the core container. |
|
| 138 | + } |
|
| 139 | + } else if (strpos($name, 'OC\\Settings\\') === 0 && substr_count($name, '\\') >= 3) { |
|
| 140 | + $segments = explode('\\', $name); |
|
| 141 | + try { |
|
| 142 | + $appContainer = $this->getAppContainer(strtolower($segments[1]), $segments[1]); |
|
| 143 | + return $appContainer->queryNoFallback($name); |
|
| 144 | + } catch (QueryException $e) { |
|
| 145 | + // Didn't find the service or the respective app container, |
|
| 146 | + // ignore it and fall back to the core container. |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + return parent::query($name); |
|
| 151 | + } |
|
| 152 | 152 | } |