summaryrefslogtreecommitdiffstats
path: root/apps/dav/appinfo
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/appinfo')
-rw-r--r--apps/dav/appinfo/app.php18
-rw-r--r--apps/dav/appinfo/application.php50
2 files changed, 52 insertions, 16 deletions
diff --git a/apps/dav/appinfo/app.php b/apps/dav/appinfo/app.php
index 3651a5034c5..bc889176f7f 100644
--- a/apps/dav/appinfo/app.php
+++ b/apps/dav/appinfo/app.php
@@ -21,21 +21,7 @@
$cm = \OC::$server->getContactsManager();
$cm->register(function() use ($cm) {
- $db = \OC::$server->getDatabaseConnection();
$userId = \OC::$server->getUserSession()->getUser()->getUID();
- $principal = new \OCA\DAV\Connector\Sabre\Principal(
- \OC::$server->getUserManager()
- );
- $cardDav = new \OCA\DAV\CardDAV\CardDavBackend($db, $principal, \OC::$server->getLogger());
- $addressBooks = $cardDav->getAddressBooksForUser("principals/$userId");
- foreach ($addressBooks as $addressBookInfo) {
- $addressBook = new \OCA\DAV\CardDAV\AddressBook($cardDav, $addressBookInfo);
- $cm->registerAddressBook(
- new OCA\DAV\CardDAV\AddressBookImpl(
- $addressBook,
- $addressBookInfo,
- $cardDav
- )
- );
- }
+ $app = new \OCA\Dav\AppInfo\Application();
+ $app->setupContactsProvider($cm, $userId);
});
diff --git a/apps/dav/appinfo/application.php b/apps/dav/appinfo/application.php
new file mode 100644
index 00000000000..f97d43f188e
--- /dev/null
+++ b/apps/dav/appinfo/application.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace OCA\Dav\AppInfo;
+
+use OCA\DAV\CardDAV\ContactsManager;
+use \OCP\AppFramework\App;
+use OCP\AppFramework\IAppContainer;
+use OCP\Contacts\IManager;
+
+class Application extends App {
+
+ /**
+ * Application constructor.
+ *
+ * @param array $urlParams
+ */
+ public function __construct (array $urlParams=array()) {
+ parent::__construct('dav', $urlParams);
+
+ $container = $this->getContainer();
+ $container->registerService('ContactsManager', function($c) {
+ /** @var IAppContainer $c */
+ return new ContactsManager(
+ $c->query('CardDavBackend')
+ );
+ });
+
+ $container->registerService('CardDavBackend', function($c) {
+ /** @var IAppContainer $c */
+ $db = $c->getServer()->getDatabaseConnection();
+ $logger = $c->getServer()->getLogger();
+ $principal = new \OCA\DAV\Connector\Sabre\Principal(
+ $c->getServer()->getUserManager()
+ );
+ return new \OCA\DAV\CardDAV\CardDavBackend($db, $principal, $logger);
+ });
+
+ }
+
+ /**
+ * @param IManager $contactsManager
+ * @param string $userID
+ */
+ public function setupContactsProvider(IManager $contactsManager, $userID) {
+ /** @var ContactsManager $cm */
+ $cm = $this->getContainer()->query('ContactsManager');
+ $cm->setupContactsProvider($contactsManager, $userID);
+ }
+
+}