2015-07-08 21:29:55 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ownCloud - weather
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later. See the COPYING file.
|
|
|
|
*
|
|
|
|
* @author Loic Blot <loic.blot@unix-experience.fr>
|
|
|
|
* @copyright Loic Blot 2015
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
namespace OCA\Weather\AppInfo;
|
|
|
|
|
|
|
|
use \OCP\AppFramework\App;
|
2023-07-24 19:24:05 +00:00
|
|
|
use Psr\Container\ContainerInterface;
|
2015-07-08 21:29:55 +00:00
|
|
|
|
2023-07-24 19:24:05 +00:00
|
|
|
use OCA\Weather\Controller\CityController;
|
|
|
|
use OCA\Weather\Controller\SettingsController;
|
|
|
|
use OCA\Weather\Controller\WeatherController;
|
2015-07-08 21:29:55 +00:00
|
|
|
|
2023-07-24 19:24:05 +00:00
|
|
|
use OCA\Weather\Db\CityMapper;
|
|
|
|
use OCA\Weather\Db\SettingsMapper;
|
|
|
|
use OCP\AppFramework\Bootstrap\IBootContext;
|
|
|
|
use OCP\AppFramework\Bootstrap\IBootstrap;
|
|
|
|
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
|
|
|
use OCP\IUserSession;
|
|
|
|
use OC\User\Session;
|
2015-07-08 21:29:55 +00:00
|
|
|
|
2023-07-24 19:24:05 +00:00
|
|
|
class Application extends App implements IBootstrap {
|
2015-07-08 21:29:55 +00:00
|
|
|
|
2023-07-24 19:24:05 +00:00
|
|
|
public function __construct (array $urlParams = []) {
|
2015-07-08 21:29:55 +00:00
|
|
|
parent::__construct('weather', $urlParams);
|
2023-07-24 19:24:05 +00:00
|
|
|
}
|
2015-07-08 21:29:55 +00:00
|
|
|
|
2023-07-24 19:24:05 +00:00
|
|
|
public function register(IRegistrationContext $context): void {
|
|
|
|
|
|
|
|
$context->registerService('UserId', function(ContainerInterface $c) {
|
|
|
|
/** @var Session */
|
|
|
|
$userSession = $c->get(IUserSession::class);
|
2015-07-08 21:29:55 +00:00
|
|
|
|
2023-07-24 19:24:05 +00:00
|
|
|
return $userSession->getUser() ? $userSession->getUser()->getUID() : null;
|
|
|
|
});
|
2015-07-08 21:29:55 +00:00
|
|
|
|
2023-07-24 19:24:05 +00:00
|
|
|
$context->registerService('Config', function(ContainerInterface $c) {
|
|
|
|
return $c->get('ServerContainer')->getConfig();
|
2017-07-03 21:12:50 +00:00
|
|
|
});
|
|
|
|
|
2023-07-24 19:24:05 +00:00
|
|
|
$context->registerService('L10N', function(ContainerInterface $c) {
|
|
|
|
return $c->get('ServerContainer')->getL10N($c->get('AppName'));
|
2019-05-19 08:30:28 +00:00
|
|
|
});
|
|
|
|
|
2015-07-08 21:29:55 +00:00
|
|
|
/**
|
|
|
|
* Database Layer
|
|
|
|
*/
|
2023-07-24 19:24:05 +00:00
|
|
|
$context->registerService('CityMapper', function(ContainerInterface $c) {
|
|
|
|
return new CityMapper($c->get('ServerContainer')->getDatabaseConnection());
|
2015-07-08 21:29:55 +00:00
|
|
|
});
|
|
|
|
|
2023-07-24 19:24:05 +00:00
|
|
|
$context->registerService('SettingsMapper', function(ContainerInterface $c) {
|
|
|
|
return new SettingsMapper($c->get('ServerContainer')->getDatabaseConnection());
|
2015-07-18 13:58:51 +00:00
|
|
|
});
|
|
|
|
|
2015-07-08 21:29:55 +00:00
|
|
|
/**
|
|
|
|
* Controllers
|
|
|
|
*/
|
2023-07-24 19:24:05 +00:00
|
|
|
$context->registerService('CityController', function(ContainerInterface $c) {
|
2015-07-08 21:29:55 +00:00
|
|
|
return new CityController(
|
2023-07-24 19:24:05 +00:00
|
|
|
$c->get('AppName'),
|
|
|
|
$c->get('Config'),
|
|
|
|
$c->get('Request'),
|
|
|
|
$c->get('UserId'),
|
|
|
|
$c->get('CityMapper'),
|
|
|
|
$c->get('SettingsMapper')
|
2015-07-18 13:58:51 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2023-07-24 19:24:05 +00:00
|
|
|
$context->registerService('SettingsController', function(ContainerInterface $c) {
|
2015-07-18 13:58:51 +00:00
|
|
|
return new SettingsController(
|
2023-07-24 19:24:05 +00:00
|
|
|
$c->get('AppName'),
|
|
|
|
$c->get('Config'),
|
|
|
|
$c->get('Request'),
|
|
|
|
$c->get('UserId'),
|
|
|
|
$c->get('SettingsMapper'),
|
|
|
|
$c->get('CityMapper')
|
2015-07-08 21:29:55 +00:00
|
|
|
);
|
|
|
|
});
|
2015-07-11 15:01:30 +00:00
|
|
|
|
2023-07-24 19:24:05 +00:00
|
|
|
$context->registerService('WeatherController', function(ContainerInterface $c) {
|
2015-07-11 15:01:30 +00:00
|
|
|
return new WeatherController(
|
2023-07-24 19:24:05 +00:00
|
|
|
$c->get('AppName'),
|
|
|
|
$c->get('Config'),
|
|
|
|
$c->get('Request'),
|
|
|
|
$c->get('UserId'),
|
|
|
|
$c->get('CityMapper'),
|
|
|
|
$c->get('SettingsMapper'),
|
|
|
|
$c->get('L10N')
|
2015-07-11 15:01:30 +00:00
|
|
|
);
|
|
|
|
});
|
2015-07-08 21:29:55 +00:00
|
|
|
}
|
2023-07-24 19:24:05 +00:00
|
|
|
|
|
|
|
public function boot(IBootContext $context): void {
|
|
|
|
}
|
2015-07-08 21:29:55 +00:00
|
|
|
}
|