2013-09-17 18:46:59 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2014-01-26 00:40:22 +01:00
|
|
|
* @author Thomas Tanghus
|
|
|
|
* @copyright 2013-2014 Thomas Tanghus (thomas@tanghus.net)
|
|
|
|
*
|
2013-09-17 18:46:59 +02:00
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Contacts;
|
|
|
|
|
2015-05-08 00:57:33 +02:00
|
|
|
use OCP\AppFramework\App as MainApp;
|
2015-07-03 13:28:54 +02:00
|
|
|
use OCP\AppFramework\Http;
|
2015-05-08 00:57:33 +02:00
|
|
|
use OCP\AppFramework\IAppContainer;
|
|
|
|
use OCA\Contacts\Middleware\Http as HttpMiddleware;
|
|
|
|
use OCA\Contacts\Controller\PageController;
|
|
|
|
use OCA\Contacts\Controller\AddressBookController;
|
|
|
|
use OCA\Contacts\Controller\BackendController;
|
|
|
|
use OCA\Contacts\Controller\GroupController;
|
|
|
|
use OCA\Contacts\Controller\ContactController;
|
|
|
|
use OCA\Contacts\Controller\ContactPhotoController;
|
|
|
|
use OCA\Contacts\Controller\SettingsController;
|
|
|
|
use OCA\Contacts\Controller\ImportController;
|
|
|
|
use OCA\Contacts\Controller\ExportController;
|
2013-09-17 18:46:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This class manages our app actions
|
2013-10-18 15:29:16 +02:00
|
|
|
*
|
2015-07-03 13:28:54 +02:00
|
|
|
* TODO: Build app properly on basis of AppFramework
|
2013-09-17 18:46:59 +02:00
|
|
|
*/
|
|
|
|
class Dispatcher extends MainApp {
|
2014-04-07 22:29:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $appName;
|
|
|
|
|
2013-09-17 18:46:59 +02:00
|
|
|
/**
|
2014-04-08 01:19:30 +02:00
|
|
|
* @var \OCA\Contacts\App
|
2013-09-17 18:46:59 +02:00
|
|
|
*/
|
|
|
|
protected $app;
|
|
|
|
|
2014-04-07 22:29:15 +02:00
|
|
|
/**
|
|
|
|
* @var \OCP\IServerContainer
|
|
|
|
*/
|
|
|
|
protected $server;
|
|
|
|
|
|
|
|
/**
|
2014-04-08 01:19:30 +02:00
|
|
|
* @var \OCP\AppFramework\IAppContainer
|
2014-04-07 22:29:15 +02:00
|
|
|
*/
|
|
|
|
protected $container;
|
|
|
|
|
2013-10-11 14:47:17 +02:00
|
|
|
public function __construct($params) {
|
2014-04-07 22:29:15 +02:00
|
|
|
$this->appName = 'contacts';
|
|
|
|
parent::__construct($this->appName, $params);
|
2013-09-17 18:46:59 +02:00
|
|
|
$this->container = $this->getContainer();
|
2014-04-07 22:29:15 +02:00
|
|
|
$this->server = $this->container->getServer();
|
2015-07-03 13:28:54 +02:00
|
|
|
$user = \OC::$server->getUserSession()->getUser();
|
|
|
|
if (is_null($user)) {
|
|
|
|
\OC_Util::redirectToDefaultPage();
|
|
|
|
}
|
|
|
|
$userId = $user->getUID();
|
2015-06-30 00:25:55 +02:00
|
|
|
$this->app = new App($userId);
|
2013-09-17 18:46:59 +02:00
|
|
|
$this->registerServices();
|
2014-04-10 20:29:17 +02:00
|
|
|
$this->container->registerMiddleware('HttpMiddleware');
|
2013-09-17 18:46:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function registerServices() {
|
2013-10-24 11:14:46 +02:00
|
|
|
$app = $this->app;
|
2014-05-25 08:44:33 +02:00
|
|
|
$appName = $this->appName;
|
2014-04-07 22:29:15 +02:00
|
|
|
|
2014-04-10 20:29:17 +02:00
|
|
|
$this->container->registerService('HttpMiddleware', function($container) {
|
|
|
|
return new HttpMiddleware();
|
|
|
|
});
|
|
|
|
|
2014-05-25 08:44:33 +02:00
|
|
|
$this->container->registerService('PageController', function(IAppContainer $container) use($app, $appName) {
|
2014-04-07 22:29:15 +02:00
|
|
|
$request = $container->query('Request');
|
2014-05-25 08:44:33 +02:00
|
|
|
return new PageController($appName, $request);
|
2013-10-17 02:10:34 +02:00
|
|
|
});
|
2014-05-25 08:44:33 +02:00
|
|
|
$this->container->registerService('AddressBookController', function(IAppContainer $container) use($app, $appName) {
|
2014-04-07 22:29:15 +02:00
|
|
|
$request = $container->query('Request');
|
2015-06-30 00:25:55 +02:00
|
|
|
$userId = \OC::$server->getUserSession()->getUser()->getUID();
|
|
|
|
return new AddressBookController($appName, $request, $app, $userId);
|
2013-09-17 18:46:59 +02:00
|
|
|
});
|
2014-05-25 08:44:33 +02:00
|
|
|
$this->container->registerService('BackendController', function(IAppContainer $container) use($app, $appName) {
|
2014-04-10 19:51:52 +02:00
|
|
|
$request = $container->query('Request');
|
2014-04-09 22:07:13 +02:00
|
|
|
return new BackendController($container, $request, $app);
|
2014-04-05 00:50:55 +02:00
|
|
|
});
|
2014-05-25 08:44:33 +02:00
|
|
|
$this->container->registerService('GroupController', function(IAppContainer $container) use($app, $appName) {
|
2014-04-07 22:29:15 +02:00
|
|
|
$request = $container->query('Request');
|
2014-09-26 16:08:22 +02:00
|
|
|
$tags = $container->getServer()->getTagManager()->load('contact', array(), true);
|
2014-05-25 08:44:33 +02:00
|
|
|
return new GroupController($appName, $request, $app, $tags);
|
2013-09-17 18:46:59 +02:00
|
|
|
});
|
2014-05-25 08:44:33 +02:00
|
|
|
$this->container->registerService('ContactController', function(IAppContainer $container) use($app, $appName) {
|
2014-04-07 22:29:15 +02:00
|
|
|
$request = $container->query('Request');
|
2014-05-25 08:44:33 +02:00
|
|
|
return new ContactController($appName, $request, $app);
|
2013-09-17 18:46:59 +02:00
|
|
|
});
|
2014-05-25 08:44:33 +02:00
|
|
|
$this->container->registerService('ContactPhotoController', function(IAppContainer $container) use($app, $appName) {
|
2014-04-07 22:29:15 +02:00
|
|
|
$request = $container->query('Request');
|
2014-05-25 08:44:33 +02:00
|
|
|
$cache = $container->getServer()->getCache();
|
|
|
|
return new ContactPhotoController($appName, $request, $app, $cache);
|
2013-09-17 18:46:59 +02:00
|
|
|
});
|
2014-05-25 08:44:33 +02:00
|
|
|
$this->container->registerService('SettingsController', function(IAppContainer $container) use($app, $appName) {
|
2014-04-07 22:29:15 +02:00
|
|
|
$request = $container->query('Request');
|
2014-05-25 08:44:33 +02:00
|
|
|
return new SettingsController($appName, $request, $app);
|
2013-09-17 18:46:59 +02:00
|
|
|
});
|
2014-05-25 08:44:33 +02:00
|
|
|
$this->container->registerService('ImportController', function(IAppContainer $container) use($app, $appName) {
|
2014-04-07 22:29:15 +02:00
|
|
|
$request = $container->query('Request');
|
2014-05-25 08:44:33 +02:00
|
|
|
$cache = $container->getServer()->getCache();
|
2014-07-04 16:51:59 +02:00
|
|
|
$tags = $container->getServer()->getTagManager()->load('contact');
|
|
|
|
return new ImportController($appName, $request, $app, $cache, $tags);
|
2013-09-24 13:39:45 +02:00
|
|
|
});
|
2014-05-25 08:44:33 +02:00
|
|
|
$this->container->registerService('ExportController', function(IAppContainer $container) use($app, $appName) {
|
2014-04-07 22:29:15 +02:00
|
|
|
$request = $container->query('Request');
|
2014-05-25 08:44:33 +02:00
|
|
|
return new ExportController($appName, $request, $app);
|
2013-09-17 18:46:59 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-10-24 11:14:46 +02:00
|
|
|
}
|