Skip to content

Commit e166820

Browse files
author
Michael
committed
Add setup callback function
1 parent 9640229 commit e166820

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/BaseRepository.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class BaseRepository extends EntityRepository
1111
protected $namedParamCounter = 0;
1212
protected $joins = array();
1313
protected $disableJoins = false;
14+
protected $setupFunction = null;
1415

1516
public function disableJoins(bool $disableJoins)
1617
{
@@ -31,7 +32,13 @@ public function countRows(string $column, array $filters = array())
3132
$query = $queryBuilder->getQuery();
3233

3334
return $query->getSingleScalarResult();
35+
}
36+
37+
public function setup(callable $callback)
38+
{
39+
$this->setupFunction = $callback;
3440

41+
return $this;
3542
}
3643

3744
public function findFiltered(array $filters = array(), $order = array(), $limit = null, $offset = 0)
@@ -66,6 +73,10 @@ public function buildQuery(array $filters = array(), $order = array(), $limit =
6673
$this->alias
6774
));
6875

76+
// Got a setup function?
77+
if(is_callable($this->setupFunction))
78+
$queryBuilder = call_user_func($this->setupFunction, $this->alias, $queryBuilder);
79+
6980
// Defaults options
7081
$opt = array_merge(array(
7182
'disable_joins' => false

0 commit comments

Comments
 (0)