Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Application.php « AppInfo « lib - github.com/nextcloud/weather.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: df4baeb05f5e5e34299398b2792023fa8a10f4a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?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;
use \OCP\IContainer;

use \OCA\Weather\Controller\CityController;
use \OCA\Weather\Controller\SettingsController;
use \OCA\Weather\Controller\WeatherController;

use \OCA\Weather\Db\CityMapper;
use \OCA\Weather\Db\SettingsMapper;

class Application extends App {

	public function __construct (array $urlParams=array()) {
		parent::__construct('weather', $urlParams);

		$container = $this->getContainer();

		/**
		 * Core
		 */
		$container->registerService('UserId', function(IContainer $c) {
			$user = $c->getServer()->getUserSession()->getUser();
			return $user ? $user->getUID() : null;
    });

		$container->registerService('Config', function($c) {
			return $c->query('ServerContainer')->getConfig();
		});

		$container->registerService('L10N', function($c) {
		return $c->query('ServerContainer')->getL10N($c->query('AppName'));
		});

		/**
		 * Database Layer
		 */
		$container->registerService('CityMapper', function(IContainer $c) {
			return new CityMapper($c->query('ServerContainer')->getDatabaseConnection());
		});

		$container->registerService('SettingsMapper', function(IContainer $c) {
			return new SettingsMapper($c->query('ServerContainer')->getDatabaseConnection());
		});

		/**
		 * Controllers
		 */
		$container->registerService('CityController', function(IContainer $c) {
			return new CityController(
				$c->query('AppName'),
				$c->query('Config'),
				$c->query('Request'),
				$c->query('UserId'),
				$c->query('CityMapper'),
				$c->query('SettingsMapper')
			);
		});

		$container->registerService('SettingsController', function(IContainer $c) {
			return new SettingsController(
				$c->query('AppName'),
				$c->query('Config'),
				$c->query('Request'),
				$c->query('UserId'),
				$c->query('SettingsMapper'),
				$c->query('CityMapper')
			);
		});

		$container->registerService('WeatherController', function(IContainer $c) {
			return new WeatherController(
				$c->query('AppName'),
				$c->query('Config'),
				$c->query('Request'),
				$c->query('UserId'),
				$c->query('CityMapper'),
				$c->query('SettingsMapper'),
				$c->query('L10N')
			);
		});
	}
}