Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Commit

Permalink
Fix DI
Browse files Browse the repository at this point in the history
  • Loading branch information
LEDfan committed Sep 4, 2015
1 parent 15b2fb6 commit 3497955
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
17 changes: 7 additions & 10 deletions appinfo/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace OCA\Maps\AppInfo;


use OCA\Maps\Db\LocationManager;
use \OCP\AppFramework\App;
use \OCA\Maps\Db\CacheManager;
use \OCA\Maps\Db\DeviceMapper;
Expand Down Expand Up @@ -55,6 +56,12 @@ public function __construct (array $urlParams=array()) {
$c->query('ServerContainer')->getDb()
);
});

$container->registerService('locationManager', function($c) {
return new LocationManager(
$c->query('ServerContainer')->getDb()
);
});
$container->registerService('LocationMapper', function($c) {
return new LocationMapper(
$c->query('ServerContainer')->getDb()
Expand All @@ -66,16 +73,6 @@ public function __construct (array $urlParams=array()) {
);
});

/**
* Core
*/
$container->registerService('UserId', function($c) {
return \OCP\User::getUser();
});
$container->registerService('Db', function() {
return new Db();
});

}


Expand Down
6 changes: 5 additions & 1 deletion controller/pagecontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace OCA\Maps\Controller;

use OCA\Maps\Db\LocationManager;
use \OCP\IRequest;
use \OCP\AppFramework\Http\TemplateResponse;
use \OCP\AppFramework\Controller;
Expand All @@ -21,7 +22,9 @@ class PageController extends Controller {
private $userId;
private $cacheManager;
private $locationManager;
public function __construct($appName, IRequest $request, $userId, $cacheManager,$locationManager) {
public function __construct($appName, IRequest $request, $userId,
CacheManager $cacheManager,
LocationManager $locationManager) {
parent::__construct($appName, $request);
$this -> userId = $userId;
$this -> cacheManager = $cacheManager;
Expand All @@ -39,6 +42,7 @@ public function __construct($appName, IRequest $request, $userId, $cacheManager,
* @NoCSRFRequired
*/
public function index() {

$params = array('user' => $this -> userId,'devices'=>$this->locationManager->loadAll($this->userId));
$response = new TemplateResponse('maps', 'main', $params);
if (class_exists('OCP\AppFramework\Http\ContentSecurityPolicy')) {
Expand Down
2 changes: 1 addition & 1 deletion db/cachemanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class CacheManager {
private $userid;
private $db;
public function __construct($db) {
public function __construct(IDb $db) {
$this -> db = $db;
}

Expand Down
2 changes: 1 addition & 1 deletion db/locationmanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class LocationManager {
private $userid;
private $db;
public function __construct($db) {
public function __construct(IDb $db) {
$this -> db = $db;
}

Expand Down

0 comments on commit 3497955

Please sign in to comment.