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;
|
|
|
|
|
|
|
|
use OCP\AppFramework\App as MainApp,
|
|
|
|
OCP\AppFramework\IAppContainer,
|
|
|
|
OCA\Contacts\App,
|
|
|
|
OCA\Contacts\Middleware\Http as HttpMiddleware,
|
2013-10-17 02:10:34 +02:00
|
|
|
OCA\Contacts\Controller\PageController,
|
2013-09-17 18:46:59 +02:00
|
|
|
OCA\Contacts\Controller\AddressBookController,
|
|
|
|
OCA\Contacts\Controller\GroupController,
|
|
|
|
OCA\Contacts\Controller\ContactController,
|
|
|
|
OCA\Contacts\Controller\ContactPhotoController,
|
|
|
|
OCA\Contacts\Controller\SettingsController,
|
2013-09-24 13:39:45 +02:00
|
|
|
OCA\Contacts\Controller\ImportController,
|
|
|
|
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
|
|
|
*
|
|
|
|
* TODO: Merge with App
|
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-07 22:29:15 +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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var OCP\AppFramework\IAppContainer
|
|
|
|
*/
|
|
|
|
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-03-10 22:54:56 +01:00
|
|
|
$this->container->registerMiddleware(new HttpMiddleware());
|
2014-04-07 22:29:15 +02:00
|
|
|
$this->server = $this->container->getServer();
|
2013-09-24 13:39:45 +02:00
|
|
|
$this->app = new App($this->container->query('API')->getUserId());
|
2013-09-17 18:46:59 +02:00
|
|
|
$this->registerServices();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function registerServices() {
|
2014-04-07 22:29:15 +02:00
|
|
|
$appName = $this->appName;
|
2013-10-24 11:14:46 +02:00
|
|
|
$app = $this->app;
|
2014-04-07 22:29:15 +02:00
|
|
|
|
|
|
|
$this->container->registerService('PageController', function(IAppContainer $container) use($app, $appName) {
|
|
|
|
$request = $container->query('Request');
|
|
|
|
return new PageController($appName, $request);
|
2013-10-17 02:10:34 +02:00
|
|
|
});
|
2014-04-07 22:29:15 +02:00
|
|
|
$this->container->registerService('AddressBookController', function(IAppContainer $container) use($app, $appName) {
|
|
|
|
$request = $container->query('Request');
|
|
|
|
return new AddressBookController($appName, $request, $app);
|
2013-09-17 18:46:59 +02:00
|
|
|
});
|
2014-04-07 22:29:15 +02:00
|
|
|
$this->container->registerService('GroupController', function(IAppContainer $container) use($app, $appName) {
|
|
|
|
$request = $container->query('Request');
|
|
|
|
$tags = $this->server->getTagManager()->load('contact');
|
|
|
|
return new GroupController($this->appName, $request, $app, $tags);
|
2013-09-17 18:46:59 +02:00
|
|
|
});
|
2014-04-07 22:29:15 +02:00
|
|
|
$this->container->registerService('ContactController', function(IAppContainer $container) use($app, $appName) {
|
|
|
|
$request = $container->query('Request');
|
|
|
|
return new ContactController($this->appName, $request, $app);
|
2013-09-17 18:46:59 +02:00
|
|
|
});
|
2014-04-07 22:29:15 +02:00
|
|
|
$this->container->registerService('ContactPhotoController', function(IAppContainer $container) use($app, $appName) {
|
|
|
|
$request = $container->query('Request');
|
|
|
|
$cache = $this->server->getCache();
|
|
|
|
return new ContactPhotoController($this->appName, $request, $app, $cache);
|
2013-09-17 18:46:59 +02:00
|
|
|
});
|
2014-04-07 22:29:15 +02:00
|
|
|
$this->container->registerService('SettingsController', function(IAppContainer $container) use($app, $appName) {
|
|
|
|
$request = $container->query('Request');
|
|
|
|
return new SettingsController($this->appName, $request, $app);
|
2013-09-17 18:46:59 +02:00
|
|
|
});
|
2014-04-07 22:29:15 +02:00
|
|
|
$this->container->registerService('ImportController', function(IAppContainer $container) use($app, $appName) {
|
|
|
|
$request = $container->query('Request');
|
|
|
|
$cache = $this->server->getCache();
|
|
|
|
return new ImportController($this->appName, $request, $app, $cache);
|
2013-09-24 13:39:45 +02:00
|
|
|
});
|
2014-04-07 22:29:15 +02:00
|
|
|
$this->container->registerService('ExportController', function(IAppContainer $container) use($app, $appName) {
|
|
|
|
$request = $container->query('Request');
|
|
|
|
return new ExportController($this->appName, $request, $app);
|
2013-09-17 18:46:59 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-10-24 11:14:46 +02:00
|
|
|
}
|