Skip to content

Commit 46a6b84

Browse files
author
Daniel Stříbrný
committed
PSR-4 autoload fixed, deps polished
1 parent 50bc09c commit 46a6b84

2 files changed

Lines changed: 22 additions & 21 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace ADT\QueryObjectDataSource;
4+
5+
interface IQueryObjectDataSourceFactory {
6+
7+
/**
8+
* @param \Kdyby\Doctrine\QueryObject $queryObject
9+
* @param \Kdyby\Doctrine\EntityRepository $repo
10+
* @return QueryObjectDataSource
11+
*/
12+
function create(\Kdyby\Doctrine\QueryObject $queryObject, \Kdyby\Doctrine\EntityRepository $repo);
13+
14+
}

src/QueryObjectDataSource.php

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,17 @@
22

33
namespace ADT\QueryObjectDataSource;
44

5-
interface IQueryObjectDataSourceFactory {
6-
7-
/** @return QueryObjectDataSource */
8-
function create(\Kdyby\Doctrine\QueryObject $queryObject, $primaryKey);
9-
10-
}
11-
12-
135
class QueryObjectDataSource extends \Nette\Object implements \Ublaboo\DataGrid\DataSource\IDataSource {
146

15-
/** @var \Kdyby\Doctrine\EntityManager */
16-
protected $em;
17-
187
/** @var \Kdyby\Doctrine\ResultSet */
198
protected $resultSet;
209

10+
/** @var \Kdyby\Doctrine\EntityRepository */
11+
protected $repo;
12+
2113
/** @var \Kdyby\Doctrine\QueryObject */
2214
protected $queryObject;
2315

24-
/** @var string */
25-
protected $primaryKey;
26-
2716
/** @var callable */
2817
public $filterCallback;
2918

@@ -35,13 +24,11 @@ class QueryObjectDataSource extends \Nette\Object implements \Ublaboo\DataGrid\D
3524

3625
/**
3726
* @param \Kdyby\Doctrine\QueryObject $queryObject
38-
* @param string $primaryKey
39-
* @param \Kdyby\Doctrine\EntityManager $em
27+
* @param \Kdyby\Doctrine\EntityRepository $repo
4028
*/
41-
public function __construct(\Kdyby\Doctrine\QueryObject $queryObject, $primaryKey, \Kdyby\Doctrine\EntityManager $em) {
29+
public function __construct(\Kdyby\Doctrine\QueryObject $queryObject, \Kdyby\Doctrine\EntityRepository $repo) {
4230
$this->queryObject = $queryObject;
43-
$this->primaryKey = $primaryKey;
44-
$this->em = $em;
31+
$this->repo = $repo;
4532
}
4633

4734
/**
@@ -73,7 +60,7 @@ public function setSortCallback($callback) {
7360

7461
protected function getResultSet() {
7562
if (!$this->resultSet) {
76-
$this->resultSet = $this->em->getRepository($this->queryObject->getEntity())
63+
$this->resultSet = $this->repo
7764
->fetch($this->queryObject);
7865
}
7966

@@ -85,7 +72,7 @@ protected function getResultSet() {
8572
* @return int
8673
*/
8774
public function getCount() {
88-
return $this->em->getRepository($this->queryObject->getEntity())
75+
return $this->repo
8976
->fetch($this->queryObject)
9077
->getTotalCount();
9178
}

0 commit comments

Comments
 (0)